IllegalStateException: Found multiple @SpringBootConfiguration annotated classes [Generic bean:...

IllegalStateException: Found multiple @SpringBootConfiguration annotated classes [Generic 
bean: class [com.XXX.XXXResourceApplication]; scope=; abstract=false; lazyInit=null; 
autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; 
factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; 
defined in file [E:\resources\target\classes\com\XXX\XXXResourceApplication.class], Generic bean: class 
[com.XXX.SystemCenterApplication]; scope=; abstract=false; lazyInit=null; 
autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; 
factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; 
defined in file [E:\system\target\classes\com\XXX\SystemCenterApplication.class]]

写测试用例的时候报这个错,是它不知道用那个启动类启动,不知道是XXXResourceApplication,还是SystemCenterApplication

我们只需要指明启动类即可。

@RunWith(SpringRunner.class)
// 指明启动类
@SpringBootTest(classes={XXXResourceApplication.class})
class SystemMessageProducerTest {
    @Resource
    SystemMessageProducer producer;

    @Test
    void sendMessage() {
        producer.sendMessage("SystemMessageProducer");
    }
}

猜你喜欢

转载自blog.csdn.net/Ciel_Y/article/details/122554617