Skip to content

Commit a04e913

Browse files
committed
Make ResourceHandlerRegistrationCustomizer public
Make `ResourceHandlerRegistrationCustomizer` a public top level class. Closes gh-14587
1 parent 4d705df commit a04e913

File tree

3 files changed

+112
-56
lines changed

3 files changed

+112
-56
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.web.reactive;
18+
19+
import org.springframework.beans.factory.annotation.Autowired;
20+
import org.springframework.boot.autoconfigure.web.ResourceProperties;
21+
import org.springframework.web.reactive.config.ResourceChainRegistration;
22+
import org.springframework.web.reactive.config.ResourceHandlerRegistration;
23+
import org.springframework.web.reactive.resource.AppCacheManifestTransformer;
24+
import org.springframework.web.reactive.resource.EncodedResourceResolver;
25+
import org.springframework.web.reactive.resource.ResourceResolver;
26+
import org.springframework.web.reactive.resource.VersionResourceResolver;
27+
28+
/**
29+
* {@link ResourceHandlerRegistrationCustomizer} used by auto-configuration to customize
30+
* the resource chain.
31+
*
32+
* @author Brian Clozel
33+
*/
34+
class ResourceChainResourceHandlerRegistrationCustomizer
35+
implements ResourceHandlerRegistrationCustomizer {
36+
37+
@Autowired
38+
private ResourceProperties resourceProperties = new ResourceProperties();
39+
40+
@Override
41+
public void customize(ResourceHandlerRegistration registration) {
42+
ResourceProperties.Chain properties = this.resourceProperties.getChain();
43+
configureResourceChain(properties,
44+
registration.resourceChain(properties.isCache()));
45+
}
46+
47+
private void configureResourceChain(ResourceProperties.Chain properties,
48+
ResourceChainRegistration chain) {
49+
ResourceProperties.Strategy strategy = properties.getStrategy();
50+
if (properties.isCompressed()) {
51+
chain.addResolver(new EncodedResourceResolver());
52+
}
53+
if (strategy.getFixed().isEnabled() || strategy.getContent().isEnabled()) {
54+
chain.addResolver(getVersionResourceResolver(strategy));
55+
}
56+
if (properties.isHtmlApplicationCache()) {
57+
chain.addTransformer(new AppCacheManifestTransformer());
58+
}
59+
}
60+
61+
private ResourceResolver getVersionResourceResolver(
62+
ResourceProperties.Strategy properties) {
63+
VersionResourceResolver resolver = new VersionResourceResolver();
64+
if (properties.getFixed().isEnabled()) {
65+
String version = properties.getFixed().getVersion();
66+
String[] paths = properties.getFixed().getPaths();
67+
resolver.addFixedVersionStrategy(version, paths);
68+
}
69+
if (properties.getContent().isEnabled()) {
70+
String[] paths = properties.getContent().getPaths();
71+
resolver.addContentVersionStrategy(paths);
72+
}
73+
return resolver;
74+
}
75+
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.web.reactive;
18+
19+
import org.springframework.web.reactive.config.ResourceHandlerRegistration;
20+
21+
/**
22+
* Callback interface that can be used to customize {@link ResourceHandlerRegistration}.
23+
*
24+
* @author Brian Clozel
25+
* @since 2.1.0
26+
*/
27+
@FunctionalInterface
28+
public interface ResourceHandlerRegistrationCustomizer {
29+
30+
/**
31+
* Customize the given {@link ResourceHandlerRegistration}.
32+
* @param registration the registration to customize
33+
*/
34+
void customize(ResourceHandlerRegistration registration);
35+
36+
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import org.springframework.beans.factory.ListableBeanFactory;
2727
import org.springframework.beans.factory.ObjectProvider;
28-
import org.springframework.beans.factory.annotation.Autowired;
2928
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
3029
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
3130
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -57,16 +56,11 @@
5756
import org.springframework.web.filter.reactive.HiddenHttpMethodFilter;
5857
import org.springframework.web.reactive.config.DelegatingWebFluxConfiguration;
5958
import org.springframework.web.reactive.config.EnableWebFlux;
60-
import org.springframework.web.reactive.config.ResourceChainRegistration;
6159
import org.springframework.web.reactive.config.ResourceHandlerRegistration;
6260
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
6361
import org.springframework.web.reactive.config.ViewResolverRegistry;
6462
import org.springframework.web.reactive.config.WebFluxConfigurationSupport;
6563
import org.springframework.web.reactive.config.WebFluxConfigurer;
66-
import org.springframework.web.reactive.resource.AppCacheManifestTransformer;
67-
import org.springframework.web.reactive.resource.EncodedResourceResolver;
68-
import org.springframework.web.reactive.resource.ResourceResolver;
69-
import org.springframework.web.reactive.resource.VersionResourceResolver;
7064
import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver;
7165
import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
7266
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerAdapter;
@@ -277,54 +271,4 @@ public ResourceChainResourceHandlerRegistrationCustomizer resourceHandlerRegistr
277271

278272
}
279273

280-
interface ResourceHandlerRegistrationCustomizer {
281-
282-
void customize(ResourceHandlerRegistration registration);
283-
284-
}
285-
286-
static class ResourceChainResourceHandlerRegistrationCustomizer
287-
implements ResourceHandlerRegistrationCustomizer {
288-
289-
@Autowired
290-
private ResourceProperties resourceProperties = new ResourceProperties();
291-
292-
@Override
293-
public void customize(ResourceHandlerRegistration registration) {
294-
ResourceProperties.Chain properties = this.resourceProperties.getChain();
295-
configureResourceChain(properties,
296-
registration.resourceChain(properties.isCache()));
297-
}
298-
299-
private void configureResourceChain(ResourceProperties.Chain properties,
300-
ResourceChainRegistration chain) {
301-
ResourceProperties.Strategy strategy = properties.getStrategy();
302-
if (properties.isCompressed()) {
303-
chain.addResolver(new EncodedResourceResolver());
304-
}
305-
if (strategy.getFixed().isEnabled() || strategy.getContent().isEnabled()) {
306-
chain.addResolver(getVersionResourceResolver(strategy));
307-
}
308-
if (properties.isHtmlApplicationCache()) {
309-
chain.addTransformer(new AppCacheManifestTransformer());
310-
}
311-
}
312-
313-
private ResourceResolver getVersionResourceResolver(
314-
ResourceProperties.Strategy properties) {
315-
VersionResourceResolver resolver = new VersionResourceResolver();
316-
if (properties.getFixed().isEnabled()) {
317-
String version = properties.getFixed().getVersion();
318-
String[] paths = properties.getFixed().getPaths();
319-
resolver.addFixedVersionStrategy(version, paths);
320-
}
321-
if (properties.getContent().isEnabled()) {
322-
String[] paths = properties.getContent().getPaths();
323-
resolver.addContentVersionStrategy(paths);
324-
}
325-
return resolver;
326-
}
327-
328-
}
329-
330274
}

0 commit comments

Comments
 (0)