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
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;
}
I've been having the same problem for a while, but Andy Wilkinson's hint set me on the right track. What worked for me was to set the cache as Andy did, but then also explicitly set the resources in context.
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory() {
@Override
protected void postProcessContext(Context context) {
final int cacheSize = 40 * 1024;
StandardRoot standardRoot = new StandardRoot(context);
standardRoot.setCacheMaxSize(cacheSize);
context.setResources(standardRoot); // This is what made it work in my case.
logger.info(String.format("New cache size (KB): %d", context.getResources().getCacheMaxSize()));
}
};
return tomcatFactory;
}
Hope this helps!
Referring to there answer here, I created src/main/webapp/META-INF/context.xml and added the following.
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resources cachingAllowed="true" cacheMaxSize="204800" />
</Context>