我有一个spring boot Web应用程序,正在将它作为war文件部署在tomcat中。我不希望用户显示白色标签错误页面。我对此有所进步,但需要将其重新定向到错误页面。
下面的代码是/ error白色标签错误页面是自定义错误消息。但是我希望将其重定向到我的Web应用程序资源中模板文件夹下的error.jsp或error.html。我尝试将@RestController更改为@Controller,但没有运气。
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";
}
}
相依性
<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>
参考方案
关闭application.properties
中的whitelabel错误页面
server.error.whitelabel.enabled=false
See also Spring Boot Docs
Spring Boot索引未加载 - java我有一个Spring Boot应用程序。我没有使用@EnableWebMvc,并且我的资源在src/main/resources/static文件夹中。当我尝试加载localhost:8080/ui/时,它只是下载一个随机文件(类型:八位字节流)。如果我直接使用/ui/index.html则可以。我也在使用WebSecurityConfigurerAdapt…
Spring MVC拦截器映射问题 - java我有这段XML:<mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/statics/**" /> <bean class="com.company.website.servlet.StaticsHandlerIntercept…
Heroku Spring Boot Web服务始终返回404,但不在本地主机上 - java我已经开发了一个Web服务,正在尝试将其部署到Heroku。看来成功了,尽管每当我尝试调用我的URL之一时,我都会得到一个404。我知道这意味着资源不可用,但在localhost上运行良好。Heroku部署的输出是标准的Spring引导,但缺少以下内容:2016-05-23 22:29:22.145 INFO 15785 --- [ main] s.w.s.…
在Maven中创建模块 - java我创建了这个maven子项目,它将包含项目的域对象: <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-start…
无法将应用程序日志保存到文件 - java我正在创建一个简单的Spring Boot应用程序,该应用程序会在API调用上产生结果。该应用程序按预期工作,但我无法将日志打印到文件中。日志仅在控制台中显示。这是我的pom文件:<?xml version="1.0" encoding="UTF-8"?> <project xmlns="h…