【BUG】Java问题解决:** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan

解决办法的参考来源: 

https://www.cnblogs.com/shea/p/8693202.htmlhttps://www.cnblogs.com/shea/p/8693202.html

1、我的问题

报错日志显示:


** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.

控制台输出

【BUG】Java问题解决:** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan_第1张图片

【BUG】Java问题解决:** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan_第2张图片

Test ignored.
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test
// 警告:你的应用上下文可能没有启动,因为你将注解添加到了默认的package上面了

2、原因

我的默认路径:将APP启动类直接放在java包下了,这是有问题的。

【BUG】Java问题解决:** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan_第3张图片

3、解决办法

方法1:在main/java下建个包,将Application文件放进去:

【BUG】Java问题解决:** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan_第4张图片

 方法2:在Application类上面加@ComponentScan注解,指定要扫描的。(这种方法我还没试过)

@SpringBootApplication
@EnableEurekaClient
@ComponentScan(basePackageClasses = TestClass.class )
public class ClientDemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(ClientDemoApplication.class, args);
    }
}

【BUG】Java问题解决:** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan_第5张图片

你可能感兴趣的:(突如其来的BUG,java,bug,spring,boot)