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

时间:2019-07-17 15:02:51

标签: java spring-boot

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

import org.springframework.boot.autoconfigure.SpringBootApplication;

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

然后是Servlet初始化程序类

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来运行应用程序时,会出现以下消息:

  

Whitelabel错误页面

您能帮我解决这个问题吗? 预先感谢。

1 个答案:

答案 0 :(得分:1)

我想我有一个答案:

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

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