sping boot Controller扫描不到
SpringBoot项目的Bean装配默认规则是根据Application类所在的包位置从上往下扫描!
也就是SpringBoot项目入口类。@SpringBootApplication 只有和Application同级或者子集才能自动扫描的到;
如果我们想扫描我们指定的包,则需要在添加@ComponentScan(basePackages={"doma","com.zmm.myspringboot"}) 来
指定要扫描的包以及要扫描的类。
1 @RestController 2 @SpringBootApplication 3 @ComponentScan(basePackages={"doma","com.zmm.myspringboot"}) 4 public class MyspringbootApplication { 5 6 public static void main(String[] args) { 7 SpringApplication.run(MyspringbootApplication.class, args); 8 }

浙公网安备 33010602011771号