解决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