关于ApplicationContext is unlikely to start due to a @ComponentScan of the default package.的解决办法
关于Idea springBoot 启动报错ApplicationContext is unlikely to start due to a @ComponentScan of the default package.的解决办法
参考链接:https://*.com/questions/35070455/springboot-beandefinitionstoreexception-failed-to-parse-configuration-class
启动报错截图以及启动文件放置位置错误示范:
原因分析:因为Application 启动类不能直接放在src/main/java目录下导致报错,正确的防止位置如下,当然最好单独再命名一个Controller文件夹防止启动类,而不是像我直接把启动文件拖进去发现不报错了,同时在Application启动类中不要添加这个标签
@ComponentScan("")
我的启动类ReadApplication是这样的
package config; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.context.annotation.ComponentScan; import ymlConfig.YmlConfig; @SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}) @EnableConfigurationProperties({PropsConfig.class, YmlConfig.class}) //@ComponentScan("") public class ReadApplication extends SpringBootServletInitializer{ @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(ReadApplication.class); } public static void main(String[] args) { SpringApplication.run(ReadApplication.class, args); } }
正确的位置是这样的