19
19
import org .springframework .boot .autoconfigure .condition .ConditionMessage ;
20
20
import org .springframework .boot .autoconfigure .condition .ConditionOutcome ;
21
21
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 ;
22
25
import org .springframework .context .annotation .Condition ;
23
26
import org .springframework .context .annotation .ConditionContext ;
24
27
import org .springframework .core .env .ConfigurableEnvironment ;
28
+ import org .springframework .core .env .Environment ;
25
29
import org .springframework .core .type .AnnotatedTypeMetadata ;
26
30
import org .springframework .util .ClassUtils ;
27
31
@@ -41,10 +45,11 @@ class OnEnabledResourceChainCondition extends SpringBootCondition {
41
45
@ Override
42
46
public ConditionOutcome getMatchOutcome (ConditionContext context , AnnotatedTypeMetadata metadata ) {
43
47
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 );
48
53
ConditionMessage .Builder message = ConditionMessage .forCondition (ConditionalOnEnabledResourceChain .class );
49
54
if (match == null ) {
50
55
if (ClassUtils .isPresent (WEBJAR_ASSET_LOCATOR , getClass ().getClassLoader ())) {
@@ -58,8 +63,19 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
58
63
return ConditionOutcome .noMatch (message .because ("disabled" ));
59
64
}
60
65
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" ;
63
79
return environment .getProperty (name , Boolean .class , defaultValue );
64
80
}
65
81
0 commit comments