微服务架构风格是一种将一个单一应用程序开发为一组小型服务的方法,每个服务运行在自己的进程中,服务间通信采用轻量级通信机制(通常用HTTP资源API)。
按照书上教程搭完简易项目后,启动报错:
Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package.
SpringBoot在写启动类的时候如果不使用@ComponentScan指明对象扫描范围,默认指扫描当前启动类所在的包里的对象,如果当前启动类没有包,则在启动时会报错:Your ApplicationContext is unlikely to start due to a @ComponentScan of the default package错误。 因为启动类不能直接放在main/java文件夹下,必须要建一个包把它放进去或者使用@ComponentScan指明要扫描的包。
@SpringBootApplication @ComponentScan(basePackageClasses=MytestApplication.class)
public class MytestApplication {
public static void main(String[] args){
SpringApplication.run(MytestApplication.class, args);
}
}
@ComponentScan(basePackageClasses=要扫描类.class所在位置的包)-意思是要扫描哪个类所在的包
我的整改方法,直接将启动类放进代码的com总包里,则会自动扫描com包(包括com内的子包)内的所有文件,这个错误就不会报了。