spring boot 扫描不到controller情形一

我在参考spring官方guid中写了一个小项目,由于idea将启动项放在demo包下无法扫描
到java包下的controller类会报404。
解决方法:
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);
	}
}



posted @ 2017-10-16 10:59  木子归零  阅读(8187)  评论(1编辑  收藏  举报