How does Spring Boot control Tomcat cache?

前端 未结 3 1106
余生分开走
余生分开走 2021-01-02 02:39

I\'m porting 5 years old Spring MVC application with JSPs to Spring Boot. Therefore, according to sample in http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference

3条回答
  •  天命终不由人
    2021-01-02 03:17

    You can configure the cache size using a context customizer to configure the context with a customized StandardRoot:

    Java 7:

    @Bean
    public TomcatEmbeddedServletContainerFactory tomcatFactory() {
        TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
        tomcatFactory.addContextCustomizers(new TomcatContextCustomizer() {
    
            @Override
            public void customize(Context context) {
                StandardRoot standardRoot = new StandardRoot(context);
                standardRoot.setCacheMaxSize(40 * 1024);
            }
    
        });
        return tomcatFactory;
    }
    

    Java 8:

    @Bean
    public TomcatEmbeddedServletContainerFactory tomcatFactory() {
        TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
        tomcatFactory.addContextCustomizers((context) -> {
            StandardRoot standardRoot = new StandardRoot(context);
            standardRoot.setCacheMaxSize(40 * 1024);
        });
        return tomcatFactory;
    }
    

提交回复
热议问题