Remove deprecated code flagged for removal

Closes gh-27303
This commit is contained in:
Stephane Nicoll
2021-07-14 11:49:52 +02:00
parent 46ad4c6f98
commit dc5acb0019
82 changed files with 183 additions and 2508 deletions

View File

@@ -1,50 +0,0 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.batch;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.boot.ApplicationRunner;
/**
* {@link ApplicationRunner} to {@link JobLauncher launch} Spring Batch jobs. Runs all
* jobs in the surrounding context by default. Can also be used to launch a specific job
* by providing a jobName.
*
* @author Dave Syer
* @author Jean-Pierre Bergamin
* @author Mahmoud Ben Hassine
* @since 1.0.0
* @deprecated since 2.3.0 for removal in 2.6.0 in favor of
* {@link JobLauncherApplicationRunner}
*/
@Deprecated
public class JobLauncherCommandLineRunner extends JobLauncherApplicationRunner {
/**
* Create a new {@link JobLauncherCommandLineRunner}.
* @param jobLauncher to launch jobs
* @param jobExplorer to check the job repository for previous executions
* @param jobRepository to check if a job instance exists with the given parameters
* when running a job
*/
public JobLauncherCommandLineRunner(JobLauncher jobLauncher, JobExplorer jobExplorer, JobRepository jobRepository) {
super(jobLauncher, jobExplorer, jobRepository);
}
}

View File

@@ -1,82 +0,0 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.hazelcast;
import java.io.IOException;
import java.net.URL;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.client.config.XmlClientConfigBuilder;
import com.hazelcast.client.config.YamlClientConfigBuilder;
import com.hazelcast.core.HazelcastInstance;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Factory that can be used to create a client {@link HazelcastInstance}.
*
* @author Vedran Pavic
* @since 2.0.0
* @deprecated since 2.4.3 for removal in 2.6 in favor of using the Hazelcast API directly
*/
@Deprecated
public class HazelcastClientFactory {
private final ClientConfig clientConfig;
/**
* Create a {@link HazelcastClientFactory} for the specified configuration location.
* @param clientConfigLocation the location of the configuration file
* @throws IOException if the configuration location could not be read
*/
public HazelcastClientFactory(Resource clientConfigLocation) throws IOException {
this.clientConfig = getClientConfig(clientConfigLocation);
}
/**
* Create a {@link HazelcastClientFactory} for the specified configuration.
* @param clientConfig the configuration
*/
public HazelcastClientFactory(ClientConfig clientConfig) {
Assert.notNull(clientConfig, "ClientConfig must not be null");
this.clientConfig = clientConfig;
}
private ClientConfig getClientConfig(Resource clientConfigLocation) throws IOException {
URL configUrl = clientConfigLocation.getURL();
String configFileName = configUrl.getPath();
if (configFileName.endsWith(".yaml")) {
return new YamlClientConfigBuilder(configUrl).build();
}
return new XmlClientConfigBuilder(configUrl).build();
}
/**
* Get the {@link HazelcastInstance}.
* @return the {@link HazelcastInstance}
*/
public HazelcastInstance getHazelcastInstance() {
if (StringUtils.hasText(this.clientConfig.getInstanceName())) {
return HazelcastClient.getOrCreateHazelcastClient(this.clientConfig);
}
return HazelcastClient.newHazelcastClient(this.clientConfig);
}
}

View File

@@ -1,96 +0,0 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.hazelcast;
import java.io.IOException;
import java.net.URL;
import com.hazelcast.config.Config;
import com.hazelcast.config.XmlConfigBuilder;
import com.hazelcast.config.YamlConfigBuilder;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
/**
* Factory that can be used to create a {@link HazelcastInstance}.
*
* @author Stephane Nicoll
* @author Phillip Webb
* @since 1.3.0
* @deprecated since 2.4.3 for removal in 2.6 in favor of using the Hazelcast API directly
*/
@Deprecated
public class HazelcastInstanceFactory {
private final Config config;
/**
* Create a {@link HazelcastInstanceFactory} for the specified configuration location.
* @param configLocation the location of the configuration file
* @throws IOException if the configuration location could not be read
*/
public HazelcastInstanceFactory(Resource configLocation) throws IOException {
Assert.notNull(configLocation, "ConfigLocation must not be null");
this.config = getConfig(configLocation);
}
/**
* Create a {@link HazelcastInstanceFactory} for the specified configuration.
* @param config the configuration
*/
public HazelcastInstanceFactory(Config config) {
Assert.notNull(config, "Config must not be null");
this.config = config;
}
private Config getConfig(Resource configLocation) throws IOException {
URL configUrl = configLocation.getURL();
Config config = createConfig(configUrl);
if (ResourceUtils.isFileURL(configUrl)) {
config.setConfigurationFile(configLocation.getFile());
}
else {
config.setConfigurationUrl(configUrl);
}
return config;
}
private static Config createConfig(URL configUrl) throws IOException {
String configFileName = configUrl.getPath();
if (configFileName.endsWith(".yaml")) {
return new YamlConfigBuilder(configUrl).build();
}
return new XmlConfigBuilder(configUrl).build();
}
/**
* Get the {@link HazelcastInstance}.
* @return the {@link HazelcastInstance}
*/
public HazelcastInstance getHazelcastInstance() {
if (StringUtils.hasText(this.config.getInstanceName())) {
return Hazelcast.getOrCreateHazelcastInstance(this.config);
}
return Hazelcast.newHazelcastInstance(this.config);
}
}

View File

