1. 程式人生 > >Springboot專案啟動後訪問不到Controller

Springboot專案啟動後訪問不到Controller

1.搭建一個簡單的Springboot專案,最開始將啟動類main函式與controller放到一個類裡,可以正常啟動和訪問,但是將兩個分開再啟動時訪問就會報錯:This application has no explicit mapping for /error, so you are seeing this as a fallback.

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

}