Skip to content

Commit 7e3bee3

Browse files
committed
Merge branch '2.0.x'
2 parents 3e25996 + 1774a28 commit 7e3bee3

File tree

4 files changed

+39
-12
lines changed

4 files changed

+39
-12
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerServletWebConfiguration.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.freemarker;
1818

19+
import javax.servlet.DispatcherType;
1920
import javax.servlet.Servlet;
2021

2122
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -25,6 +26,7 @@
2526
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
2627
import org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain;
2728
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
29+
import org.springframework.boot.web.servlet.FilterRegistrationBean;
2830
import org.springframework.context.annotation.Bean;
2931
import org.springframework.context.annotation.Configuration;
3032
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
@@ -74,8 +76,11 @@ public FreeMarkerViewResolver freeMarkerViewResolver() {
7476
@Bean
7577
@ConditionalOnMissingBean
7678
@ConditionalOnEnabledResourceChain
77-
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
78-
return new ResourceUrlEncodingFilter();
79+
public FilterRegistrationBean<ResourceUrlEncodingFilter> resourceUrlEncodingFilter() {
80+
FilterRegistrationBean<ResourceUrlEncodingFilter> registration = new FilterRegistrationBean<>(
81+
new ResourceUrlEncodingFilter());
82+
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ERROR);
83+
return registration;
7984
}
8085

8186
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.LinkedHashMap;
2121

2222
import javax.annotation.PostConstruct;
23+
import javax.servlet.DispatcherType;
2324

2425
import com.github.mxab.thymeleaf.extras.dataattribute.dialect.DataAttributeDialect;
2526
import nz.net.ultraq.thymeleaf.LayoutDialect;
@@ -52,6 +53,7 @@
5253
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
5354
import org.springframework.boot.context.properties.EnableConfigurationProperties;
5455
import org.springframework.boot.context.properties.PropertyMapper;
56+
import org.springframework.boot.web.servlet.FilterRegistrationBean;
5557
import org.springframework.context.ApplicationContext;
5658
import org.springframework.context.annotation.Bean;
5759
import org.springframework.context.annotation.Configuration;
@@ -70,6 +72,7 @@
7072
* @author Eddú Meléndez
7173
* @author Daniel Fernández
7274
* @author Kazuki Shimizu
75+
* @author Artsiom Yudovin
7376
*/
7477
@Configuration
7578
@EnableConfigurationProperties(ThymeleafProperties.class)
@@ -166,8 +169,11 @@ static class ThymeleafWebMvcConfiguration {
166169
@Bean
167170
@ConditionalOnMissingBean
168171
@ConditionalOnEnabledResourceChain
169-
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
170-
return new ResourceUrlEncodingFilter();
172+
public FilterRegistrationBean<ResourceUrlEncodingFilter> resourceUrlEncodingFilter() {
173+
FilterRegistrationBean<ResourceUrlEncodingFilter> registration = new FilterRegistrationBean<>(
174+
new ResourceUrlEncodingFilter());
175+
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ERROR);
176+
return registration;
171177
}
172178

173179
@Configuration

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationServletIntegrationTests.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,15 +17,18 @@
1717
package org.springframework.boot.autoconfigure.freemarker;
1818

1919
import java.io.StringWriter;
20+
import java.util.EnumSet;
2021
import java.util.Locale;
2122

23+
import javax.servlet.DispatcherType;
2224
import javax.servlet.http.HttpServletRequest;
2325

2426
import org.junit.After;
2527
import org.junit.Before;
2628
import org.junit.Test;
2729

2830
import org.springframework.boot.test.util.TestPropertyValues;
31+
import org.springframework.boot.web.servlet.FilterRegistrationBean;
2932
import org.springframework.mock.web.MockHttpServletRequest;
3033
import org.springframework.mock.web.MockHttpServletResponse;
3134
import org.springframework.mock.web.MockServletContext;
@@ -153,14 +156,18 @@ public void renderTemplate() throws Exception {
153156
@Test
154157
public void registerResourceHandlingFilterDisabledByDefault() {
155158
registerAndRefreshContext();
156-
assertThat(this.context.getBeansOfType(ResourceUrlEncodingFilter.class))
157-
.isEmpty();
159+
assertThat(this.context.getBeansOfType(FilterRegistrationBean.class)).isEmpty();
158160
}
159161

160162
@Test
161163
public void registerResourceHandlingFilterOnlyIfResourceChainIsEnabled() {
162164
registerAndRefreshContext("spring.resources.chain.enabled:true");
163-
assertThat(this.context.getBean(ResourceUrlEncodingFilter.class)).isNotNull();
165+
FilterRegistrationBean<?> registration = this.context
166+
.getBean(FilterRegistrationBean.class);
167+
assertThat(registration.getFilter())
168+
.isInstanceOf(ResourceUrlEncodingFilter.class);
169+
assertThat(registration).hasFieldOrPropertyWithValue("dispatcherTypes",
170+
EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));
164171
}
165172

166173
private void registerAndRefreshContext(String... env) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletAutoConfigurationTests.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,11 @@
1818

1919
import java.io.File;
2020
import java.util.Collections;
21+
import java.util.EnumSet;
2122
import java.util.Locale;
2223

24+
import javax.servlet.DispatcherType;
25+
2326
import nz.net.ultraq.thymeleaf.LayoutDialect;
2427
import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingStrategy;
2528
import org.junit.After;
@@ -37,6 +40,7 @@
3740
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
3841
import org.springframework.boot.test.rule.OutputCapture;
3942
import org.springframework.boot.test.util.TestPropertyValues;
43+
import org.springframework.boot.web.servlet.FilterRegistrationBean;
4044
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4145
import org.springframework.context.annotation.Bean;
4246
import org.springframework.context.annotation.Configuration;
@@ -61,6 +65,7 @@
6165
* @author Eddú Meléndez
6266
* @author Brian Clozel
6367
* @author Kazuki Shimizu
68+
* @author Artsiom Yudovin
6469
*/
6570
public class ThymeleafServletAutoConfigurationTests {
6671

@@ -205,14 +210,18 @@ public void renderNonWebAppTemplate() {
205210
@Test
206211
public void registerResourceHandlingFilterDisabledByDefault() {
207212
load(BaseConfiguration.class);
208-
assertThat(this.context.getBeansOfType(ResourceUrlEncodingFilter.class))
209-
.isEmpty();
213+
assertThat(this.context.getBeansOfType(FilterRegistrationBean.class)).isEmpty();
210214
}
211215

212216
@Test
213217
public void registerResourceHandlingFilterOnlyIfResourceChainIsEnabled() {
214218
load(BaseConfiguration.class, "spring.resources.chain.enabled:true");
215-
assertThat(this.context.getBean(ResourceUrlEncodingFilter.class)).isNotNull();
219+
FilterRegistrationBean<?> registration = this.context
220+
.getBean(FilterRegistrationBean.class);
221+
assertThat(registration.getFilter())
222+
.isInstanceOf(ResourceUrlEncodingFilter.class);
223+
assertThat(registration).hasFieldOrPropertyWithValue("dispatcherTypes",
224+
EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));
216225
}
217226

218227
@Test

0 commit comments

Comments
 (0)