做单元测试的时候发现错误,
java.lang.IllegalStateException: Found multiple @SpringBootConfiguration annotated classes [Generic bean: class [cn.com.git.Application]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [C:\Users\git\git\batchSpringboot\batch-springboot\batch-view\target\classes\cn\com\git\Application.class], Generic bean: class [cn.com.git.WebApplication]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [C:\Users\git\git\batchSpringboot\batch-springboot\batch-view\target\classes\cn\com\git\WebApplication.class]]
at org.springframework.util.Assert.state(Assert.java:94)
at org.springframework.boot.test.context.AnnotatedClassFinder.scanPackage(AnnotatedClassFinder.java:92)
at org.springframework.boot.test.context.AnnotatedClassFinder.findFromPackage(AnnotatedClassFinder.java:82)
at org.springframework.boot.test.context.AnnotatedClassFinder.findFromClass(AnnotatedClassFinder.java:68)
检查发现是有两个启动类
@SpringBootApplication //启动springboot
@RestController
@ComponentScan(basePackages = "cn.com.git.batch.*")
@MapperScan(basePackages="cn.com.git.batch.dao") //扫描Mapper接口类
public class WebApplication extends SpringBootServletInitializer{
注释掉一个后正常,测试通过!