Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
8a1e010d
Commit
8a1e010d
authored
Oct 29, 2014
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow multiple templateLoaderPaths to be configured for FreeMarker
Closes gh-1767
parent
ef245593
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
11 deletions
+28
-11
FreeMarkerAutoConfiguration.java
...autoconfigure/freemarker/FreeMarkerAutoConfiguration.java
+15
-5
FreeMarkerProperties.java
...k/boot/autoconfigure/freemarker/FreeMarkerProperties.java
+4
-4
FreeMarkerAutoConfigurationTests.java
...onfigure/freemarker/FreeMarkerAutoConfigurationTests.java
+8
-1
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+1
-1
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java
View file @
8a1e010d
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
freemarker
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Properties
;
import
javax.annotation.PostConstruct
;
...
...
@@ -65,10 +67,18 @@ public class FreeMarkerAutoConfiguration {
@PostConstruct
public
void
checkTemplateLocationExists
()
{
if
(
this
.
properties
.
isCheckTemplateLocation
())
{
Resource
resource
=
this
.
resourceLoader
.
getResource
(
this
.
properties
.
getTemplateLoaderPath
());
Assert
.
state
(
resource
.
exists
(),
"Cannot find template location: "
+
resource
+
" (please add some templates, "
Resource
templatePathResource
=
null
;
List
<
Resource
>
resources
=
new
ArrayList
<
Resource
>();
for
(
String
templateLoaderPath
:
this
.
properties
.
getTemplateLoaderPath
())
{
Resource
resource
=
this
.
resourceLoader
.
getResource
(
templateLoaderPath
);
resources
.
add
(
resource
);
if
(
resource
.
exists
())
{
templatePathResource
=
resource
;
break
;
}
}
Assert
.
notNull
(
templatePathResource
,
"Cannot find template location(s): "
+
resources
+
" (please add some templates, "
+
"check your FreeMarker configuration, or set "
+
"spring.freemarker.checkTemplateLocation=false)"
);
}
...
...
@@ -80,7 +90,7 @@ public class FreeMarkerAutoConfiguration {
protected
FreeMarkerProperties
properties
;
protected
void
applyProperties
(
FreeMarkerConfigurationFactory
factory
)
{
factory
.
setTemplateLoaderPath
(
this
.
properties
.
getTemplateLoaderPath
());
factory
.
setTemplateLoaderPath
s
(
this
.
properties
.
getTemplateLoaderPath
());
factory
.
setDefaultEncoding
(
this
.
properties
.
getCharSet
());
Properties
settings
=
new
Properties
();
settings
.
putAll
(
this
.
properties
.
getSettings
());
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerProperties.java
View file @
8a1e010d
...
...
@@ -40,7 +40,7 @@ public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties
private
Map
<
String
,
String
>
settings
=
new
HashMap
<
String
,
String
>();
private
String
templateLoaderPath
=
DEFAULT_TEMPLATE_LOADER_PATH
;
private
String
[]
templateLoaderPath
=
new
String
[]
{
DEFAULT_TEMPLATE_LOADER_PATH
}
;
public
FreeMarkerProperties
()
{
super
(
DEFAULT_PREFIX
,
DEFAULT_SUFFIX
);
...
...
@@ -54,12 +54,12 @@ public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties
this
.
settings
=
settings
;
}
public
String
getTemplateLoaderPath
()
{
public
String
[]
getTemplateLoaderPath
()
{
return
this
.
templateLoaderPath
;
}
public
void
setTemplateLoaderPath
(
String
templateLoaderPath
)
{
this
.
templateLoaderPath
=
templateLoaderPath
;
public
void
setTemplateLoaderPath
(
String
...
templateLoaderPaths
)
{
this
.
templateLoaderPath
=
templateLoaderPath
s
;
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java
View file @
8a1e010d
...
...
@@ -73,7 +73,7 @@ public class FreeMarkerAutoConfigurationTests {
@Test
(
expected
=
BeanCreationException
.
class
)
public
void
nonExistentTemplateLocation
()
{
registerAndRefreshContext
(
"spring.freemarker.templateLoaderPath:"
+
"classpath:/does-not-exist/"
);
+
"classpath:/does-not-exist/
,classpath:/also-does-not-exist
"
);
}
@Test
...
...
@@ -83,6 +83,13 @@ public class FreeMarkerAutoConfigurationTests {
+
"classpath:/templates/empty-directory/"
);
}
@Test
public
void
nonExistentLocationAndEmptyLocation
()
{
new
File
(
"target/test-classes/templates/empty-directory"
).
mkdir
();
registerAndRefreshContext
(
"spring.freemarker.templateLoaderPath:"
+
"classpath:/does-not-exist/,classpath:/templates/empty-directory/"
);
}
@Test
public
void
defaultViewResolution
()
throws
Exception
{
registerAndRefreshContext
();
...
...
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
8a1e010d
...
...
@@ -123,7 +123,7 @@ content into your application; rather pick only the properties that you need.
spring.freemarker.requestContextAttribute=
spring.freemarker.settings.*=
spring.freemarker.suffix=.ftl
spring.freemarker.templateLoaderPath=classpath:/templates/
spring.freemarker.templateLoaderPath=classpath:/templates/
# comma-separated list
spring.freemarker.viewNames= # whitelist of view names that can be resolved
# GROOVY TEMPLATES ({sc-spring-boot-autoconfigure}/groovy/template/GroovyTemplateAutoConfiguration.{sc-ext}[GroovyTemplateAutoConfiguration])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment