java.lang.IllegalStateException: Found multiple @SpringBootConfiguration annotated classes

最近在搭建springboot继承dubbo的分布式项目时,测试dao层遇到的问题,启动测试方法时,出现如下错误:

java.lang.IllegalStateException: Found multiple @SpringBootConfiguration annotated classes [Generic bean: class [com.example.cqw.DubboDaoApplication]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [D:\study\dubbo-parent\dubbo-dao\target\classes\com\example\cqw\DubboDaoApplication.class], 
    at org.springframework.util.Assert.state(Assert.java:94)
    at org.springframework.boot.test.context.SpringBootConfigurationFinder.scanPackage(SpringBootConfigurationFinder.java:69)

如图:

 

 

分析原因:因为项目是springboot+dubbo架构,dao项目依赖于pojo项目,在pojo项目中也有启动类@SpringBootApplication,因为在dao的测试类中启动方法时,会加载pojo项目启动类,所以会造成上图所示错误,注释掉pojo项目启动类上的@SpringBootApplication注解即可

 

简单的说,就是你在项目中有两个@SpringBootApplication,注释掉一个你不用的就可以。

posted @ 2020-02-06 10:23  King-DA  阅读(6628)  评论(0编辑  收藏  举报