繁体   English   中英

如何解决 Spring Boot 应用程序中与“Whitelabel Error Page”相关的问题

[英]How to resolve the problem related to "Whitelabel Error Page" in a Spring Boot application

我正在尝试执行我的新 Spring Boot 应用程序。 前两个类是:

import org.springframework.boot.autoconfigure.SpringBootApplication;

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

然后是 servlet Initializer 类

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(UbbioneApplication.class);
    }
}

但是当我习惯于通过在控制台中编写mvn spring-boot:run来运行我的应用程序时,我会出现以下消息:

白标错误页面

请问你能帮我解决这个问题吗? 提前致谢。

我想我有一个答案:

我为我的应用程序创建了一个控制器,并更新了我的代码如下:

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"Name_controller_path"})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

然后我的控制器看起来像这样:

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Appcontroller {

    @RequestMapping(value = "/home", method = RequestMethod.GET)
    String home() {
        return "home";
    }
}

然后使用此路径查看您的执行情况: http://localhost:8080/home

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM