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);
	}
}




免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM