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
4e177eee
Commit
4e177eee
authored
Feb 11, 2016
by
Kazuki Shimizu
Committed by
Andy Wilkinson
Feb 11, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Auto-configure ResourceUrlEncodingFilter when using FreeMarker
Closes gh-5126
parent
1f106ddf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
5 deletions
+32
-5
FreeMarkerAutoConfiguration.java
...autoconfigure/freemarker/FreeMarkerAutoConfiguration.java
+11
-1
FreeMarkerAutoConfigurationTests.java
...onfigure/freemarker/FreeMarkerAutoConfigurationTests.java
+17
-1
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+4
-3
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java
View file @
4e177eee
/*
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebAppli
...
@@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnNotWebAppli
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
;
import
org.springframework.boot.autoconfigure.template.TemplateLocation
;
import
org.springframework.boot.autoconfigure.template.TemplateLocation
;
import
org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain
;
import
org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration
;
import
org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
...
@@ -42,6 +43,7 @@ import org.springframework.context.annotation.Bean;
...
@@ -42,6 +43,7 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
;
import
org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
;
import
org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean
;
import
org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean
;
import
org.springframework.web.servlet.resource.ResourceUrlEncodingFilter
;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerConfig
;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerConfig
;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver
;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver
;
...
@@ -51,6 +53,7 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
...
@@ -51,6 +53,7 @@ import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
*
*
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Dave Syer
* @author Dave Syer
* @author Kazuki Shimizu
* @since 1.1.0
* @since 1.1.0
*/
*/
@Configuration
@Configuration
...
@@ -149,5 +152,12 @@ public class FreeMarkerAutoConfiguration {
...
@@ -149,5 +152,12 @@ public class FreeMarkerAutoConfiguration {
return
resolver
;
return
resolver
;
}
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledResourceChain
public
ResourceUrlEncodingFilter
resourceUrlEncodingFilter
()
{
return
new
ResourceUrlEncodingFilter
();
}
}
}
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java
View file @
4e177eee
/*
/*
* Copyright 2012-201
4
the original author or authors.
* Copyright 2012-201
6
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -36,6 +36,7 @@ import org.springframework.mock.web.MockServletContext;
...
@@ -36,6 +36,7 @@ import org.springframework.mock.web.MockServletContext;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.resource.ResourceUrlEncodingFilter
;
import
org.springframework.web.servlet.support.RequestContext
;
import
org.springframework.web.servlet.support.RequestContext
;
import
org.springframework.web.servlet.view.AbstractTemplateViewResolver
;
import
org.springframework.web.servlet.view.AbstractTemplateViewResolver
;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
;
...
@@ -48,6 +49,7 @@ import static org.hamcrest.Matchers.containsString;
...
@@ -48,6 +49,7 @@ import static org.hamcrest.Matchers.containsString;
* Tests for {@link FreeMarkerAutoConfiguration}.
* Tests for {@link FreeMarkerAutoConfiguration}.
*
*
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Kazuki Shimizu
*/
*/
public
class
FreeMarkerAutoConfigurationTests
{
public
class
FreeMarkerAutoConfigurationTests
{
...
@@ -189,6 +191,20 @@ public class FreeMarkerAutoConfigurationTests {
...
@@ -189,6 +191,20 @@ public class FreeMarkerAutoConfigurationTests {
}
}
}
}
@Test
public
void
registerResourceHandlingFilterDisabledByDefault
()
throws
Exception
{
registerAndRefreshContext
();
assertThat
(
this
.
context
.
getBeansOfType
(
ResourceUrlEncodingFilter
.
class
))
.
isEmpty
();
}
@Test
public
void
registerResourceHandlingFilterOnlyIfResourceChainIsEnabled
()
throws
Exception
{
registerAndRefreshContext
(
"spring.resources.chain.enabled:true"
);
assertThat
(
this
.
context
.
getBean
(
ResourceUrlEncodingFilter
.
class
)).
isNotNull
();
}
private
void
registerAndRefreshContext
(
String
...
env
)
{
private
void
registerAndRefreshContext
(
String
...
env
)
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
env
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
env
);
this
.
context
.
register
(
FreeMarkerAutoConfiguration
.
class
);
this
.
context
.
register
(
FreeMarkerAutoConfiguration
.
class
);
...
...
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
4e177eee
...
@@ -1509,9 +1509,10 @@ for all static resources, effectively adding a content hash in URLs, such as
...
@@ -1509,9 +1509,10 @@ for all static resources, effectively adding a content hash in URLs, such as
----
----
NOTE: Links to resources are rewritten at runtime in template, thanks to a
NOTE: Links to resources are rewritten at runtime in template, thanks to a
`ResourceUrlEncodingFilter`, auto-configured for Thymeleaf and Velocity. You should
`ResourceUrlEncodingFilter`, auto-configured for Thymeleaf, Velocity and FreeMarker. You
manually declare this filter when using JSPs. Other template engines aren't automatically
should manually declare this filter when using JSPs. Other template engines aren't
supported right now, but can be with custom template macros/helpers and the use of the
automatically supported right now, but can be with custom template macros/helpers and the
use of the
{spring-javadoc}/web/servlet/resource/ResourceUrlProvider.{dc-ext}[`ResourceUrlProvider`].
{spring-javadoc}/web/servlet/resource/ResourceUrlProvider.{dc-ext}[`ResourceUrlProvider`].
When loading resources dynamically with, for example, a JavaScript module loader, renaming
When loading resources dynamically with, for example, a JavaScript module loader, renaming
...
...
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