|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2016 the original author or authors.
|
|
|
|
* Copyright 2012-2017 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -19,11 +19,11 @@ package org.springframework.boot.autoconfigure.web;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
|
|
|
import org.springframework.boot.bind.PropertySourcesPropertyValues;
|
|
|
|
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
|
|
|
import org.springframework.boot.bind.RelaxedDataBinder;
|
|
|
|
|
|
|
|
import org.springframework.context.annotation.Condition;
|
|
|
|
import org.springframework.context.annotation.Condition;
|
|
|
|
import org.springframework.context.annotation.ConditionContext;
|
|
|
|
import org.springframework.context.annotation.ConditionContext;
|
|
|
|
import org.springframework.core.env.ConfigurableEnvironment;
|
|
|
|
import org.springframework.core.env.ConfigurableEnvironment;
|
|
|
|
|
|
|
|
import org.springframework.core.env.PropertyResolver;
|
|
|
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
|
|
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
|
|
|
|
|
|
|
@ -32,6 +32,7 @@ import org.springframework.util.ClassUtils;
|
|
|
|
* enabled.
|
|
|
|
* enabled.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @see ConditionalOnEnabledResourceChain
|
|
|
|
* @see ConditionalOnEnabledResourceChain
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class OnEnabledResourceChainCondition extends SpringBootCondition {
|
|
|
|
class OnEnabledResourceChainCondition extends SpringBootCondition {
|
|
|
@ -43,10 +44,10 @@ class OnEnabledResourceChainCondition extends SpringBootCondition {
|
|
|
|
AnnotatedTypeMetadata metadata) {
|
|
|
|
AnnotatedTypeMetadata metadata) {
|
|
|
|
ConfigurableEnvironment environment = (ConfigurableEnvironment) context
|
|
|
|
ConfigurableEnvironment environment = (ConfigurableEnvironment) context
|
|
|
|
.getEnvironment();
|
|
|
|
.getEnvironment();
|
|
|
|
ResourceProperties properties = new ResourceProperties();
|
|
|
|
boolean fixed = getEnabledProperty(environment, "strategy.fixed.", false);
|
|
|
|
RelaxedDataBinder binder = new RelaxedDataBinder(properties, "spring.resources");
|
|
|
|
boolean content = getEnabledProperty(environment, "strategy.content.", false);
|
|
|
|
binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources()));
|
|
|
|
Boolean chain = getEnabledProperty(environment, "", null);
|
|
|
|
Boolean match = properties.getChain().getEnabled();
|
|
|
|
Boolean match = ResourceProperties.Chain.getEnabled(fixed, content, chain);
|
|
|
|
ConditionMessage.Builder message = ConditionMessage
|
|
|
|
ConditionMessage.Builder message = ConditionMessage
|
|
|
|
.forCondition(ConditionalOnEnabledResourceChain.class);
|
|
|
|
.forCondition(ConditionalOnEnabledResourceChain.class);
|
|
|
|
if (match == null) {
|
|
|
|
if (match == null) {
|
|
|
@ -63,4 +64,11 @@ class OnEnabledResourceChainCondition extends SpringBootCondition {
|
|
|
|
return ConditionOutcome.noMatch(message.because("disabled"));
|
|
|
|
return ConditionOutcome.noMatch(message.because("disabled"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Boolean getEnabledProperty(ConfigurableEnvironment environment, String key,
|
|
|
|
|
|
|
|
Boolean defaultValue) {
|
|
|
|
|
|
|
|
PropertyResolver resolver = new RelaxedPropertyResolver(environment,
|
|
|
|
|
|
|
|
"spring.resources.chain." + key);
|
|
|
|
|
|
|
|
return resolver.getProperty("enabled", Boolean.class, defaultValue);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|