简体   繁体   English

Spring 启动 JspServlet 自动配置

[英]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).我正在 Tomcat 中运行 Spring Boot 应用程序(请不要问:))并且我有一些需要映射到 /[az]*.jsp 的 URL(同样,客户要求)。

When running the application inside Tomcat, the JspServlet class is present and gets autoconfigured to handle everything ending in .jsp.在 Tomcat 中运行应用程序时,JspServlet 类会出现并自动配置为处理以 .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.正如M. Deinum所说, JspServlet没有被我的 Spring Boot 应用程序注册,而是由 Tomcat 的默认web.xml存在的默认 JspServlet 处理请求。 Adding the following bean solved the problem for me:添加以下 bean 为我解决了问题:

@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.application.properties虽然我不确定这是必要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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