SpringBoot Embedded Tomcat JSPServlet Options

泄露秘密 提交于 2020-01-16 20:56:28

问题


What is the preferred way to set the configuration options for JSPServlet like checkInterval, keepgenerated, modificationTestInterval etc? The reason I am trying to alter it is because of some strange issues with JSP Compilations. We are using executable war packaging and setting the 'server.tomcat.basedir' property to point to a locally accessible folder. The generated jsp java source and class files shows modification date as Jan 14 1970. In windows explorer, the modification just shows up as empty. On linux, we did a touch on all the files. But as soon as the jsp file is accessed again, the modification date goes back to 1970. We doubt that this is causing the jsp files to be compiled every time it is accessed and thus slowing things down. However the recompilation only seems to happen in linux environment. Has anyone experienced this problem? Our environment : Spring Boot 1.2.2.BUILD-SNAPSHOT, Tomcat 8, JDK 1.8_025.


回答1:


You can use an EmbeddedServletContainerCustomizer @Bean to look up the JSP servlet and configure its init parameters. For example, in your main @Configuration class:

@Bean
public EmbeddedServletContainerCustomizer customizer() {
    return new EmbeddedServletContainerCustomizer() {

        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            if (container instanceof TomcatEmbeddedServletContainerFactory) {
                customizeTomcat((TomcatEmbeddedServletContainerFactory) container);
            }
        }

        private void customizeTomcat(TomcatEmbeddedServletContainerFactory tomcat) {
            tomcat.addContextCustomizers(new TomcatContextCustomizer() {

                @Override
                public void customize(Context context) {
                    Wrapper jsp = (Wrapper) context.findChild("jsp");
                    jsp.addInitParameter("modificationTestInterval", "10");
                }
            });
        }
    };
}



回答2:


Or you could just add the parameters to your application.properties file as described here: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html Look for:
server.jsp-servlet.init-parameters.*= # Init parameters used to configure the JSP servlet

For example:

server.jsp-servlet.init-parameters.modificationTestInterval=10


来源:https://stackoverflow.com/questions/28863340/springboot-embedded-tomcat-jspservlet-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!