When the springboot / error page status is 999, 80% of the people will not

to configure
server:
  port: 8000
  servlet:
    context-path: "/api"
  compression:
    enabled: false

Just contacted with SpringBoot, HelloWolrd has been implemented. The normal 404 was also handled successfully. But 127.0.0.1:8000/api/error has always been "Whitelabel Error Page". Tried a lot of methods, still can't solve.
I need to add status 999 to ErrorPageConifg, but I don't know how to add it. In theory, we can expand HttpStatus, but this is read-only.

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Jan 14 16:29:43 CST 2020
There was an unexpected error (type=None, status=999).
No message available
 

ErrorPageConifg.java

package cn.vlice.aox.AoxServer.config;

import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;

@Configuration
public class ErrorPageConifg {
    @Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
        return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
            @Override
            public void customize(ConfigurableWebServerFactory factory) {
                ErrorPage page404 = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404");
                ErrorPage page500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500");
                factory.addErrorPages(page404, page500);
            }
        };
    }
}
 

ErrorPageController.java

package cn.vlice.aox.AoxServer.controller;

import cn.vlice.aox.AoxServer.data.Request;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/error")
public class ErrorPageController {
    @RequestMapping("/999")
    public Request toPage999() {
        HttpStatus status = HttpStatus.valueOf(404);
        return Request.error(status.getReasonPhrase(), status.value());
    }

    @RequestMapping("/404")
    public Request toPage404() {
        HttpStatus status = HttpStatus.valueOf(404);
        return Request.error(status.getReasonPhrase(), status.value());
    }

    @RequestMapping("/500")
    public Request toPage500() {
        HttpStatus status = HttpStatus.valueOf(500);
        return Request.error(status.getReasonPhrase(), status.value());
    }
}
 springboot

Violet ice, a UP who is busy with work and has no time to record video

 
Postscript 1.3 months ago
 

Problem solved

public class ErrorPageController implements ErrorController {
...

    @Override
    public String getErrorPath() {
        return "/error/404";
    }
}

Finally note: the theory of light is not enough. By the way, I'd like to present you a set of 2020 latest JAVA architecture project practical course and interview question bank of Dachang, which can be found under the transformation of seven bar umbrella bar and Zero clothing umbrella (Digital homophony). There are many new JAVA architecture projects in it, as well as communication with old drivers
The text and pictures of this article come from the Internet and my own ideas. They are only for learning and communication. They have no commercial use. The copyright belongs to the original author. If you have any questions, please contact us in time for handling

Tags: Java SpringBoot

Posted on Wed, 13 May 2020 10:17:57 -0400 by pneudralics