I'm using spring mvc v3 with freemarker views and cannot disable caching. I tried by setting cache to false in viewResolver element in (spring-servlet.xml) but didn't work.
Basically what I'd like to the do some changes in freemarker and see these changes in the browser with refresh only (w/o restarting the application)
Any hints how to do that?
In my XML the following was successful:
<bean id="freemarkerMailConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
<property name="templateLoaderPaths" value="classpath:emailtemplates/task,classpath:emailtemplates/user"/>
<!-- Activate the following to disable template caching -->
<property name="freemarkerSettings" value="cache_storage=freemarker.cache.NullCacheStorage" />
</bean>
This is my mail config, but the freemarkerConfig should be interesting four you, too.
I dont use to configure freemarker with xml configurations but with @Configuration
annotated classes; cause i rather the Spring-Boot´ style. So you can disable the freemarker´s cache like this:
@Bean
public FreeMarkerConfigurer freeMarkerConfigurer() throws IOException, TemplateException
{
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer()
{
@Override
protected void postProcessConfiguration(freemarker.template.Configuration config) throws IOException, TemplateException
{
ClassTemplateLoader classTplLoader = new ClassTemplateLoader(context.getClassLoader(), "/templates");
ClassTemplateLoader baseMvcTplLoader = new ClassTemplateLoader(FreeMarkerConfigurer.class, ""); //TODO tratar de acceder a spring.ftl de forma directa
MultiTemplateLoader mtl = new MultiTemplateLoader(new TemplateLoader[]
{
classTplLoader,
baseMvcTplLoader
});
config.setTemplateLoader(mtl);
config.setCacheStorage(new NullCacheStorage());
}
};
configurer.setDefaultEncoding("UTF-8");
configurer.setPreferFileSystemAccess(false);
return configurer;
}
The key is in:
config.setCacheStorage(new NullCacheStorage());
But you can also use this instruction instead:
config.setTemplateUpdateDelayMilliseconds(0);
It should work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With