[英]Spring boot Test with non-Spring Boot Application
I have an application using Spring MVC 4, and not using any spring-boot-starter-* dependencies. 我有一个使用Spring MVC 4的应用程序,而不使用任何spring-boot-starter- *依赖项。 ie, I don't have that class with a main method calling SpringApplication.run
. 即,我没有该类的主要方法调用SpringApplication.run
。 I'm configuring all by myself with xml and other @Configuration
classes. 我自己用xml和其他@Configuration
类进行配置。
Question : Is it possible to configure Spring Boot Test (using the spring-boot-starter-test) in that non Spring Boot Application? 问题 :是否可以在该非Spring Boot应用程序中配置Spring Boot Test(使用spring-boot-starter-test)?
spring-boot-starter-test has dependency on spring-boot-test JAR . spring-boot-starter-test依赖于spring-boot-test JAR 。 There are some spring-boot
packages used. 有一些使用spring-boot
软件包。 So if you wouldn't use these features, you may be able to use it as pure test dependency. 因此,如果您不使用这些功能,则可以将其用作纯测试依赖项。 But better alternative would be to use plain spring-test
module. 但是更好的选择是使用普通的spring-test
模块。 That covers most of the Spring test functionality anyway. 无论如何,这涵盖了大多数Spring测试功能。
spring-boot-starter-test has all you need, but it is dependency that you need to have, it will give you all power from spring-boot side, ie if you have your test class annotated with spring-boot-starter-test具有所需的一切,但它是所需的依赖项,它将为您提供spring-boot方面的所有功能,即如果您的测试类带有注释
@RunWith(SpringRunner.class)
@@SpringBootTest(
classes = ${YourMainClass}.class
)
it should work, even though I would strongly recommend using whole power of Spring Boot framework with the usage of all proper dependencies. 即使我强烈建议将Spring Boot框架的全部功能与所有适当的依赖项一起使用,它也应该起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.