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