[英]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.