ajoshow
ajoshow

Reputation: 38

Unable redirect view inside ErrorViewResolver on Spring Boot 1.5.20.RELEASE

I am experimenting with ErrorViewResolver, trying to redirect view from the ModelAndView, but it keeps shows 404 http status error. The Spring Boot version I am using is 1.5.20.RELEASE. While I downgrade the version to 1.5.1x.RELEASE or upgrade to 2.x, it is redirected successfully.

Here's sample code:

@Component
public class MyErrorResolveView implements ErrorViewResolver {
    @Override
    public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map<String, Object> model) {
        // return new ModelAndView("test"); // this work fine
        return new ModelAndView("redirect:/page"); 
    }
}

application.properties

spring.mvc.view.prefix=/WEB-INF/pages/
spring.mvc.view.suffix=.jsp
server.error.whitelabel.enabled=false

Controller

 @GetMapping(value =  {"/page"})
 public ModelAndView page() {
    return new ModelAndView("test");
 }

Spring Security:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.cors().disable().csrf().disable().authorizeRequests().anyRequest().permitAll();
}

JSP location: src/main/webapp/WEB-INF/pages/test.jsp

Run with bootRun, try to access http://localhost:8080/notExist, expected to see "test" page, but actual see HTTP ERROR 404 page.

I am not sure is there any configuration I missed, or it is a bug/feature for Spring Boot 1.5.20.RELEASE?

Upvotes: 1

Views: 1379

Answers (1)

study
study

Reputation: 5817

Spring Boot 1.5.20.RELEASE depends on tomcat-embed-core 8.5.39 and the tomcat version has some breaking changes. Try to use old tomcat-embed-core version.

Upvotes: 1

Related Questions