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.

解决SpringBoot项目出现Whitelabel Error Page的问题(下)
解决SpringBoot项目出现Whitelabel Error Page的问题(下)

Whitelabel Error Page的问题就解决了!

当然,@ComponentScan(basePackages="com.example")不是必须的。
解决SpringBoot项目出现Whitelabel Error Page的问题(下)

SpringBoot默认会扫描启动类所在的包及其子包。启动类是注解@SpringBootApplication标注的类。

出现Whitelabel Error Page问题的情况:

  • Controller等组件不在SpringBoot的扫描路径中。
  • 没有在application.properties文件中指定server.servlet.context-path

参考:

相关文章:

  • 2022-12-23
  • 2021-11-01
  • 2021-05-24
  • 2022-12-23
  • 2021-04-28
  • 2021-05-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-14
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2021-12-21
相关资源
相似解决方案