Skip to content

Commit c22e655

Browse files
committed
Move spring.resources.* properties to spring.web.resources.*
Closes gh-23917
1 parent 929d8fc commit c22e655

23 files changed

+1168
-519
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
2020
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
2121
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
22+
import org.springframework.boot.autoconfigure.web.WebProperties.Resources.Chain;
23+
import org.springframework.boot.context.properties.bind.BindResult;
24+
import org.springframework.boot.context.properties.bind.Binder;
2225
import org.springframework.context.annotation.Condition;
2326
import org.springframework.context.annotation.ConditionContext;
2427
import org.springframework.core.env.ConfigurableEnvironment;
28+
import org.springframework.core.env.Environment;
2529
import org.springframework.core.type.AnnotatedTypeMetadata;
2630
import org.springframework.util.ClassUtils;
2731

@@ -41,10 +45,11 @@ class OnEnabledResourceChainCondition extends SpringBootCondition {
4145
@Override
4246
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
4347
ConfigurableEnvironment environment = (ConfigurableEnvironment) context.getEnvironment();
44-
boolean fixed = getEnabledProperty(environment, "strategy.fixed.", false);
45-
boolean content = getEnabledProperty(environment, "strategy.content.", false);
46-
Boolean chain = getEnabledProperty(environment, "", null);
47-
Boolean match = ResourceProperties.Chain.getEnabled(fixed, content, chain);
48+
String prefix = determineResourcePropertiesPrefix(environment);
49+
boolean fixed = getEnabledProperty(environment, prefix, "strategy.fixed.", false);
50+
boolean content = getEnabledProperty(environment, prefix, "strategy.content.", false);
51+
Boolean chain = getEnabledProperty(environment, prefix, "", null);
52+
Boolean match = Chain.getEnabled(fixed, content, chain);
4853
ConditionMessage.Builder message = ConditionMessage.forCondition(ConditionalOnEnabledResourceChain.class);
4954
if (match == null) {
5055
if (ClassUtils.isPresent(WEBJAR_ASSET_LOCATOR, getClass().getClassLoader())) {
@@ -58,8 +63,19 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
5863
return ConditionOutcome.noMatch(message.because("disabled"));
5964
}
6065

61-
private Boolean getEnabledProperty(ConfigurableEnvironment environment, String key, Boolean defaultValue) {
62-
String name = "spring.resources.chain." + key + "enabled";
66+
@SuppressWarnings("deprecation")
67+
private String determineResourcePropertiesPrefix(Environment environment) {
68+
BindResult<org.springframework.boot.autoconfigure.web.ResourceProperties> result = Binder.get(environment)
69+
.bind("spring.resources", org.springframework.boot.autoconfigure.web.ResourceProperties.class);
70+
if (result.isBound() && result.get().hasBeenCustomized()) {
71+
return "spring.resources.chain.";
72+
}
73+
return "spring.web.resources.chain.";
74+
}
75+
76+
private Boolean getEnabledProperty(ConfigurableEnvironment environment, String prefix, String key,
77+
Boolean defaultValue) {
78+
String name = prefix + key + "enabled";
6379
return environment.getProperty(name, Boolean.class, defaultValue);
6480
}
6581

0 commit comments

Comments
 (0)