新进的公司用到springBoot、springCloud,回到家里赶紧补课
有个问题困扰了我近两个小时。
把controller放到springBootApplication类所在包的其他位置下,会扫描不到controller,查了资料
链接:https://www.cnblogs.com/shuoli/p/7676001.html
https://www.cnblogs.com/oyx305/p/5512545.html
http://blog.csdn.net/Fandly168/article/details/73302281
https://www.cnblogs.com/oskyhg/p/6683629.html
解决方法:
1.将要用的组建放在启动类包下(不规范)
2.在启动类填加注解@ComponentScan,或者@ComponentScans
例:
package test.demo.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("controller")//包名
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
application.java也应该按照官方的建议放在root目录下,这样才能扫描到Service和dao,不然还会引起,扫描不到注解的问题。