@@ -20,7 +20,6 @@ import com.mongodb.ConnectionString;
import org.bson.UuidRepresentation;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
/**
* Configuration properties for Mongo.
@@ -195,23 +194,6 @@ public class MongoProperties {
return this.gridfs;
}
/**
* Return the GridFS database name.
* @return the GridFS database name
* @deprecated since 2.4.0 for removal in 2.6.0 in favor of
* {@link Gridfs#getDatabase()}
*/
@DeprecatedConfigurationProperty(replacement = "spring.data.mongodb.gridfs.database")
@Deprecated
public String getGridFsDatabase() {
return this.gridfs.getDatabase();
}
@Deprecated
public void setGridFsDatabase(String gridFsDatabase) {
this.gridfs.setDatabase(gridFsDatabase);
}
public String getMongoClientDatabase() {
if (this.database != null) {
return this.database;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -20,12 +20,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionMessage;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.autoconfigure.web.WebProperties.Resources.Chain;
import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.ClassUtils;
@@ -45,10 +42,9 @@ class OnEnabledResourceChainCondition extends SpringBootCondition {
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment();
String prefix = determineResourcePropertiesPrefix(environment);
boolean fixed = getEnabledProperty(environment, prefix, "strategy.fixed.", false);
boolean content = getEnabledProperty(environment, prefix, "strategy.content.", false);
Boolean chain = getEnabledProperty(environment, prefix, "", null);
boolean fixed = getEnabledProperty(environment, "strategy.fixed.", false);
boolean content = getEnabledProperty(environment, "strategy.content.", false);
Boolean chain = getEnabledProperty(environment, "", null);
Boolean match = Chain.getEnabled(fixed, content, chain);
ConditionMessage.Builder message = ConditionMessage.forCondition(ConditionalOnEnabledResourceChain.class);
if (match == null) {
@@ -63,19 +59,8 @@ class OnEnabledResourceChainCondition extends SpringBootCondition {
return ConditionOutcome.noMatch(message.because("disabled"));
}
@SuppressWarnings("deprecation")
private String determineResourcePropertiesPrefix(Environment environment) {
BindResult<org.springframework.boot.autoconfigure.web.ResourceProperties> result = Binder.get(environment)
.bind("spring.resources", org.springframework.boot.autoconfigure.web.ResourceProperties.class);
if (result.isBound() && result.get().hasBeenCustomized()) {
return "spring.resources.chain.";
}
return "spring.web.resources.chain.";
}
private Boolean getEnabledProperty(ConfigurableEnvironment environment, String prefix, String key,
Boolean defaultValue) {
String name = prefix + key + "enabled";
private Boolean getEnabledProperty(ConfigurableEnvironment environment, String key, Boolean defaultValue) {
String name = "spring.web.resources.chain." + key + "enabled";
return environment.getProperty(name, Boolean.class, defaultValue);
}

View File

@@ -1,282 +0,0 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.web;
import java.time.Duration;
import org.springframework.boot.autoconfigure.web.WebProperties.Resources;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
/**
* Properties used to configure resource handling.
*
* @author Phillip Webb
* @author Brian Clozel
* @author Dave Syer
* @author Venil Noronha
* @author Kristine Jetzke
* @since 1.1.0
* @deprecated since 2.4.0 for removal in 2.6.0 in favor of
* {@link WebProperties.Resources}
*/
@Deprecated
@ConfigurationProperties(prefix = "spring.resources", ignoreUnknownFields = false)
public class ResourceProperties extends Resources {
private final Chain chain = new Chain();
private final Cache cache = new Cache();
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.static-locations")
public String[] getStaticLocations() {
return super.getStaticLocations();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.add-mappings")
public boolean isAddMappings() {
return super.isAddMappings();
}
@Override
public Chain getChain() {
return this.chain;
}
@Override
public Cache getCache() {
return this.cache;
}
@Deprecated
public static class Chain extends Resources.Chain {
private final org.springframework.boot.autoconfigure.web.ResourceProperties.Strategy strategy = new org.springframework.boot.autoconfigure.web.ResourceProperties.Strategy();
/**
* Whether to enable HTML5 application cache manifest rewriting.
*/
private boolean htmlApplicationCache = false;
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.chain.enabled")
public Boolean getEnabled() {
return super.getEnabled();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.chain.cache")
public boolean isCache() {
return super.isCache();
}
@DeprecatedConfigurationProperty(reason = "The appcache manifest feature is being removed from browsers.")
public boolean isHtmlApplicationCache() {
return this.htmlApplicationCache;
}
public void setHtmlApplicationCache(boolean htmlApplicationCache) {
this.htmlApplicationCache = htmlApplicationCache;
this.customized = true;
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.chain.compressed")
public boolean isCompressed() {
return super.isCompressed();
}
@Override
public org.springframework.boot.autoconfigure.web.ResourceProperties.Strategy getStrategy() {
return this.strategy;
}
}
/**
* Strategies for extracting and embedding a resource version in its URL path.
*/
@Deprecated
public static class Strategy extends Resources.Chain.Strategy {
private final org.springframework.boot.autoconfigure.web.ResourceProperties.Fixed fixed = new org.springframework.boot.autoconfigure.web.ResourceProperties.Fixed();
private final org.springframework.boot.autoconfigure.web.ResourceProperties.Content content = new org.springframework.boot.autoconfigure.web.ResourceProperties.Content();
@Override
public org.springframework.boot.autoconfigure.web.ResourceProperties.Fixed getFixed() {
return this.fixed;
}
@Override
public org.springframework.boot.autoconfigure.web.ResourceProperties.Content getContent() {
return this.content;
}
}
/**
* Version Strategy based on content hashing.
*/
@Deprecated
public static class Content extends Resources.Chain.Strategy.Content {
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.chain.strategy.content.enabled")
public boolean isEnabled() {
return super.isEnabled();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.chain.strategy.content.paths")
public String[] getPaths() {
return super.getPaths();
}
}
/**
* Version Strategy based on a fixed version string.
*/
@Deprecated
public static class Fixed extends Resources.Chain.Strategy.Fixed {
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.chain.strategy.fixed.enabled")
public boolean isEnabled() {
return super.isEnabled();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.chain.strategy.fixed.paths")
public String[] getPaths() {
return super.getPaths();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.chain.strategy.fixed.version")
public String getVersion() {
return super.getVersion();
}
}
/**
* Cache configuration.
*/
@Deprecated
public static class Cache extends Resources.Cache {
private final Cachecontrol cachecontrol = new Cachecontrol();
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.period")
public Duration getPeriod() {
return super.getPeriod();
}
@Override
public Cachecontrol getCachecontrol() {
return this.cachecontrol;
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.use-last-modified")
public boolean isUseLastModified() {
return super.isUseLastModified();
}
/**
* Cache Control HTTP header configuration.
*/
@Deprecated
public static class Cachecontrol extends Resources.Cache.Cachecontrol {
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.cachecontrol.max-age")
public Duration getMaxAge() {
return super.getMaxAge();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.cachecontrol.no-cache")
public Boolean getNoCache() {
return super.getNoCache();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.cachecontrol.no-store")
public Boolean getNoStore() {
return super.getNoStore();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.cachecontrol.must-revalidate")
public Boolean getMustRevalidate() {
return super.getMustRevalidate();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.cachecontrol.no-transform")
public Boolean getNoTransform() {
return super.getNoTransform();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.cachecontrol.cache-public")
public Boolean getCachePublic() {
return super.getCachePublic();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.cachecontrol.cache-private")
public Boolean getCachePrivate() {
return super.getCachePrivate();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.cachecontrol.proxy-revalidate")
public Boolean getProxyRevalidate() {
return super.getProxyRevalidate();
}
@Override
@DeprecatedConfigurationProperty(
replacement = "spring.web.resources.cache.cachecontrol.stale-while-revalidate")
public Duration getStaleWhileRevalidate() {
return super.getStaleWhileRevalidate();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.cachecontrol.stale-if-error")
public Duration getStaleIfError() {
return super.getStaleIfError();
}
@Override
@DeprecatedConfigurationProperty(replacement = "spring.web.resources.cache.cachecontrol.s-max-age")
public Duration getSMaxAge() {
return super.getSMaxAge();
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -52,11 +52,6 @@ class ResourceChainResourceHandlerRegistrationCustomizer implements ResourceHand
if (strategy.getFixed().isEnabled() || strategy.getContent().isEnabled()) {
chain.addResolver(getVersionResourceResolver(strategy));
}
if ((properties instanceof org.springframework.boot.autoconfigure.web.ResourceProperties.Chain)
&& ((org.springframework.boot.autoconfigure.web.ResourceProperties.Chain) properties)
.isHtmlApplicationCache()) {
chain.addTransformer(new org.springframework.web.reactive.resource.AppCacheManifestTransformer());
}
}
private ResourceResolver getVersionResourceResolver(Resources.Chain.Strategy properties) {

View File

@@ -115,11 +115,8 @@ public class WebFluxAutoConfiguration {
@Bean
@SuppressWarnings("deprecation")
public RouterFunctionMapping welcomePageRouterFunctionMapping(ApplicationContext applicationContext,
WebFluxProperties webFluxProperties,
org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties,
WebProperties webProperties) {
String[] staticLocations = resourceProperties.hasBeenCustomized() ? resourceProperties.getStaticLocations()
: webProperties.getResources().getStaticLocations();
WebFluxProperties webFluxProperties, WebProperties webProperties) {
String[] staticLocations = webProperties.getResources().getStaticLocations();
WelcomePageRouterFunctionFactory factory = new WelcomePageRouterFunctionFactory(
new TemplateAvailabilityProviders(applicationContext), applicationContext, staticLocations,
webFluxProperties.getStaticPathPattern());
@@ -136,8 +133,7 @@ public class WebFluxAutoConfiguration {
@SuppressWarnings("deprecation")
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties({ org.springframework.boot.autoconfigure.web.ResourceProperties.class,
WebProperties.class, WebFluxProperties.class })
@EnableConfigurationProperties({ WebProperties.class, WebFluxProperties.class })
@Import({ EnableWebFluxConfiguration.class })
@Order(0)
public static class WebFluxConfig implements WebFluxConfigurer {
@@ -158,14 +154,12 @@ public class WebFluxAutoConfiguration {
private final ObjectProvider<ViewResolver> viewResolvers;
public WebFluxConfig(org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties,
WebProperties webProperties, WebFluxProperties webFluxProperties, ListableBeanFactory beanFactory,
ObjectProvider<HandlerMethodArgumentResolver> resolvers,
public WebFluxConfig(WebProperties webProperties, WebFluxProperties webFluxProperties,
ListableBeanFactory beanFactory, ObjectProvider<HandlerMethodArgumentResolver> resolvers,
ObjectProvider<CodecCustomizer> codecCustomizers,
ObjectProvider<ResourceHandlerRegistrationCustomizer> resourceHandlerRegistrationCustomizer,
ObjectProvider<ViewResolver> viewResolvers) {
this.resourceProperties = resourceProperties.hasBeenCustomized() ? resourceProperties
: webProperties.getResources();
this.resourceProperties = webProperties.getResources();
this.webFluxProperties = webFluxProperties;
this.beanFactory = beanFactory;
this.argumentResolvers = resolvers;
@@ -331,13 +325,9 @@ public class WebFluxAutoConfiguration {
static class ResourceChainCustomizerConfiguration {
@Bean
@SuppressWarnings("deprecation")
ResourceChainResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer(
org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties,
WebProperties webProperties) {
Resources resources = resourceProperties.hasBeenCustomized() ? resourceProperties
: webProperties.getResources();
return new ResourceChainResourceHandlerRegistrationCustomizer(resources);
return new ResourceChainResourceHandlerRegistrationCustomizer(webProperties.getResources());
}
}

View File

@@ -92,21 +92,6 @@ public abstract class AbstractErrorWebExceptionHandler implements ErrorWebExcept
private List<ViewResolver> viewResolvers = Collections.emptyList();
/**
* Create a new {@code AbstractErrorWebExceptionHandler}.
* @param errorAttributes the error attributes
* @param resourceProperties the resource properties
* @param applicationContext the application context
* @deprecated since 2.4.0 for removal in 2.6.0 in favor of
* {@link #AbstractErrorWebExceptionHandler(ErrorAttributes, Resources, ApplicationContext)}
*/
@Deprecated
public AbstractErrorWebExceptionHandler(ErrorAttributes errorAttributes,
org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties,
ApplicationContext applicationContext) {
this(errorAttributes, (Resources) resourceProperties, applicationContext);
}
/**
* Create a new {@code AbstractErrorWebExceptionHandler}.
* @param errorAttributes the error attributes

View File

@@ -91,22 +91,6 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
private final ErrorProperties errorProperties;
/**
* Create a new {@code DefaultErrorWebExceptionHandler} instance.
* @param errorAttributes the error attributes
* @param resourceProperties the resources configuration properties
* @param errorProperties the error configuration properties
* @param applicationContext the current application context
* @deprecated since 2.4.0 for removal in 2.6.0 in favor of
* {@link #DefaultErrorWebExceptionHandler(ErrorAttributes, Resources, ErrorProperties, ApplicationContext)}
*/
@Deprecated
public DefaultErrorWebExceptionHandler(ErrorAttributes errorAttributes,
org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties,
ErrorProperties errorProperties, ApplicationContext applicationContext) {
this(errorAttributes, (Resources) resourceProperties, errorProperties, applicationContext);
}
/**
* Create a new {@code DefaultErrorWebExceptionHandler} instance.
* @param errorAttributes the error attributes

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -53,8 +53,7 @@ import org.springframework.web.reactive.result.view.ViewResolver;
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
@ConditionalOnClass(WebFluxConfigurer.class)
@AutoConfigureBefore(WebFluxAutoConfiguration.class)
@EnableConfigurationProperties({ ServerProperties.class,
org.springframework.boot.autoconfigure.web.ResourceProperties.class, WebProperties.class })
@EnableConfigurationProperties({ ServerProperties.class, WebProperties.class })
public class ErrorWebFluxAutoConfiguration {
private final ServerProperties serverProperties;
@@ -67,12 +66,10 @@ public class ErrorWebFluxAutoConfiguration {
@ConditionalOnMissingBean(value = ErrorWebExceptionHandler.class, search = SearchStrategy.CURRENT)
@Order(-1)
public ErrorWebExceptionHandler errorWebExceptionHandler(ErrorAttributes errorAttributes,
org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties,
WebProperties webProperties, ObjectProvider<ViewResolver> viewResolvers,
ServerCodecConfigurer serverCodecConfigurer, ApplicationContext applicationContext) {
DefaultErrorWebExceptionHandler exceptionHandler = new DefaultErrorWebExceptionHandler(errorAttributes,
resourceProperties.hasBeenCustomized() ? resourceProperties : webProperties.getResources(),
this.serverProperties.getError(), applicationContext);
webProperties.getResources(), this.serverProperties.getError(), applicationContext);
exceptionHandler.setViewResolvers(viewResolvers.orderedStream().collect(Collectors.toList()));
exceptionHandler.setMessageWriters(serverCodecConfigurer.getWriters());
exceptionHandler.setMessageReaders(serverCodecConfigurer.getReaders());

View File

@@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.web.servlet;
import java.time.Duration;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.function.Consumer;
@@ -180,8 +179,7 @@ public class WebMvcAutoConfiguration {
@SuppressWarnings("deprecation")
@Configuration(proxyBeanMethods = false)
@Import(EnableWebMvcConfiguration.class)
@EnableConfigurationProperties({ WebMvcProperties.class,
org.springframework.boot.autoconfigure.web.ResourceProperties.class, WebProperties.class })
@EnableConfigurationProperties({ WebMvcProperties.class, WebProperties.class })
@Order(0)
public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer, ServletContextAware {
@@ -203,15 +201,12 @@ public class WebMvcAutoConfiguration {
private ServletContext servletContext;
public WebMvcAutoConfigurationAdapter(
org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties,
WebProperties webProperties, WebMvcProperties mvcProperties, ListableBeanFactory beanFactory,
ObjectProvider<HttpMessageConverters> messageConvertersProvider,
public WebMvcAutoConfigurationAdapter(WebProperties webProperties, WebMvcProperties mvcProperties,
ListableBeanFactory beanFactory, ObjectProvider<HttpMessageConverters> messageConvertersProvider,
ObjectProvider<ResourceHandlerRegistrationCustomizer> resourceHandlerRegistrationCustomizerProvider,
ObjectProvider<DispatcherServletPath> dispatcherServletPath,
ObjectProvider<ServletRegistrationBean<?>> servletRegistrations) {
this.resourceProperties = resourceProperties.hasBeenCustomized() ? resourceProperties
: webProperties.getResources();
this.resourceProperties = webProperties.getResources();
this.mvcProperties = mvcProperties;
this.beanFactory = beanFactory;
this.messageConvertersProvider = messageConvertersProvider;
@@ -399,15 +394,11 @@ public class WebMvcAutoConfiguration {
private ResourceLoader resourceLoader;
@SuppressWarnings("deprecation")
public EnableWebMvcConfiguration(
org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties,
WebMvcProperties mvcProperties, WebProperties webProperties,
public EnableWebMvcConfiguration(WebMvcProperties mvcProperties, WebProperties webProperties,
ObjectProvider<WebMvcRegistrations> mvcRegistrationsProvider,
ObjectProvider<ResourceHandlerRegistrationCustomizer> resourceHandlerRegistrationCustomizerProvider,
ListableBeanFactory beanFactory) {
this.resourceProperties = resourceProperties.hasBeenCustomized() ? resourceProperties
: webProperties.getResources();
this.resourceProperties = webProperties.getResources();
this.mvcProperties = mvcProperties;
this.webProperties = webProperties;
this.mvcRegistrations = mvcRegistrationsProvider.getIfUnique();
@@ -464,18 +455,12 @@ public class WebMvcAutoConfiguration {
@Override
@Bean
@ConditionalOnMissingBean(name = DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME)
@SuppressWarnings("deprecation")
public LocaleResolver localeResolver() {
if (this.webProperties.getLocaleResolver() == WebProperties.LocaleResolver.FIXED) {
return new FixedLocaleResolver(this.webProperties.getLocale());
}
if (this.mvcProperties.getLocaleResolver() == WebMvcProperties.LocaleResolver.FIXED) {
return new FixedLocaleResolver(this.mvcProperties.getLocale());
}
AcceptHeaderLocaleResolver localeResolver = new AcceptHeaderLocaleResolver();
Locale locale = (this.webProperties.getLocale() != null) ? this.webProperties.getLocale()
: this.mvcProperties.getLocale();
localeResolver.setDefaultLocale(locale);
localeResolver.setDefaultLocale(this.webProperties.getLocale());
return localeResolver;
}
@@ -616,12 +601,9 @@ public class WebMvcAutoConfiguration {
static class ResourceChainCustomizerConfiguration {
@Bean
@SuppressWarnings("deprecation")
ResourceChainResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer(
org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties,
WebProperties webProperties) {
return new ResourceChainResourceHandlerRegistrationCustomizer(
resourceProperties.hasBeenCustomized() ? resourceProperties : webProperties.getResources());
return new ResourceChainResourceHandlerRegistrationCustomizer(webProperties.getResources());
}
}
@@ -646,7 +628,6 @@ public class WebMvcAutoConfiguration {
configureResourceChain(properties, registration.resourceChain(properties.isCache()));
}
@SuppressWarnings("deprecation")
private void configureResourceChain(Resources.Chain properties, ResourceChainRegistration chain) {
Strategy strategy = properties.getStrategy();
if (properties.isCompressed()) {
@@ -655,11 +636,6 @@ public class WebMvcAutoConfiguration {
if (strategy.getFixed().isEnabled() || strategy.getContent().isEnabled()) {
chain.addResolver(getVersionResourceResolver(strategy));
}
if (properties instanceof org.springframework.boot.autoconfigure.web.ResourceProperties.Chain
&& ((org.springframework.boot.autoconfigure.web.ResourceProperties.Chain) properties)
.isHtmlApplicationCache()) {
chain.addTransformer(new org.springframework.web.servlet.resource.AppCacheManifestTransformer());
}
}
private ResourceResolver getVersionResourceResolver(Strategy properties) {

View File

@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.web.servlet;
import java.time.Duration;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -46,17 +45,6 @@ public class WebMvcProperties {
*/
private DefaultMessageCodesResolver.Format messageCodesResolverFormat;
/**
* Locale to use. By default, this locale is overridden by the "Accept-Language"
* header.
*/
private Locale locale;
/**
* Define how the locale should be resolved.
*/
private LocaleResolver localeResolver = LocaleResolver.ACCEPT_HEADER;
private final Format format = new Format();
/**
@@ -121,26 +109,6 @@ public class WebMvcProperties {
this.messageCodesResolverFormat = messageCodesResolverFormat;
}
@Deprecated
@DeprecatedConfigurationProperty(replacement = "spring.web.locale")
public Locale getLocale() {
return this.locale;
}
public void setLocale(Locale locale) {
this.locale = locale;
}
@Deprecated
@DeprecatedConfigurationProperty(replacement = "spring.web.locale-resolver")
public LocaleResolver getLocaleResolver() {
return this.localeResolver;
}
public void setLocaleResolver(LocaleResolver localeResolver) {
this.localeResolver = localeResolver;
}
@Deprecated
@DeprecatedConfigurationProperty(replacement = "spring.mvc.format.date")
public String getDateFormat() {
@@ -547,25 +515,4 @@ public class WebMvcProperties {
}
/**
* Locale resolution options.
* @deprecated since 2.4.0 for removal in 2.6.0 in favor of
* {@link org.springframework.boot.autoconfigure.web.WebProperties.LocaleResolver}
*/
@Deprecated
public enum LocaleResolver {
/**
* Always use the configured locale.
*/
FIXED,
/**
* Use the "Accept-Language" header or the configured locale if the header is not
* set.
*/
ACCEPT_HEADER
}
}

View File

@@ -74,19 +74,6 @@ public class DefaultErrorViewResolver implements ErrorViewResolver, Ordered {
private int order = Ordered.LOWEST_PRECEDENCE;
/**
* Create a new {@link DefaultErrorViewResolver} instance.
* @param applicationContext the source application context
* @param resourceProperties resource properties
* @deprecated since 2.4.0 for removal in 2.6.0 in favor of
* {@link #DefaultErrorViewResolver(ApplicationContext, Resources)}
*/
@Deprecated
public DefaultErrorViewResolver(ApplicationContext applicationContext,
org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties) {
this(applicationContext, (Resources) resourceProperties);
}
/**
* Create a new {@link DefaultErrorViewResolver} instance.
* @param applicationContext the source application context

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -124,20 +124,16 @@ public class ErrorMvcAutoConfiguration {
@SuppressWarnings("deprecation")
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties({ org.springframework.boot.autoconfigure.web.ResourceProperties.class,
WebProperties.class, WebMvcProperties.class })
@EnableConfigurationProperties({ WebProperties.class, WebMvcProperties.class })
static class DefaultErrorViewResolverConfiguration {
private final ApplicationContext applicationContext;
private final Resources resources;
DefaultErrorViewResolverConfiguration(ApplicationContext applicationContext,
org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties,
WebProperties webProperties) {
DefaultErrorViewResolverConfiguration(ApplicationContext applicationContext, WebProperties webProperties) {
this.applicationContext = applicationContext;
this.resources = webProperties.getResources().hasBeenCustomized() ? webProperties.getResources()
: resourceProperties;
this.resources = webProperties.getResources();
}
@Bean

View File

@@ -1585,10 +1585,6 @@
"description": "Whether to enable Spring's HiddenHttpMethodFilter.",
"defaultValue": false
},
{
"name": "spring.mvc.locale-resolver",
"defaultValue": "accept-header"
},
{
"name": "spring.mvc.pathmatch.matching-strategy",
"defaultValue": "ant-path-matcher"
@@ -1682,7 +1678,7 @@
"type": "java.lang.Boolean",
"description": "Whether to enable resolution of already gzipped resources. Checks for a resource name variant with the \"*.gz\" extension.",
"deprecation": {
"replacement": "spring.resources.chain.compressed",
"replacement": "spring.web.resources.chain.compressed",
"level": "error"
}
},

View File

@@ -79,17 +79,6 @@ class MongoDataAutoConfigurationTests {
});
}
@Test
@Deprecated
void whenGridFsDatabaseIsConfiguredWithDeprecatedPropertyThenGridFsTemplateIsAutoConfiguredAndUsesIt() {
this.contextRunner.withPropertyValues("spring.data.mongodb.gridFsDatabase:grid").run((context) -> {
assertThat(context).hasSingleBean(GridFsTemplate.class);
GridFsTemplate template = context.getBean(GridFsTemplate.class);
MongoDatabaseFactory factory = (MongoDatabaseFactory) ReflectionTestUtils.getField(template, "dbFactory");
assertThat(factory.getMongoDatabase().getName()).isEqualTo("grid");
});
}
@Test
void whenGridFsBucketIsConfiguredThenGridFsTemplateIsAutoConfiguredAndUsesIt() {
this.contextRunner.withPropertyValues("spring.data.mongodb.gridfs.bucket:test-bucket").run((context) -> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -58,13 +58,6 @@ class MongoReactiveDataAutoConfigurationTests {
.run((context) -> assertThat(grisFsTemplateDatabaseName(context)).isEqualTo("grid"));
}
@Test
@Deprecated
void whenGridFsDatabaseIsConfiguredWithDeprecatedPropertyThenGridFsTemplateUsesIt() {
this.contextRunner.withPropertyValues("spring.data.mongodb.gridFsDatabase:grid")
.run((context) -> assertThat(grisFsTemplateDatabaseName(context)).isEqualTo("grid"));
}
@Test
void whenGridFsBucketIsConfiguredThenGridFsTemplateUsesIt() {
this.contextRunner.withPropertyValues("spring.data.mongodb.gridfs.bucket:test-bucket").run((context) -> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -155,7 +155,7 @@ class FreeMarkerAutoConfigurationServletIntegrationTests {
@Test
void registerResourceHandlingFilterOnlyIfResourceChainIsEnabled() {
load("spring.resources.chain.enabled:true");
load("spring.web.resources.chain.enabled:true");
FilterRegistrationBean<?> registration = this.context.getBean(FilterRegistrationBean.class);
assertThat(registration.getFilter()).isInstanceOf(ResourceUrlEncodingFilter.class);
assertThat(registration).hasFieldOrPropertyWithValue("dispatcherTypes",
@@ -166,7 +166,7 @@ class FreeMarkerAutoConfigurationServletIntegrationTests {
@SuppressWarnings("rawtypes")
void registerResourceHandlingFilterWithOtherRegistrationBean() {
// gh-14897
load(FilterRegistrationOtherConfiguration.class, "spring.resources.chain.enabled:true");
load(FilterRegistrationOtherConfiguration.class, "spring.web.resources.chain.enabled:true");
Map<String, FilterRegistrationBean> beans = this.context.getBeansOfType(FilterRegistrationBean.class);
assertThat(beans).hasSize(2);
FilterRegistrationBean registration = beans.values().stream()
@@ -179,7 +179,7 @@ class FreeMarkerAutoConfigurationServletIntegrationTests {
@SuppressWarnings("rawtypes")
void registerResourceHandlingFilterWithResourceRegistrationBean() {
// gh-14926
load(FilterRegistrationResourceConfiguration.class, "spring.resources.chain.enabled:true");
load(FilterRegistrationResourceConfiguration.class, "spring.web.resources.chain.enabled:true");
Map<String, FilterRegistrationBean> beans = this.context.getBeansOfType(FilterRegistrationBean.class);
assertThat(beans).hasSize(1);
FilterRegistrationBean registration = beans.values().stream()

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -260,7 +260,7 @@ class ThymeleafServletAutoConfigurationTests {
@Test
void registerResourceHandlingFilterOnlyIfResourceChainIsEnabled() {
this.contextRunner.withPropertyValues("spring.resources.chain.enabled:true").run((context) -> {
this.contextRunner.withPropertyValues("spring.web.resources.chain.enabled:true").run((context) -> {
FilterRegistrationBean<?> registration = context.getBean(FilterRegistrationBean.class);
assertThat(registration.getFilter()).isInstanceOf(ResourceUrlEncodingFilter.class);
assertThat(registration).hasFieldOrPropertyWithValue("dispatcherTypes",
@@ -273,7 +273,7 @@ class ThymeleafServletAutoConfigurationTests {
void registerResourceHandlingFilterWithOtherRegistrationBean() {
// gh-14897
this.contextRunner.withUserConfiguration(FilterRegistrationOtherConfiguration.class)
.withPropertyValues("spring.resources.chain.enabled:true").run((context) -> {
.withPropertyValues("spring.web.resources.chain.enabled:true").run((context) -> {
Map<String, FilterRegistrationBean> beans = context.getBeansOfType(FilterRegistrationBean.class);
assertThat(beans).hasSize(2);
FilterRegistrationBean registration = beans.values().stream()
@@ -288,7 +288,7 @@ class ThymeleafServletAutoConfigurationTests {
void registerResourceHandlingFilterWithResourceRegistrationBean() {
// gh-14926
this.contextRunner.withUserConfiguration(FilterRegistrationResourceConfiguration.class)
.withPropertyValues("spring.resources.chain.enabled:true").run((context) -> {
.withPropertyValues("spring.web.resources.chain.enabled:true").run((context) -> {
Map<String, FilterRegistrationBean> beans = context.getBeansOfType(FilterRegistrationBean.class);
assertThat(beans).hasSize(1);
FilterRegistrationBean registration = beans.values().stream()

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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,6 @@ package org.springframework.boot.autoconfigure.web;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -48,31 +46,27 @@ class ConditionalOnEnabledResourceChainTests {
assertThat(this.context.containsBean("foo")).isFalse();
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void disabledExplicitly(String prefix) {
load(prefix + "chain.enabled:false");
@Test
void disabledExplicitly() {
load("spring.web.resources.chain.enabled:false");
assertThat(this.context.containsBean("foo")).isFalse();
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void enabledViaMainEnabledFlag(String prefix) {
load(prefix + "chain.enabled:true");
@Test
void enabledViaMainEnabledFlag() {
load("spring.web.resources.chain.enabled:true");
assertThat(this.context.containsBean("foo")).isTrue();
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void enabledViaFixedStrategyFlag(String prefix) {
load(prefix + "chain.strategy.fixed.enabled:true");
@Test
void enabledViaFixedStrategyFlag() {
load("spring.web.resources.chain.strategy.fixed.enabled:true");
assertThat(this.context.containsBean("foo")).isTrue();
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void enabledViaContentStrategyFlag(String prefix) {
load(prefix + "chain.strategy.content.enabled:true");
@Test
void enabledViaContentStrategyFlag() {
load("spring.web.resources.chain.strategy.content.enabled:true");
assertThat(this.context.containsBean("foo")).isTrue();
}

View File

@@ -1,70 +0,0 @@
/*
* Copyright 2012-2021 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.web;
import java.util.function.Consumer;
import org.junit.jupiter.api.Test;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Binding tests for {@link ResourceProperties}.
*
* @author Stephane Nicoll
*/
@Deprecated
class ResourcePropertiesBindingTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withUserConfiguration(TestConfiguration.class);
@Test
void staticLocationsExpandArray() {
this.contextRunner
.withPropertyValues("spring.resources.static-locations[0]=classpath:/one/",
"spring.resources.static-locations[1]=classpath:/two",
"spring.resources.static-locations[2]=classpath:/three/",
"spring.resources.static-locations[3]=classpath:/four",
"spring.resources.static-locations[4]=classpath:/five/",
"spring.resources.static-locations[5]=classpath:/six")
.run(assertResourceProperties((properties) -> assertThat(properties.getStaticLocations()).contains(
"classpath:/one/", "classpath:/two/", "classpath:/three/", "classpath:/four/",
"classpath:/five/", "classpath:/six/")));
}
private ContextConsumer<AssertableApplicationContext> assertResourceProperties(
Consumer<ResourceProperties> consumer) {
return (context) -> {
assertThat(context).hasSingleBean(ResourceProperties.class);
consumer.accept(context.getBean(ResourceProperties.class));
};
}
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(ResourceProperties.class)
static class TestConfiguration {
}
}

View File

@@ -1,106 +0,0 @@
/*
* Copyright 2012-2020 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.web;
import java.time.Duration;
import org.junit.jupiter.api.Test;
import org.springframework.http.CacheControl;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ResourceProperties}.
*
* @author Stephane Nicoll
* @author Kristine Jetzke
*/
@Deprecated
class ResourcePropertiesTests {
private final ResourceProperties properties = new ResourceProperties();
@Test
void resourceChainNoCustomization() {
assertThat(this.properties.getChain().getEnabled()).isNull();
}
@Test
void resourceChainStrategyEnabled() {
this.properties.getChain().getStrategy().getFixed().setEnabled(true);
assertThat(this.properties.getChain().getEnabled()).isTrue();
}
@Test
void resourceChainEnabled() {
this.properties.getChain().setEnabled(true);
assertThat(this.properties.getChain().getEnabled()).isTrue();
}
@Test
void resourceChainDisabled() {
this.properties.getChain().setEnabled(false);
assertThat(this.properties.getChain().getEnabled()).isFalse();
}
@Test
void defaultStaticLocationsAllEndWithTrailingSlash() {
assertThat(this.properties.getStaticLocations()).allMatch((location) -> location.endsWith("/"));
}
@Test
void customStaticLocationsAreNormalizedToEndWithTrailingSlash() {
this.properties.setStaticLocations(new String[] { "/foo", "/bar", "/baz/" });
String[] actual = this.properties.getStaticLocations();
assertThat(actual).containsExactly("/foo/", "/bar/", "/baz/");
}
@Test
void emptyCacheControl() {
CacheControl cacheControl = this.properties.getCache().getCachecontrol().toHttpCacheControl();
assertThat(cacheControl).isNull();
}
@Test
void cacheControlAllPropertiesSet() {
ResourceProperties.Cache.Cachecontrol properties = this.properties.getCache().getCachecontrol();
properties.setMaxAge(Duration.ofSeconds(4));
properties.setCachePrivate(true);
properties.setCachePublic(true);
properties.setMustRevalidate(true);
properties.setNoTransform(true);
properties.setProxyRevalidate(true);
properties.setSMaxAge(Duration.ofSeconds(5));
properties.setStaleIfError(Duration.ofSeconds(6));
properties.setStaleWhileRevalidate(Duration.ofSeconds(7));
CacheControl cacheControl = properties.toHttpCacheControl();
assertThat(cacheControl.getHeaderValue())
.isEqualTo("max-age=4, must-revalidate, no-transform, public, private, proxy-revalidate,"
+ " s-maxage=5, stale-if-error=6, stale-while-revalidate=7");
}
@Test
void invalidCacheControlCombination() {
ResourceProperties.Cache.Cachecontrol properties = this.properties.getCache().getCachecontrol();
properties.setMaxAge(Duration.ofSeconds(4));
properties.setNoStore(true);
CacheControl cacheControl = properties.toHttpCacheControl();
assertThat(cacheControl.getHeaderValue()).isEqualTo("no-store");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 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.
@@ -32,7 +32,6 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll
* @author Kristine Jetzke
*/
@Deprecated
class WebPropertiesResourcesTests {
private final Resources properties = new WebProperties().getResources();

View File

@@ -34,8 +34,6 @@ import javax.validation.ValidatorFactory;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
@@ -182,18 +180,16 @@ class WebFluxAutoConfigurationTests {
});
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void shouldNotMapResourcesWhenDisabled(String prefix) {
this.contextRunner.withPropertyValues(prefix + ".add-mappings:false")
@Test
void shouldNotMapResourcesWhenDisabled() {
this.contextRunner.withPropertyValues("spring.web.resources.add-mappings:false")
.run((context) -> assertThat(context.getBean("resourceHandlerMapping"))
.isNotInstanceOf(SimpleUrlHandlerMapping.class));
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void resourceHandlerChainEnabled(String prefix) {
this.contextRunner.withPropertyValues(prefix + "chain.enabled:true").run((context) -> {
@Test
void resourceHandlerChainEnabled() {
this.contextRunner.withPropertyValues("spring.web.resources.chain.enabled:true").run((context) -> {
SimpleUrlHandlerMapping hm = context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class);
assertThat(hm.getUrlMap().get("/**")).isInstanceOf(ResourceWebHandler.class);
ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/**");
@@ -418,11 +414,10 @@ class WebFluxAutoConfigurationTests {
});
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void cachePeriod(String prefix) {
@Test
void cachePeriod() {
Assertions.setExtractBareNamePropertyMethods(false);
this.contextRunner.withPropertyValues(prefix + "cache.period:5").run((context) -> {
this.contextRunner.withPropertyValues("spring.web.resources.cache.period:5").run((context) -> {
Map<PathPattern, Object> handlerMap = getHandlerMap(context);
assertThat(handlerMap).hasSize(2);
for (Object handler : handlerMap.values()) {
@@ -435,12 +430,11 @@ class WebFluxAutoConfigurationTests {
Assertions.setExtractBareNamePropertyMethods(true);
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void cacheControl(String prefix) {
@Test
void cacheControl() {
Assertions.setExtractBareNamePropertyMethods(false);
this.contextRunner.withPropertyValues(prefix + "cache.cachecontrol.max-age:5",
prefix + "cache.cachecontrol.proxy-revalidate:true").run((context) -> {
this.contextRunner.withPropertyValues("spring.web.resources.cache.cachecontrol.max-age:5",
"spring.web.resources.cache.cachecontrol.proxy-revalidate:true").run((context) -> {
Map<PathPattern, Object> handlerMap = getHandlerMap(context);
assertThat(handlerMap).hasSize(2);
for (Object handler : handlerMap.values()) {
@@ -476,14 +470,14 @@ class WebFluxAutoConfigurationTests {
});
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void welcomePageHandlerMapping(String prefix) {
this.contextRunner.withPropertyValues(prefix + "static-locations=classpath:/welcome-page/").run((context) -> {
assertThat(context).getBeans(RouterFunctionMapping.class).hasSize(2);
assertThat(context.getBean("welcomePageRouterFunctionMapping", HandlerMapping.class)).isNotNull()
.extracting("order").isEqualTo(1);
});
@Test
void welcomePageHandlerMapping() {
this.contextRunner.withPropertyValues("spring.web.resources.static-locations=classpath:/welcome-page/")
.run((context) -> {
assertThat(context).getBeans(RouterFunctionMapping.class).hasSize(2);
assertThat(context.getBean("welcomePageRouterFunctionMapping", HandlerMapping.class)).isNotNull()
.extracting("order").isEqualTo(1);
});
}
@Test

View File

@@ -38,8 +38,6 @@ import javax.servlet.http.HttpServletResponse;
import javax.validation.ValidatorFactory;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
@@ -216,17 +214,15 @@ class WebMvcAutoConfigurationTests {
});
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void resourceHandlerMappingDisabled(String prefix) {
this.contextRunner.withPropertyValues(prefix + "add-mappings:false")
@Test
void resourceHandlerMappingDisabled() {
this.contextRunner.withPropertyValues("spring.web.resources.add-mappings:false")
.run((context) -> assertThat(getResourceMappingLocations(context)).hasSize(0));
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void resourceHandlerChainEnabled(String prefix) {
this.contextRunner.withPropertyValues(prefix + "chain.enabled:true").run((context) -> {
@Test
void resourceHandlerChainEnabled() {
this.contextRunner.withPropertyValues("spring.web.resources.chain.enabled:true").run((context) -> {
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(2);
assertThat(getResourceTransformers(context, "/webjars/**")).hasSize(1);
assertThat(getResourceResolvers(context, "/**")).extractingResultOf("getClass")
@@ -236,13 +232,11 @@ class WebMvcAutoConfigurationTests {
});
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void resourceHandlerFixedStrategyEnabled(String prefix) {
this.contextRunner
.withPropertyValues(prefix + "chain.strategy.fixed.enabled:true",
prefix + "chain.strategy.fixed.version:test", prefix + "chain.strategy.fixed.paths:/**/*.js")
.run((context) -> {
@Test
void resourceHandlerFixedStrategyEnabled() {
this.contextRunner.withPropertyValues("spring.web.resources.chain.strategy.fixed.enabled:true",
"spring.web.resources.chain.strategy.fixed.version:test",
"spring.web.resources.chain.strategy.fixed.paths:/**/*.js").run((context) -> {
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(3);
assertThat(getResourceTransformers(context, "/webjars/**")).hasSize(2);
assertThat(getResourceResolvers(context, "/**")).extractingResultOf("getClass").containsOnly(
@@ -255,11 +249,10 @@ class WebMvcAutoConfigurationTests {
});
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void resourceHandlerContentStrategyEnabled(String prefix) {
this.contextRunner.withPropertyValues(prefix + "chain.strategy.content.enabled:true",
prefix + "chain.strategy.content.paths:/**,/*.png").run((context) -> {
@Test
void resourceHandlerContentStrategyEnabled() {
this.contextRunner.withPropertyValues("spring.web.resources.chain.strategy.content.enabled:true",
"spring.web.resources.chain.strategy.content.paths:/**,/*.png").run((context) -> {
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(3);
assertThat(getResourceTransformers(context, "/webjars/**")).hasSize(2);
assertThat(getResourceResolvers(context, "/**")).extractingResultOf("getClass").containsOnly(
@@ -272,25 +265,22 @@ class WebMvcAutoConfigurationTests {
});
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
@SuppressWarnings("deprecation")
void resourceHandlerChainCustomized(String prefix) {
this.contextRunner.withPropertyValues(prefix + "chain.enabled:true", prefix + "chain.cache:false",
prefix + "chain.strategy.content.enabled:true", prefix + "chain.strategy.content.paths:/**,/*.png",
prefix + "chain.strategy.fixed.enabled:true", prefix + "chain.strategy.fixed.version:test",
prefix + "chain.strategy.fixed.paths:/**/*.js", prefix + "chain.html-application-cache:true",
prefix + "chain.compressed:true").run((context) -> {
@Test
void resourceHandlerChainCustomized() {
this.contextRunner.withPropertyValues("spring.web.resources.chain.enabled:true",
"spring.web.resources.chain.cache:false", "spring.web.resources.chain.strategy.content.enabled:true",
"spring.web.resources.chain.strategy.content.paths:/**,/*.png",
"spring.web.resources.chain.strategy.fixed.enabled:true",
"spring.web.resources.chain.strategy.fixed.version:test",
"spring.web.resources.chain.strategy.fixed.paths:/**/*.js",
"spring.web.resources.chain.html-application-cache:true", "spring.web.resources.chain.compressed:true")
.run((context) -> {
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(3);
assertThat(getResourceTransformers(context, "/webjars/**"))
.hasSize(prefix.equals("spring.resources.") ? 2 : 1);
assertThat(getResourceTransformers(context, "/webjars/**")).hasSize(1);
assertThat(getResourceResolvers(context, "/**")).extractingResultOf("getClass").containsOnly(
EncodedResourceResolver.class, VersionResourceResolver.class, PathResourceResolver.class);
assertThat(getResourceTransformers(context, "/**")).extractingResultOf("getClass")
.containsOnly(prefix.equals("spring.resources.")
? new Class<?>[] { CssLinkResourceTransformer.class,
org.springframework.web.servlet.resource.AppCacheManifestTransformer.class }
: new Class<?>[] { CssLinkResourceTransformer.class });
.containsOnly(CssLinkResourceTransformer.class);
VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(context, "/**")
.get(1);
Map<String, VersionStrategy> strategyMap = resolver.getStrategyMap();
@@ -308,11 +298,10 @@ class WebMvcAutoConfigurationTests {
});
}
@ParameterizedTest
@ValueSource(strings = { "mvc", "web" })
void overrideLocale(String mvcOrWeb) {
this.contextRunner.withPropertyValues("spring." + mvcOrWeb + ".locale:en_UK",
"spring." + mvcOrWeb + ".locale-resolver=fixed").run((loader) -> {
@Test
void overrideLocale() {
this.contextRunner.withPropertyValues("spring.web.locale:en_UK", "spring.web.locale-resolver=fixed")
.run((loader) -> {
// mock request and set user preferred locale
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(StringUtils.parseLocaleString("nl_NL"));
@@ -326,10 +315,9 @@ class WebMvcAutoConfigurationTests {
});
}
@ParameterizedTest
@ValueSource(strings = { "mvc", "web" })
void useAcceptHeaderLocale(String mvcOrWeb) {
this.contextRunner.withPropertyValues("spring." + mvcOrWeb + ".locale:en_UK").run((loader) -> {
@Test
void useAcceptHeaderLocale() {
this.contextRunner.withPropertyValues("spring.web.locale:en_UK").run((loader) -> {
// mock request and set user preferred locale
MockHttpServletRequest request = new MockHttpServletRequest();
request.addPreferredLocale(StringUtils.parseLocaleString("nl_NL"));
@@ -342,10 +330,9 @@ class WebMvcAutoConfigurationTests {
});
}
@ParameterizedTest
@ValueSource(strings = { "mvc", "web" })
void useDefaultLocaleIfAcceptHeaderNoSet(String mvcOrWeb) {
this.contextRunner.withPropertyValues("spring." + mvcOrWeb + ".locale:en_UK").run((context) -> {
@Test
void useDefaultLocaleIfAcceptHeaderNoSet() {
this.contextRunner.withPropertyValues("spring.web.locale:en_UK").run((context) -> {
// mock request and set user preferred locale
MockHttpServletRequest request = new MockHttpServletRequest();
LocaleResolver localeResolver = context.getBean(LocaleResolver.class);
@@ -680,20 +667,19 @@ class WebMvcAutoConfigurationTests {
};
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void welcomePageHandlerMappingIsAutoConfigured(String prefix) {
this.contextRunner.withPropertyValues(prefix + "static-locations:classpath:/welcome-page/").run((context) -> {
assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class);
assertThat(bean.getRootHandler()).isNotNull();
});
@Test
void welcomePageHandlerMappingIsAutoConfigured() {
this.contextRunner.withPropertyValues("spring.web.resources.static-locations:classpath:/welcome-page/")
.run((context) -> {
assertThat(context).hasSingleBean(WelcomePageHandlerMapping.class);
WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class);
assertThat(bean.getRootHandler()).isNotNull();
});
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void welcomePageHandlerIncludesCorsConfiguration(String prefix) {
this.contextRunner.withPropertyValues(prefix + "static-locations:classpath:/welcome-page/")
@Test
void welcomePageHandlerIncludesCorsConfiguration() {
this.contextRunner.withPropertyValues("spring.web.resources.static-locations:classpath:/welcome-page/")
.withUserConfiguration(CorsConfigurer.class).run((context) -> {
WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class);
UrlBasedCorsConfigurationSource source = (UrlBasedCorsConfigurationSource) bean
@@ -816,10 +802,9 @@ class WebMvcAutoConfigurationTests {
.run((context) -> assertThat(context).hasNotFailed());
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void cachePeriod(String prefix) {
this.contextRunner.withPropertyValues(prefix + "cache.period:5").run((context) -> {
@Test
void cachePeriod() {
this.contextRunner.withPropertyValues("spring.web.resources.cache.period:5").run((context) -> {
assertResourceHttpRequestHandler((context), (handler) -> {
assertThat(handler.getCacheSeconds()).isEqualTo(5);
assertThat(handler.getCacheControl()).isNull();
@@ -827,12 +812,11 @@ class WebMvcAutoConfigurationTests {
});
}
@ParameterizedTest
@ValueSource(strings = { "spring.resources.", "spring.web.resources." })
void cacheControl(String prefix) {
@Test
void cacheControl() {
this.contextRunner
.withPropertyValues(prefix + "cache.cachecontrol.max-age:5",
prefix + "cache.cachecontrol.proxy-revalidate:true")
.withPropertyValues("spring.web.resources.cache.cachecontrol.max-age:5",
"spring.web.resources.cache.cachecontrol.proxy-revalidate:true")
.run((context) -> assertResourceHttpRequestHandler(context, (handler) -> {
assertThat(handler.getCacheSeconds()).isEqualTo(-1);
assertThat(handler.getCacheControl()).usingRecursiveComparison()

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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.
@@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Madhura Bhave
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = { "spring.resources.chain.strategy.content.enabled=true",
properties = { "spring.web.resources.chain.strategy.content.enabled=true",
"spring.thymeleaf.prefix=classpath:/templates/thymeleaf/" })
class WelcomePageIntegrationTests {