解決SpringBoot項目出現Whitelabel Error Page的問題(下)


3.解決Whitelabel Error Page的問題

# application.properties
server.servlet.context-path=/restful-demo
package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages="com.example")
public class RestfulDemoApplication {

    public static void main(String[] args) {
          SpringApplication.run(RestfulDemoApplication.class, args);
    }

}

@ComponentScan(basePackages="com.example"):Tells Spring to look for other components, configurations, and services in the com/example package, letting it find the controllers.


Whitelabel Error Page的問題就解決了!

當然,@ComponentScan(basePackages="com.example")不是必須的。

SpringBoot默認會掃描啟動類所在的包及其子包。啟動類是注解@SpringBootApplication標注的類。

出現Whitelabel Error Page問題的情況:

  • Controller等組件不在SpringBoot的掃描路徑中。
  • 沒有在application.properties文件中指定server.servlet.context-path

參考:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM