我正在考虑开发这样的应用程序:
为此,我的应用程序需要唯一标识与其共享的文档的所有者。我查看了 API,但找不到如何操作。我找到了像File.getOwnerNames()这样的方法,但它们是包含名称的纯字符串,但没有任何用于识别用户的唯一键。
需要有关如何实现这一目标的帮助。谢谢。
桑杰
我正在尝试对服务方法进行单元测试。服务方法调用 spring 数据存储库方法来获取一些数据。我想模拟该存储库调用,并自己提供数据。怎么做?按照Spring Boot 文档,当我模拟存储库并直接在测试代码中调用存储库方法时,模拟正在工作。但是,当我调用服务方法(该方法又会调用存储库方法)时,模拟不起作用。下面是示例代码:
服务等级:
@Service
public class PersonService {
private final PersonRepository personRepository;
@Autowired
public PersonService(personRepository personRepository) {
this.personRepository = personRepository;
}
public List<Person> findByName(String name) {
return personRepository.findByName(name); // I'd like to mock this call
}
}
Run Code Online (Sandbox Code Playgroud)
测试类:
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTests {
// http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-testing-spring-boot-applications-mocking-beans
@MockBean
private PersonRepository personRepository;
@Autowired
private PersonService personService;
private List<Person> people = new ArrayList<>();
@Test
public void contextLoads() throws Exception {
people.add(new Person());
people.add(new Person());
given(this.personRepository.findByName("Sanjay Patel")).willReturn(people);
assertTrue(personService.findByName("Sanjay Patel") …Run Code Online (Sandbox Code Playgroud) 与spring-cloud-config集中配置类似,我们是否有集中 i18n 的东西messages.properties?这样做的最佳方法是什么?
Spring文档告诉我们,如果我们使用Java 8 --parameters flag编译项目,我们可以跳过在@PathVariable等注释中给出参数名称.这意味着,我们可以使用@PathVariable id而不是@PathVariable("id") id.
在Spring Boot Maven应用程序中,我很想知道如何告诉编译器使用参数标志.它是默认打开的吗?我们需要在pom.xml中提供一些东西吗?
我们正在为一个项目评估 Spring 5,但不确定如何最好地验证Mono参数。传统上,我们一直使用MethodValidationPostProcessor来验证我们的方法参数,如下所示:
@Validated
@Service
public class FooService
@Validated(SignUpValidation.class)
public void signup(@Valid UserCommand userCommand) {
...
}
Run Code Online (Sandbox Code Playgroud)
然后我们将在ControllerAdviceor 中处理异常ErrorController,并将合适的 4xx 响应传递给客户端。
但是当我将参数更改为 时Mono,如下所示,它似乎不再起作用。
@Validated
@Service
public class FooService
@Validated(SignUpValidation.class)
public Mono<Void> signup(@Valid Mono<UserCommand> userCommand) {
...
}
Run Code Online (Sandbox Code Playgroud)
据我了解 Spring Reactive,可能它实际上不应该工作。那么,验证Monos 和Fluxes 然后发送合适的错误响应的Spring 5 最佳实践是什么?
spring spring-mvc spring-validator spring-boot spring-webflux
我无法弄清楚如何使用Google Apps脚本访问Google文档中的注释。查看API参考,我仅找到CommentSection类,但已将其标记为已弃用。寻求帮助。谢谢。
桑杰
在使用JpaRepositorySpring Data JPA的方法(例如findOne、findBy...等)获取实体后,我想知道自动执行一些自定义代码的最佳方法是什么,比如初始化一些瞬态字段。
换句话说,假设我有一个用户实体fullName瞬态场,应设置为串联firstName,并lastName从数据库中获取后,我该怎么办?
我正在考虑为用户编写一些Java代码来安装时间驱动的触发器(定期运行谷歌应用程序脚本).但无法找到用于操纵触发器的REST API.想知道是否有可能.谢谢.
桑杰
spring ×5
spring-boot ×3
spring-data ×2
spring-mvc ×2
google-api ×1
google-docs ×1
hibernate ×1
jpa ×1
spring-cloud ×1