我在参考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);
	}
}



相关文章:

  • 2022-12-23
  • 2021-10-16
  • 2021-09-13
  • 2021-06-14
  • 2021-08-25
  • 2021-11-14
  • 2021-10-06
猜你喜欢
  • 2021-06-17
  • 2022-02-11
  • 2021-08-04
  • 2021-12-19
  • 2021-08-10
相关资源
相似解决方案