Ich habe eine Spring Boot-Webanwendung, die ich als eine Kriegsdatei in Tomcat bereitstellen. Ich möchte nicht, dass der Benutzer die White-Label-Fehlerseite anzeigt. Ich bin ein wenig weitergekommen, muss aber auf die Fehlerseite umleiten.Spring Boot Entfernen Whitelabel Fehler Seite für Webanwendung
Der folgende Code ist/Fehler White-Label-Fehlerseite ist benutzerdefinierte Fehlermeldung. Aber ich möchte, dass es auf eine error.jsp oder error.html umgeleitet wird, die unter dem Vorlagenordner in den Ressourcen meiner Webanwendung verfügbar ist. Ich versuchte, die @RestController zu @Controller ohne Glück zu ändern.
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CustomErrorController implements ErrorController {
private static final String PATH = "/error";
@RequestMapping(value = PATH)
public String error() {
return "Unexpected error has happened.Please contact administrator!!!";
}
@Override
public String getErrorPath() {
System.out.println("-- Error Page GET --");
return "error";
}
}
Abhängigkeit
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>4.0.1.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>spring-aop</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- Provided (for embedded war support) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>1.2.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4</version>
</dependency>
Dies wird umleiten Fehler page.Its ist nicht neu lenk, um benutzerdefinierte Fehlerseite Serverlet – Manu