Java 使用Spring Boot构建库:找不到@SpringBootConfiguration
我目前正在从事微服务的工作,这个项目基本上是一个库,它没有主功能。我正在为这个库编写单元测试用例,但是我找不到@SpringBootConfiguration。如果没有主功能,我们不能执行单元测试用例吗 库中唯一的文件Java 使用Spring Boot构建库:找不到@SpringBootConfiguration,java,spring,spring-boot,junit,Java,Spring,Spring Boot,Junit,我目前正在从事微服务的工作,这个项目基本上是一个库,它没有主功能。我正在为这个库编写单元测试用例,但是我找不到@SpringBootConfiguration。如果没有主功能,我们不能执行单元测试用例吗 库中唯一的文件 class OnlyFile { void validate(){ } } 测试 @SpringBootTest class MyTest { @Test void testIt(){ // //
class OnlyFile {
void validate(){
}
}
测试
@SpringBootTest
class MyTest {
@Test
void testIt(){
//
//
}
}
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.3.3.RELEASE</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
org.springframework.boot
弹簧起动试验
2.3.3.2发布
测试
org.junit.vintage
朱尼特老式发动机
如果您想编写和运行单元测试,而它只是一个库,那么我认为您没有必要在测试类上添加@SpringBootTest注释。当您需要在集成测试中使用spring应用程序上下文时,它用于集成测试
在用@SpringBootTest注释的类中运行集成测试时,您需要在与用@SpringBootConfiguration注释的测试类相同的包或子包中有一个类,该类包含加载应用程序上下文的配置。如果不需要自定义配置,则该类可以为空。或者,您可以指定在像这样加载应用程序上下文时要使用的组件
@SpringBootTest(classes = ...)