Created
March 7, 2017 10:54
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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