Spring Boot : Whitelabel Error Page

Spring Boot : Whitelabel Error Page解决方案

新搭建的Spring Boot,maven工程

pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.adtec.springboot</groupId>
    <artifactId>first</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>first</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <!-- Spring Boot Maven插件 -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

入口程序

package com.adtec.springbot.first;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
@SpringBootApplication
public class FirstApplication {

    public static void main(String[] args) {
        SpringApplication.run(FirstApplication.class, args);
    }
     @RequestMapping("/home")
     public String index(){
     return "Hello Spring Boot";
     }
}

启动日志


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.3.RELEASE)

2018-06-29 17:47:41.162  INFO 13620 --- [           main] c.a.springbot.first.FirstApplication     : Starting FirstApplication on DESKTOP-5KCJ513 with PID 13620 (C:\Users\pc\Desktop\first\first\target\classes started by pc in C:\Users\pc\Desktop\first\first)
2018-06-29 17:47:41.167  INFO 13620 --- [           main] c.a.springbot.first.FirstApplication     : No active profile set, falling back to default profiles: default
2018-06-29 17:47:41.317  INFO 13620 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4c40b76e: startup date [Fri Jun 29 17:47:41 CST 2018]; root of context hierarchy
2018-06-29 17:47:43.877  INFO 13620 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2018-06-29 17:47:43.930  INFO 13620 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-06-29 17:47:43.932  INFO 13620 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31
2018-06-29 17:47:43.953  INFO 13620 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [F:\soft\Java\jdk1.8.0_102\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;F:/soft/Java/jdk1.8.0_102/bin/../jre/bin/server;F:/soft/Java/jdk1.8.0_102/bin/../jre/bin;F:/soft/Java/jdk1.8.0_102/bin/../jre/lib/amd64;F:\soft\erl5.10.4\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;F:\soft\Java\jdk1.8.0_102\bin;C:\Program Files\MySQL\MySQL Server 5.6\bin;F:\soft\apache-maven-3.5.0\bin;C:\Users\pc\Desktop\node-v8.4.0-win-x64\node-v8.4.0-win-x64;F:\soft\PuTTY\;F:\soft\TortoiseSVN\bin;F:\soft\Python\Python36;C:\Users\pc\AppData\Local\Microsoft\WindowsApps;;C:\Users\pc\Desktop\eclipse;;.]
2018-06-29 17:47:44.202  INFO 13620 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-06-29 17:47:44.202  INFO 13620 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2890 ms
2018-06-29 17:47:44.527  INFO 13620 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Servlet dispatcherServlet mapped to [/]
2018-06-29 17:47:44.537  INFO 13620 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-06-29 17:47:44.537  INFO 13620 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-06-29 17:47:44.537  INFO 13620 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-06-29 17:47:44.537  INFO 13620 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-06-29 17:47:44.760  INFO 13620 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-06-29 17:47:45.167  INFO 13620 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@4c40b76e: startup date [Fri Jun 29 17:47:41 CST 2018]; root of context hierarchy
2018-06-29 17:47:45.368  INFO 13620 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/home]}" onto public java.lang.String com.adtec.springbot.first.FirstApplication.index()
2018-06-29 17:47:45.381  INFO 13620 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-06-29 17:47:45.383  INFO 13620 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-06-29 17:47:45.434  INFO 13620 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-06-29 17:47:45.435  INFO 13620 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-06-29 17:47:45.904  INFO 13620 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-06-29 17:47:45.980  INFO 13620 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2018-06-29 17:47:45.988  INFO 13620 --- [           main] c.a.springbot.first.FirstApplication     : Started FirstApplication in 5.364 seconds (JVM running for 6.034)
2018-06-29 17:47:46.095  INFO 13620 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2018-06-29 17:47:46.095  INFO 13620 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2018-06-29 17:47:46.142  INFO 13620 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 47 ms

访问效果
这里写图片描述

问题原因:

少了一个注解@RestController

package com.adtec.springbot.first;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class FirstApplication {

    public static void main(String[] args) {
        SpringApplication.run(FirstApplication.class, args);
    }
     @RequestMapping("/home")
     public String index(){
     return "Hello Spring Boot";
     }
}

结果
这里写图片描述

猜你喜欢

转载自blog.csdn.net/leisure_life/article/details/80860564