Merge branch '2.0.x'
This commit is contained in:
commit
7e3bee35d7
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.freemarker;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.Servlet;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
|
@ -25,6 +26,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
|
||||
|
@ -74,8 +76,11 @@ class FreeMarkerServletWebConfiguration extends AbstractFreeMarkerConfiguration
|
|||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnEnabledResourceChain
|
||||
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
|
||||
return new ResourceUrlEncodingFilter();
|
||||
public FilterRegistrationBean<ResourceUrlEncodingFilter> resourceUrlEncodingFilter() {
|
||||
FilterRegistrationBean<ResourceUrlEncodingFilter> registration = new FilterRegistrationBean<>(
|
||||
new ResourceUrlEncodingFilter());
|
||||
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ERROR);
|
||||
return registration;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.util.Collection;
|
|||
import java.util.LinkedHashMap;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.DispatcherType;
|
||||
|
||||
import com.github.mxab.thymeleaf.extras.dataattribute.dialect.DataAttributeDialect;
|
||||
import nz.net.ultraq.thymeleaf.LayoutDialect;
|
||||
|
@ -52,6 +53,7 @@ import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfigurat
|
|||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -70,6 +72,7 @@ import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
|
|||
* @author Eddú Meléndez
|
||||
* @author Daniel Fernández
|
||||
* @author Kazuki Shimizu
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(ThymeleafProperties.class)
|
||||
|
@ -166,8 +169,11 @@ public class ThymeleafAutoConfiguration {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnEnabledResourceChain
|
||||
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
|
||||
return new ResourceUrlEncodingFilter();
|
||||
public FilterRegistrationBean<ResourceUrlEncodingFilter> resourceUrlEncodingFilter() {
|
||||
FilterRegistrationBean<ResourceUrlEncodingFilter> registration = new FilterRegistrationBean<>(
|
||||
new ResourceUrlEncodingFilter());
|
||||
registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ERROR);
|
||||
return registration;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
@ -17,8 +17,10 @@
|
|||
package org.springframework.boot.autoconfigure.freemarker;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.junit.After;
|
||||
|
@ -26,6 +28,7 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
@ -153,14 +156,18 @@ public class FreeMarkerAutoConfigurationServletIntegrationTests {
|
|||
@Test
|
||||
public void registerResourceHandlingFilterDisabledByDefault() {
|
||||
registerAndRefreshContext();
|
||||
assertThat(this.context.getBeansOfType(ResourceUrlEncodingFilter.class))
|
||||
.isEmpty();
|
||||
assertThat(this.context.getBeansOfType(FilterRegistrationBean.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerResourceHandlingFilterOnlyIfResourceChainIsEnabled() {
|
||||
registerAndRefreshContext("spring.resources.chain.enabled:true");
|
||||
assertThat(this.context.getBean(ResourceUrlEncodingFilter.class)).isNotNull();
|
||||
FilterRegistrationBean<?> registration = this.context
|
||||
.getBean(FilterRegistrationBean.class);
|
||||
assertThat(registration.getFilter())
|
||||
.isInstanceOf(ResourceUrlEncodingFilter.class);
|
||||
assertThat(registration).hasFieldOrPropertyWithValue("dispatcherTypes",
|
||||
EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));
|
||||
}
|
||||
|
||||
private void registerAndRefreshContext(String... env) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
|
@ -18,8 +18,11 @@ package org.springframework.boot.autoconfigure.thymeleaf;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
|
||||
import nz.net.ultraq.thymeleaf.LayoutDialect;
|
||||
import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingStrategy;
|
||||
import org.junit.After;
|
||||
|
@ -37,6 +40,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
|||
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -61,6 +65,7 @@ import static org.hamcrest.Matchers.containsString;
|
|||
* @author Eddú Meléndez
|
||||
* @author Brian Clozel
|
||||
* @author Kazuki Shimizu
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
public class ThymeleafServletAutoConfigurationTests {
|
||||
|
||||
|
@ -205,14 +210,18 @@ public class ThymeleafServletAutoConfigurationTests {
|
|||
@Test
|
||||
public void registerResourceHandlingFilterDisabledByDefault() {
|
||||
load(BaseConfiguration.class);
|
||||
assertThat(this.context.getBeansOfType(ResourceUrlEncodingFilter.class))
|
||||
.isEmpty();
|
||||
assertThat(this.context.getBeansOfType(FilterRegistrationBean.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerResourceHandlingFilterOnlyIfResourceChainIsEnabled() {
|
||||
load(BaseConfiguration.class, "spring.resources.chain.enabled:true");
|
||||
assertThat(this.context.getBean(ResourceUrlEncodingFilter.class)).isNotNull();
|
||||
FilterRegistrationBean<?> registration = this.context
|
||||
.getBean(FilterRegistrationBean.class);
|
||||
assertThat(registration.getFilter())
|
||||
.isInstanceOf(ResourceUrlEncodingFilter.class);
|
||||
assertThat(registration).hasFieldOrPropertyWithValue("dispatcherTypes",
|
||||
EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue