From 9e0fd01aae585fd44cf7120c2a7ac5c1767014b9 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 8 Sep 2020 16:34:25 +0200 Subject: [PATCH] Deprecate resource "app-cache" configuration support This commit deprecates the `"spring.resources.chain.html-application-cache"` configuration property and its support, since the feature has been deprecated in Spring Framework. The app-cache manifest feature is being removed from browsers in favor of web workers. Closes gh-23228 --- .../boot/autoconfigure/web/ResourceProperties.java | 5 ++++- ...ResourceChainResourceHandlerRegistrationCustomizer.java | 6 +++--- .../autoconfigure/web/servlet/WebMvcAutoConfiguration.java | 4 ++-- .../web/servlet/WebMvcAutoConfigurationTests.java | 7 ++++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java index 9b8ba0362b..6f4fb0992d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. @@ -21,6 +21,7 @@ import java.time.temporal.ChronoUnit; import java.util.concurrent.TimeUnit; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.convert.DurationUnit; import org.springframework.http.CacheControl; @@ -145,6 +146,8 @@ public class ResourceProperties { return this.strategy; } + @DeprecatedConfigurationProperty(reason = "The appcache manifest feature is being removed from browsers.") + @Deprecated public boolean isHtmlApplicationCache() { return this.htmlApplicationCache; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ResourceChainResourceHandlerRegistrationCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ResourceChainResourceHandlerRegistrationCustomizer.java index 35cb76c957..549c50f837 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ResourceChainResourceHandlerRegistrationCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/ResourceChainResourceHandlerRegistrationCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * 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. @@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.web.ResourceProperties; import org.springframework.web.reactive.config.ResourceChainRegistration; import org.springframework.web.reactive.config.ResourceHandlerRegistration; -import org.springframework.web.reactive.resource.AppCacheManifestTransformer; import org.springframework.web.reactive.resource.EncodedResourceResolver; import org.springframework.web.reactive.resource.ResourceResolver; import org.springframework.web.reactive.resource.VersionResourceResolver; @@ -42,6 +41,7 @@ class ResourceChainResourceHandlerRegistrationCustomizer implements ResourceHand configureResourceChain(properties, registration.resourceChain(properties.isCache())); } + @SuppressWarnings("deprecation") private void configureResourceChain(ResourceProperties.Chain properties, ResourceChainRegistration chain) { ResourceProperties.Strategy strategy = properties.getStrategy(); if (properties.isCompressed()) { @@ -51,7 +51,7 @@ class ResourceChainResourceHandlerRegistrationCustomizer implements ResourceHand chain.addResolver(getVersionResourceResolver(strategy)); } if (properties.isHtmlApplicationCache()) { - chain.addTransformer(new AppCacheManifestTransformer()); + chain.addTransformer(new org.springframework.web.reactive.resource.AppCacheManifestTransformer()); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java index 7953a7e238..134413dc5f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java @@ -111,7 +111,6 @@ import org.springframework.web.servlet.i18n.FixedLocaleResolver; import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; -import org.springframework.web.servlet.resource.AppCacheManifestTransformer; import org.springframework.web.servlet.resource.EncodedResourceResolver; import org.springframework.web.servlet.resource.ResourceResolver; import org.springframework.web.servlet.resource.ResourceUrlProvider; @@ -564,6 +563,7 @@ public class WebMvcAutoConfiguration { configureResourceChain(properties, registration.resourceChain(properties.isCache())); } + @SuppressWarnings("deprecation") private void configureResourceChain(ResourceProperties.Chain properties, ResourceChainRegistration chain) { Strategy strategy = properties.getStrategy(); if (properties.isCompressed()) { @@ -573,7 +573,7 @@ public class WebMvcAutoConfiguration { chain.addResolver(getVersionResourceResolver(strategy)); } if (properties.isHtmlApplicationCache()) { - chain.addTransformer(new AppCacheManifestTransformer()); + chain.addTransformer(new org.springframework.web.servlet.resource.AppCacheManifestTransformer()); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java index 87ed0718f1..53ec1b6153 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java @@ -105,7 +105,6 @@ import org.springframework.web.servlet.i18n.FixedLocaleResolver; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver; -import org.springframework.web.servlet.resource.AppCacheManifestTransformer; import org.springframework.web.servlet.resource.CachingResourceResolver; import org.springframework.web.servlet.resource.CachingResourceTransformer; import org.springframework.web.servlet.resource.ContentVersionStrategy; @@ -255,6 +254,7 @@ class WebMvcAutoConfigurationTests { } @Test + @SuppressWarnings("deprecation") void resourceHandlerChainCustomized() { this.contextRunner .withPropertyValues("spring.resources.chain.enabled:true", "spring.resources.chain.cache:false", @@ -269,8 +269,9 @@ class WebMvcAutoConfigurationTests { assertThat(getResourceTransformers(context, "/webjars/**")).hasSize(2); assertThat(getResourceResolvers(context, "/**")).extractingResultOf("getClass").containsOnly( EncodedResourceResolver.class, VersionResourceResolver.class, PathResourceResolver.class); - assertThat(getResourceTransformers(context, "/**")).extractingResultOf("getClass") - .containsOnly(CssLinkResourceTransformer.class, AppCacheManifestTransformer.class); + assertThat(getResourceTransformers(context, "/**")).extractingResultOf("getClass").containsOnly( + CssLinkResourceTransformer.class, + org.springframework.web.servlet.resource.AppCacheManifestTransformer.class); VersionResourceResolver resolver = (VersionResourceResolver) getResourceResolvers(context, "/**") .get(1); Map strategyMap = resolver.getStrategyMap();