Springboot项目启动后访问不到Controller

时间:2022-09-30 01:30:23
1.搭建一个简单的Springboot项目,最开始将启动类main函数与controller放到一个类里,可以正常启动和访问,但是将两个分开再启动时访问就会报错:This application has no explicit mapping for /error, so you are seeing this as a fallback.

Springboot项目启动后访问不到Controller

2、解决方案

  在main函数启动类上加注解:@SpringBootApplication(scanBasePackages = "com") 问题即可解决。

@SpringBootApplication(scanBasePackages = "com")
@EnableAutoConfiguration
public class Application { public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
} }