简体   繁体   中英

Spring boot JspServlet autoconfiguration

I'm running a Spring boot application inside a Tomcat (don't ask please :)) and I have some URLs that need to be mapped to /[az]*.jsp (again, customer requirement).

When running the application inside Tomcat, the JspServlet class is present and gets autoconfigured to handle everything ending in .jsp. How can I disable this autoconfiguration?

Thanks.

As M. Deinum said, the JspServlet is not being registered by my Spring Boot application but instead the default JspServlet present in Tomcat's default web.xml handles the request. Adding the following bean solved the problem for me:

@Autowired
private DispatcherServlet dispatcherServlet;

@Bean
public ServletRegistrationBean servletRegistrationBean() {
    // Necessary so that JSPs don't get handled by the default JspServlet present in the default web.xml
    return new ServletRegistrationBean(dispatcherServlet, "/", "*.jsp");
}

Additionally, I set

server.servlet.jsp.registered=false

in the application.properties although I'm not sure that's necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM