SpringBoot嵌入式Tomcat JSPServlet选项 [英] SpringBoot Embedded Tomcat JSPServlet Options

查看:197
本文介绍了SpringBoot嵌入式Tomcat JSPServlet选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置JSPServlet的配置选项(如checkInterval,keepgeneration,modificationTestInterval等)的首选方法是什么?我之所以要更改它,是因为JSP编译存在一些奇怪的问题.我们正在使用可执行文件打包,并将'server.tomcat.basedir'属性设置为指向本地可访问的文件夹.生成的jsp java源文件和类文件显示的修改日期为1970年1月14日.在Windows资源管理器中,修改仅显示为空.在linux上,我们触摸了所有文件.但是,只要再次访问jsp文件,修改日期就可以追溯到1970年.我们怀疑这是否会导致每次访问jsp文件时都会对其进行编译,从而减慢了运行速度.但是,重新编译似乎只发生在linux环境中.有没有人遇到过这个问题?我们的环境:Spring Boot 1.2.2.BUILD-SNAPSHOT,Tomcat 8,JDK 1.8_025.

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.

推荐答案

您可以使用EmbeddedServletContainerCustomizer @Bean查找JSP servlet并配置其init参数.例如,在您的主要@Configuration类中:

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");
                }
            });
        }
    };
}

这篇关于SpringBoot嵌入式Tomcat JSPServlet选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