Add Freemarker `prefer-file-system-access` support

Add a `spring.freemarker.prefer-file-system-access` property and update
FreeMarkerAutoConfiguration to support it.

Fixes gh-2901
pull/2901/merge
cohee016 10 years ago committed by Phillip Webb
parent 61fc4f3f12
commit d948ec5810

@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -91,6 +91,7 @@ public class FreeMarkerAutoConfiguration {
protected void applyProperties(FreeMarkerConfigurationFactory factory) {
factory.setTemplateLoaderPaths(this.properties.getTemplateLoaderPath());
factory.setPreferFileSystemAccess(this.properties.isPreferFileSystemAccess());
factory.setDefaultEncoding(this.properties.getCharset());
Properties settings = new Properties();
settings.putAll(this.properties.getSettings());

@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -48,6 +48,12 @@ public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties
*/
private String[] templateLoaderPath = new String[] { DEFAULT_TEMPLATE_LOADER_PATH };
/**
* Prefer file system access for template loading. File system access enables hot
* detection of template changes.
*/
private boolean preferFileSystemAccess = true;
public FreeMarkerProperties() {
super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
}
@ -64,6 +70,14 @@ public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties
return this.templateLoaderPath;
}
public boolean isPreferFileSystemAccess() {
return this.preferFileSystemAccess;
}
public void setPreferFileSystemAccess(boolean preferFileSystemAccess) {
this.preferFileSystemAccess = preferFileSystemAccess;
}
public void setTemplateLoaderPath(String... templateLoaderPaths) {
this.templateLoaderPath = templateLoaderPaths;
}

@ -197,6 +197,7 @@ content into your application; rather pick only the properties that you need.
spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=false
spring.freemarker.prefix=
spring.freemarker.prefer-file-system-access=true # prefer file system access for template loading
spring.freemarker.request-context-attribute=
spring.freemarker.settings.*=
spring.freemarker.suffix=.ftl

Loading…
Cancel
Save