Skip to content

Instantly share code, notes, and snippets.

@hho
Created March 7, 2017 10:54
Show Gist options
  • Save hho/f74dea7b034a5e9bcda8911125725f5e to your computer and use it in GitHub Desktop.
Save hho/f74dea7b034a5e9bcda8911125725f5e to your computer and use it in GitHub Desktop.
Turn off Tomcat's static resource cache (written for Spring Boot 1.3.5)
import org.apache.catalina.Context;
import org.apache.catalina.webresources.StandardRoot;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.stereotype.Component;
@Component
public class TomcatNoCacheCustomizer implements EmbeddedServletContainerCustomizer {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory) container;
factory.addContextCustomizers(new TomcatContextCustomizer() {
@Override
public void customize(Context context) {
StandardRoot resources = new StandardRoot(context);
resources.setCachingAllowed(false);
context.setResources(resources);
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment