Rename some ConditionalOnProperty attributes
Rename the newly introduced @ConditionalOnProperty `match` and `defaultMatch` attributes to `havingValue` and `matchIfMissing`. Also added a new `name` attribute as an alternative to `value` to aid readability. Closes gh-1000
This commit is contained in:
parent
6825a7b42e
commit
8e0b3dd00a
|
|
@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.aop;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.reflect.Advice;
|
import org.aspectj.lang.reflect.Advice;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
|
|
@ -40,19 +39,18 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ EnableAspectJAutoProxy.class, Aspect.class, Advice.class })
|
@ConditionalOnClass({ EnableAspectJAutoProxy.class, Aspect.class, Advice.class })
|
||||||
@ConditionalOnProperty(value = "spring.aop.auto", match = "true", defaultMatch = true)
|
@ConditionalOnProperty(prefix = "spring.aop", name = "auto", havingValue = "true", matchIfMissing = true)
|
||||||
public class AopAutoConfiguration {
|
public class AopAutoConfiguration {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableAspectJAutoProxy(proxyTargetClass = false)
|
@EnableAspectJAutoProxy(proxyTargetClass = false)
|
||||||
@ConditionalOnProperty(value = "spring.aop.proxyTargetClass", match = "false", defaultMatch = true)
|
@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "false", matchIfMissing = true)
|
||||||
public static class JdkDynamicAutoProxyConfiguration {
|
public static class JdkDynamicAutoProxyConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
@EnableAspectJAutoProxy(proxyTargetClass = true)
|
||||||
@ConditionalOnExpression("${spring.aop.proxyTargetClass:false}")
|
@ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true", matchIfMissing = false)
|
||||||
@ConditionalOnProperty(value = "spring.aop.proxyTargetClass", match = "true", defaultMatch = false)
|
|
||||||
public static class CglibAutoProxyConfiguration {
|
public static class CglibAutoProxyConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ public class BatchAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
@ConditionalOnProperty(value = "spring.batch.job.enabled", match = "true", defaultMatch = true)
|
@ConditionalOnProperty(prefix = "spring.batch.job", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||||
public JobLauncherCommandLineRunner jobLauncherCommandLineRunner(
|
public JobLauncherCommandLineRunner jobLauncherCommandLineRunner(
|
||||||
JobLauncher jobLauncher, JobExplorer jobExplorer) {
|
JobLauncher jobLauncher, JobExplorer jobExplorer) {
|
||||||
JobLauncherCommandLineRunner runner = new JobLauncherCommandLineRunner(
|
JobLauncherCommandLineRunner runner = new JobLauncherCommandLineRunner(
|
||||||
|
|
|
||||||
|
|
@ -25,66 +25,56 @@ import org.springframework.context.annotation.Conditional;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Conditional} that checks if the specified properties
|
* {@link Conditional} that checks if the specified properties have a specific value. By
|
||||||
* have the requested matching value. By default the properties
|
* default the properties must be present in the {@link Environment} and
|
||||||
* must be present in the {@link Environment} ant <strong>not</strong>
|
* <strong>not</strong> equal to {@code false}. The {@link #havingValue()} and
|
||||||
* equal to {@code false}. The {@link #match()} and {@link #defaultMatch()}
|
* {@link #matchIfMissing()} attributes allow further customizations.
|
||||||
* attributes allow to further customize the condition.
|
|
||||||
*
|
*
|
||||||
* <p>The {@link #match} attribute provides the value that the property
|
* <p>
|
||||||
* should have. The {@link #defaultMatch()} flag specifies if the
|
* The {@link #havingValue} attribute can be used to specify the value that the property
|
||||||
* condition <strong>also</strong> matches if the property is not present
|
* should have. The table below shows when a condition matches according to the property
|
||||||
* at all.
|
* value and the {@link #havingValue()} attribute:
|
||||||
*
|
|
||||||
* <p>The table below defines when a condition match according to the
|
|
||||||
* property value and the {@link #match()} value
|
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
* <table border="1">
|
* <table border="1">
|
||||||
* <th>
|
|
||||||
* <td>no {@code match} value</td>
|
|
||||||
* <td>{@code true}</td>
|
|
||||||
* <td>{@code false}</td>
|
|
||||||
* <td>{@code foo}</td>
|
|
||||||
* </th>
|
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>not set ({@code defaultMatch = false})</td>
|
* <th>Property Value</th>
|
||||||
* <td>no</td>
|
* <th>{@code havingValue=""}</th>
|
||||||
* <td>no</td>
|
* <th>{@code havingValue="true"}</th>
|
||||||
* <td>no</td>
|
* <th>{@code havingValue="false"}</th>
|
||||||
* <td>no</td>
|
* <th>{@code havingValue="foo"}</th>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>not set ({@code defaultMatch = true})</td>
|
* <td>{@code "true"}</td>
|
||||||
* <td>yes</td>
|
* <td>yes</td>
|
||||||
* <td>yes</td>
|
* <td>yes</td>
|
||||||
* <td>yes</td>
|
* <td>no</td>
|
||||||
* <td>yes</td>
|
* <td>no</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>{@code true}</td>
|
* <td>{@code "false"}</td>
|
||||||
* <td>yes</td>
|
* <td>no</td>
|
||||||
* <td>yes</td>
|
* <td>no</td>
|
||||||
* <td>no</td>
|
* <td>yes</td>
|
||||||
* <td>no</td>
|
* <td>no</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>{@code false}</td>
|
* <td>{@code "foo"}</td>
|
||||||
* <td>no</td>
|
* <td>yes</td>
|
||||||
* <td>no</td>
|
* <td>no</td>
|
||||||
* <td>yes</td>
|
* <td>no</td>
|
||||||
* <td>no</td>
|
* <td>yes</td>
|
||||||
* </tr>
|
|
||||||
* <tr>
|
|
||||||
* <td>{@code foo}</td>
|
|
||||||
* <td>yes</td>
|
|
||||||
* <td>no</td>
|
|
||||||
* <td>no</td>
|
|
||||||
* <td>yes</td>
|
|
||||||
* </tr>
|
* </tr>
|
||||||
* </table>
|
* </table>
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* If the property is not contained in the {@link Environment} at all, the
|
||||||
|
* {@link #matchIfMissing()} attribute is consulted. By default missing attributes do not
|
||||||
|
* match.
|
||||||
|
*
|
||||||
* @author Maciej Walkowiak
|
* @author Maciej Walkowiak
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Phillip Webb
|
||||||
* @since 1.1.0
|
* @since 1.1.0
|
||||||
*/
|
*/
|
||||||
@Conditional(OnPropertyCondition.class)
|
@Conditional(OnPropertyCondition.class)
|
||||||
|
|
@ -93,38 +83,38 @@ import org.springframework.core.env.Environment;
|
||||||
public @interface ConditionalOnProperty {
|
public @interface ConditionalOnProperty {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A prefix that should be applied to each property.
|
* Alias for {@link #name()}.
|
||||||
* <p>Defaults to no prefix. The prefix automatically
|
*/
|
||||||
* ends with a dot if not specified.
|
String[] value() default {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A prefix that should be applied to each property. The prefix automatically ends
|
||||||
|
* with a dot if not specified.
|
||||||
*/
|
*/
|
||||||
String prefix() default "";
|
String prefix() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One or more properties to validate against the
|
* The name of the properties to test.If a prefix has been defined, it is applied to
|
||||||
* {@link #match} value. If a prefix has been defined, it
|
* compute the full key of each property. For instance if the prefix is
|
||||||
* is applied to compute the full key of each property. For
|
* {@code app.config} and one value is {@code my-value}, the fully key would be
|
||||||
* instance if the prefix is {@code app.config} and one
|
|
||||||
* value is {@code my-value}, the fully key would be
|
|
||||||
* {@code app.config.my-value}
|
* {@code app.config.my-value}
|
||||||
* <p>Use the dashed notation to specify each property, that
|
* <p>
|
||||||
* is all lower case with a "-" to separate words (e.g.
|
* Use the dashed notation to specify each property, that is all lower case with a "-"
|
||||||
* {@code my-long-property}).
|
* to separate words (e.g. {@code my-long-property}).
|
||||||
* @return the property names
|
|
||||||
*/
|
*/
|
||||||
String[] value();
|
String[] name() default {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The string representation of the expected value for the
|
* The string representation of the expected value for the properties. If not
|
||||||
* properties. If not specified, the property must
|
* specified, the property must <strong>not</strong> be equals to {@code false}
|
||||||
* <strong>not</strong> be equals to {@code false}
|
|
||||||
*/
|
*/
|
||||||
String match() default "";
|
String havingValue() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify if the condition should match if the property is not set.
|
* Specify if the condition should match if the property is not set. Defaults to
|
||||||
* Defaults to {@code false}
|
* {@code false}
|
||||||
*/
|
*/
|
||||||
boolean defaultMatch() default false;
|
boolean matchIfMissing() default false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If relaxed names should be checked. Defaults to {@code true}.
|
* If relaxed names should be checked. Defaults to {@code true}.
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,10 @@ import java.util.Map;
|
||||||
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
import org.springframework.boot.bind.RelaxedPropertyResolver;
|
||||||
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.annotation.AnnotationAttributes;
|
||||||
import org.springframework.core.env.PropertyResolver;
|
import org.springframework.core.env.PropertyResolver;
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -42,41 +44,35 @@ class OnPropertyCondition extends SpringBootCondition {
|
||||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||||
AnnotatedTypeMetadata metadata) {
|
AnnotatedTypeMetadata metadata) {
|
||||||
|
|
||||||
Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(
|
AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(metadata
|
||||||
ConditionalOnProperty.class.getName());
|
.getAnnotationAttributes(ConditionalOnProperty.class.getName()));
|
||||||
|
|
||||||
String prefix = getPrefix(annotationAttributes);
|
String prefix = annotationAttributes.getString("prefix").trim();
|
||||||
String expectedValue = getExpectedValue(annotationAttributes);
|
if (StringUtils.hasText(prefix) && !prefix.endsWith(".")) {
|
||||||
String[] names = (String[]) annotationAttributes.get("value");
|
prefix = prefix + ".";
|
||||||
boolean relaxedNames = (Boolean) annotationAttributes.get("relaxedNames");
|
}
|
||||||
boolean matchDefault = (Boolean) annotationAttributes.get("defaultMatch");
|
String havingValue = annotationAttributes.getString("havingValue");
|
||||||
|
String[] names = getNames(annotationAttributes);
|
||||||
List<String> missingProperties = new ArrayList<String>();
|
boolean relaxedNames = annotationAttributes.getBoolean("relaxedNames");
|
||||||
List<String> nonMatchingProperties = new ArrayList<String>();
|
boolean matchIfMissing = annotationAttributes.getBoolean("matchIfMissing");
|
||||||
|
|
||||||
PropertyResolver resolver = context.getEnvironment();
|
PropertyResolver resolver = context.getEnvironment();
|
||||||
if (relaxedNames) {
|
if (relaxedNames) {
|
||||||
resolver = new RelaxedPropertyResolver(resolver, prefix);
|
resolver = new RelaxedPropertyResolver(resolver, prefix);
|
||||||
prefix = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> missingProperties = new ArrayList<String>();
|
||||||
|
List<String> nonMatchingProperties = new ArrayList<String>();
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
name = prefix + name;
|
String key = (relaxedNames ? name : prefix + name);
|
||||||
boolean hasProperty = resolver.containsProperty(name);
|
if (resolver.containsProperty(key)) {
|
||||||
if (!hasProperty) { // property not set
|
if (!isMatch(resolver.getProperty(key), havingValue)) {
|
||||||
if (!matchDefault) { // property is mandatory
|
nonMatchingProperties.add(name);
|
||||||
missingProperties.add(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String actualValue = resolver.getProperty(name);
|
if (!matchIfMissing) {
|
||||||
if (expectedValue == null) {
|
missingProperties.add(name);
|
||||||
if ("false".equalsIgnoreCase(actualValue)) {
|
|
||||||
nonMatchingProperties.add(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!expectedValue.equalsIgnoreCase(actualValue)) {
|
|
||||||
nonMatchingProperties.add(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -85,42 +81,45 @@ class OnPropertyCondition extends SpringBootCondition {
|
||||||
return ConditionOutcome.match();
|
return ConditionOutcome.match();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder("@ConditionalOnProperty ");
|
StringBuilder message = new StringBuilder("@ConditionalOnProperty ");
|
||||||
if (!matchDefault && !missingProperties.isEmpty()) {
|
if (!missingProperties.isEmpty()) {
|
||||||
sb.append("missing required properties ")
|
message.append("missing required properties "
|
||||||
.append(StringUtils.arrayToCommaDelimitedString(missingProperties.toArray()))
|
+ expandNames(prefix, missingProperties) + " ");
|
||||||
.append(" ");
|
|
||||||
}
|
}
|
||||||
if (!nonMatchingProperties.isEmpty()) {
|
if (!nonMatchingProperties.isEmpty()) {
|
||||||
String expected = expectedValue == null ? "!false" : expectedValue;
|
String expected = havingValue == null ? "!false" : havingValue;
|
||||||
sb.append("expected '").append(expected).append("' for properties: ")
|
message.append("expected '").append(expected).append("' for properties ")
|
||||||
.append(StringUtils.arrayToCommaDelimitedString(nonMatchingProperties.toArray()));
|
.append(expandNames(prefix, nonMatchingProperties));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConditionOutcome.noMatch(sb.toString());
|
return ConditionOutcome.noMatch(message.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private String[] getNames(Map<String, Object> annotationAttributes) {
|
||||||
* Return the prefix to use or an empty String if it's not set.
|
String[] value = (String[]) annotationAttributes.get("value");
|
||||||
* <p>Add a dot at the end if it is not present already.
|
String[] name = (String[]) annotationAttributes.get("name");
|
||||||
*/
|
Assert.state(value.length > 0 || name.length > 0,
|
||||||
private static String getPrefix(Map<String, Object> annotationAttributes) {
|
"The name or value attribute of @ConditionalOnProperty must be specified");
|
||||||
String prefix = ((String) annotationAttributes.get("prefix")).trim();
|
Assert.state(value.length == 0 || name.length == 0,
|
||||||
if (StringUtils.hasText(prefix) && !prefix.endsWith(".")) {
|
"The name and value attributes of @ConditionalOnProperty are exclusive");
|
||||||
prefix = prefix + ".";
|
return (value.length > 0 ? value : name);
|
||||||
}
|
|
||||||
return prefix;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private boolean isMatch(String value, String requiredValue) {
|
||||||
* Return the expected value to match against or {@code null} if no
|
if (StringUtils.hasLength(requiredValue)) {
|
||||||
* match value is set.
|
return requiredValue.equalsIgnoreCase(value);
|
||||||
*/
|
|
||||||
private static String getExpectedValue(Map<String, Object> annotationAttributes) {
|
|
||||||
String match = (String) annotationAttributes.get("match");
|
|
||||||
if (StringUtils.hasText(match)) {
|
|
||||||
return match;
|
|
||||||
}
|
}
|
||||||
return null;
|
return !"false".equalsIgnoreCase(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String expandNames(String prefix, List<String> names) {
|
||||||
|
StringBuffer expanded = new StringBuffer();
|
||||||
|
for (String name : names) {
|
||||||
|
expanded.append(expanded.length() == 0 ? "" : ", ");
|
||||||
|
expanded.append(prefix);
|
||||||
|
expanded.append(name);
|
||||||
|
}
|
||||||
|
return expanded.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,7 @@ import org.springframework.data.repository.core.support.RepositoryFactoryBeanSup
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ Client.class, ElasticsearchRepository.class })
|
@ConditionalOnClass({ Client.class, ElasticsearchRepository.class })
|
||||||
@ConditionalOnProperty(value = "spring.data.elasticsearch.repositories.enabled",
|
@ConditionalOnProperty(prefix = "spring.data.elasticsearch.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||||
match = "true", defaultMatch = true)
|
|
||||||
@ConditionalOnMissingBean(RepositoryFactoryBeanSupport.class)
|
@ConditionalOnMissingBean(RepositoryFactoryBeanSupport.class)
|
||||||
@Import(ElasticsearchRepositoriesAutoConfigureRegistrar.class)
|
@Import(ElasticsearchRepositoriesAutoConfigureRegistrar.class)
|
||||||
public class ElasticsearchRepositoriesAutoConfiguration {
|
public class ElasticsearchRepositoriesAutoConfiguration {
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ import org.springframework.data.web.config.EnableSpringDataWebSupport;
|
||||||
@ConditionalOnClass(JpaRepository.class)
|
@ConditionalOnClass(JpaRepository.class)
|
||||||
@ConditionalOnMissingBean({ RepositoryFactoryBeanSupport.class,
|
@ConditionalOnMissingBean({ RepositoryFactoryBeanSupport.class,
|
||||||
JpaRepositoryConfigExtension.class })
|
JpaRepositoryConfigExtension.class })
|
||||||
@ConditionalOnProperty(value = "spring.data.jpa.repositories.enabled", match = "true", defaultMatch = true)
|
@ConditionalOnProperty(prefix = "spring.data.jpa.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||||
@Import(JpaRepositoriesAutoConfigureRegistrar.class)
|
@Import(JpaRepositoriesAutoConfigureRegistrar.class)
|
||||||
@AutoConfigureAfter(HibernateJpaAutoConfiguration.class)
|
@AutoConfigureAfter(HibernateJpaAutoConfiguration.class)
|
||||||
public class JpaRepositoriesAutoConfiguration {
|
public class JpaRepositoriesAutoConfiguration {
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ import com.mongodb.Mongo;
|
||||||
@ConditionalOnClass({ Mongo.class, MongoRepository.class })
|
@ConditionalOnClass({ Mongo.class, MongoRepository.class })
|
||||||
@ConditionalOnMissingBean({ RepositoryFactoryBeanSupport.class,
|
@ConditionalOnMissingBean({ RepositoryFactoryBeanSupport.class,
|
||||||
MongoRepositoryConfigurationExtension.class })
|
MongoRepositoryConfigurationExtension.class })
|
||||||
@ConditionalOnProperty(value = "spring.data.mongo.repositories.enabled", match = "true", defaultMatch = true)
|
@ConditionalOnProperty(prefix = "spring.data.mongo.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||||
@Import(MongoRepositoriesAutoConfigureRegistrar.class)
|
@Import(MongoRepositoriesAutoConfigureRegistrar.class)
|
||||||
@AutoConfigureAfter(MongoAutoConfiguration.class)
|
@AutoConfigureAfter(MongoAutoConfiguration.class)
|
||||||
public class MongoRepositoriesAutoConfiguration {
|
public class MongoRepositoriesAutoConfiguration {
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ import org.springframework.data.solr.repository.config.SolrRepositoryConfigExten
|
||||||
@ConditionalOnClass({ SolrServer.class, SolrRepository.class })
|
@ConditionalOnClass({ SolrServer.class, SolrRepository.class })
|
||||||
@ConditionalOnMissingBean({ RepositoryFactoryBeanSupport.class,
|
@ConditionalOnMissingBean({ RepositoryFactoryBeanSupport.class,
|
||||||
SolrRepositoryConfigExtension.class })
|
SolrRepositoryConfigExtension.class })
|
||||||
@ConditionalOnProperty(value = "spring.data.solr.repositories.enabled", match = "true", defaultMatch = true)
|
@ConditionalOnProperty(prefix = "spring.data.solr.repositories", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||||
@Import(SolrRepositoriesAutoConfigureRegistrar.class)
|
@Import(SolrRepositoriesAutoConfigureRegistrar.class)
|
||||||
public class SolrRepositoriesAutoConfiguration {
|
public class SolrRepositoriesAutoConfiguration {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ public class IntegrationAutoConfiguration {
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass(EnableIntegrationMBeanExport.class)
|
@ConditionalOnClass(EnableIntegrationMBeanExport.class)
|
||||||
@ConditionalOnMissingBean(value = IntegrationMBeanExporter.class, search = SearchStrategy.CURRENT)
|
@ConditionalOnMissingBean(value = IntegrationMBeanExporter.class, search = SearchStrategy.CURRENT)
|
||||||
@ConditionalOnProperty(value = "spring.jmx.enabled", match = "true", defaultMatch = true)
|
@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||||
@EnableIntegrationMBeanExport(defaultDomain = "${spring.jmx.default_domain:}", server = "${spring.jmx.server:mbeanServer}")
|
@EnableIntegrationMBeanExport(defaultDomain = "${spring.jmx.default_domain:}", server = "${spring.jmx.server:mbeanServer}")
|
||||||
protected static class IntegrationJmxConfiguration {
|
protected static class IntegrationJmxConfiguration {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ import org.springframework.util.ClassUtils;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ MBeanExporter.class })
|
@ConditionalOnClass({ MBeanExporter.class })
|
||||||
@ConditionalOnProperty(value = "spring.jmx.enabled", match = "true", defaultMatch = true)
|
@ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||||
public class JmxAutoConfiguration {
|
public class JmxAutoConfiguration {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ public class DeviceDelegatingViewResolverAutoConfiguration {
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableConfigurationProperties(DeviceDelegatingViewResolverProperties.class)
|
@EnableConfigurationProperties(DeviceDelegatingViewResolverProperties.class)
|
||||||
@ConditionalOnMissingBean(name = "deviceDelegatingViewResolver")
|
@ConditionalOnMissingBean(name = "deviceDelegatingViewResolver")
|
||||||
@ConditionalOnProperty(value = "spring.mobile.devicedelegatingviewresolver.enabled", match = "true", defaultMatch = false)
|
@ConditionalOnProperty(prefix = "spring.mobile.devicedelegatingviewresolver", name = "enabled", havingValue = "true", matchIfMissing = false)
|
||||||
protected static class DeviceDelegatingViewResolverConfiguration {
|
protected static class DeviceDelegatingViewResolverConfiguration {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
|
||||||
@ConditionalOnClass({ SitePreferenceHandlerInterceptor.class,
|
@ConditionalOnClass({ SitePreferenceHandlerInterceptor.class,
|
||||||
SitePreferenceHandlerMethodArgumentResolver.class })
|
SitePreferenceHandlerMethodArgumentResolver.class })
|
||||||
@AutoConfigureAfter(DeviceResolverAutoConfiguration.class)
|
@AutoConfigureAfter(DeviceResolverAutoConfiguration.class)
|
||||||
@ConditionalOnProperty(value ="spring.mobile.sitepreference.enabled", match = "true", defaultMatch = true)
|
@ConditionalOnProperty(prefix = "spring.mobile.sitepreference", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||||
public class SitePreferenceAutoConfiguration {
|
public class SitePreferenceAutoConfiguration {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware {
|
||||||
@ConditionalOnWebApplication
|
@ConditionalOnWebApplication
|
||||||
@ConditionalOnMissingBean({ OpenEntityManagerInViewInterceptor.class,
|
@ConditionalOnMissingBean({ OpenEntityManagerInViewInterceptor.class,
|
||||||
OpenEntityManagerInViewFilter.class })
|
OpenEntityManagerInViewFilter.class })
|
||||||
@ConditionalOnProperty(prefix = "spring.jpa", value = "openInView", match = "true", defaultMatch = true)
|
@ConditionalOnProperty(prefix = "spring.jpa", name = "open-in-view", havingValue = "true", matchIfMissing = true)
|
||||||
protected static class JpaWebConfiguration extends WebMvcConfigurerAdapter {
|
protected static class JpaWebConfiguration extends WebMvcConfigurerAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ import org.springframework.web.servlet.View;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ SocialConfigurerAdapter.class, FacebookConnectionFactory.class })
|
@ConditionalOnClass({ SocialConfigurerAdapter.class, FacebookConnectionFactory.class })
|
||||||
@ConditionalOnProperty(prefix = "spring.social.facebook.", value = "app-id")
|
@ConditionalOnProperty(prefix = "spring.social.facebook", name = "app-id")
|
||||||
@AutoConfigureBefore(SocialWebAutoConfiguration.class)
|
@AutoConfigureBefore(SocialWebAutoConfiguration.class)
|
||||||
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
|
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
|
||||||
public class FacebookAutoConfiguration {
|
public class FacebookAutoConfiguration {
|
||||||
|
|
@ -75,7 +75,7 @@ public class FacebookAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name = { "connect/facebookConnect", "connect/facebookConnected" })
|
@Bean(name = { "connect/facebookConnect", "connect/facebookConnected" })
|
||||||
@ConditionalOnProperty(prefix = "spring.social.", value = "auto-connection-views")
|
@ConditionalOnProperty(prefix = "spring.social", name = "auto-connection-views")
|
||||||
public View facebookConnectView() {
|
public View facebookConnectView() {
|
||||||
return new GenericConnectionStatusView("facebook", "Facebook");
|
return new GenericConnectionStatusView("facebook", "Facebook");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ import org.springframework.web.servlet.View;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ SocialConfigurerAdapter.class, LinkedInConnectionFactory.class })
|
@ConditionalOnClass({ SocialConfigurerAdapter.class, LinkedInConnectionFactory.class })
|
||||||
@ConditionalOnProperty(prefix = "spring.social.linkedin.", value = "app-id")
|
@ConditionalOnProperty(prefix = "spring.social.linkedin", name = "app-id")
|
||||||
@AutoConfigureBefore(SocialWebAutoConfiguration.class)
|
@AutoConfigureBefore(SocialWebAutoConfiguration.class)
|
||||||
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
|
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
|
||||||
public class LinkedInAutoConfiguration {
|
public class LinkedInAutoConfiguration {
|
||||||
|
|
@ -74,7 +74,7 @@ public class LinkedInAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name = { "connect/linkedinConnect", "connect/linkedinConnected" })
|
@Bean(name = { "connect/linkedinConnect", "connect/linkedinConnected" })
|
||||||
@ConditionalOnProperty(prefix = "spring.social.", value = "auto-connection-views")
|
@ConditionalOnProperty(prefix = "spring.social", name = "auto-connection-views")
|
||||||
public View linkedInConnectView() {
|
public View linkedInConnectView() {
|
||||||
return new GenericConnectionStatusView("linkedin", "LinkedIn");
|
return new GenericConnectionStatusView("linkedin", "LinkedIn");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ public class SocialWebAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(BeanNameViewResolver.class)
|
@ConditionalOnMissingBean(BeanNameViewResolver.class)
|
||||||
@ConditionalOnProperty(prefix = "spring.social.", value = "auto-connection-views")
|
@ConditionalOnProperty(prefix = "spring.social", name = "auto-connection-views")
|
||||||
public ViewResolver beanNameViewResolver() {
|
public ViewResolver beanNameViewResolver() {
|
||||||
BeanNameViewResolver viewResolver = new BeanNameViewResolver();
|
BeanNameViewResolver viewResolver = new BeanNameViewResolver();
|
||||||
viewResolver.setOrder(Integer.MIN_VALUE);
|
viewResolver.setOrder(Integer.MIN_VALUE);
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ import org.springframework.web.servlet.View;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass({ SocialConfigurerAdapter.class, TwitterConnectionFactory.class })
|
@ConditionalOnClass({ SocialConfigurerAdapter.class, TwitterConnectionFactory.class })
|
||||||
@ConditionalOnProperty(prefix = "spring.social.twitter.", value = "app-id")
|
@ConditionalOnProperty(prefix = "spring.social.twitter", name = "app-id")
|
||||||
@AutoConfigureBefore(SocialWebAutoConfiguration.class)
|
@AutoConfigureBefore(SocialWebAutoConfiguration.class)
|
||||||
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
|
@AutoConfigureAfter(WebMvcAutoConfiguration.class)
|
||||||
public class TwitterAutoConfiguration {
|
public class TwitterAutoConfiguration {
|
||||||
|
|
@ -79,7 +79,7 @@ public class TwitterAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name = { "connect/twitterConnect", "connect/twitterConnected" })
|
@Bean(name = { "connect/twitterConnect", "connect/twitterConnected" })
|
||||||
@ConditionalOnProperty(prefix = "spring.social.", value = "auto-connection-views")
|
@ConditionalOnProperty(prefix = "spring.social", name = "auto-connection-views")
|
||||||
public View twitterConnectView() {
|
public View twitterConnectView() {
|
||||||
return new GenericConnectionStatusView("twitter", "Twitter");
|
return new GenericConnectionStatusView("twitter", "Twitter");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -197,14 +197,14 @@ public class WebMvcAutoConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean(LocaleResolver.class)
|
@ConditionalOnMissingBean(LocaleResolver.class)
|
||||||
@ConditionalOnProperty(prefix = "spring.mvc.", value = "locale")
|
@ConditionalOnProperty(prefix = "spring.mvc", name = "locale")
|
||||||
public LocaleResolver localeResolver() {
|
public LocaleResolver localeResolver() {
|
||||||
return new FixedLocaleResolver(
|
return new FixedLocaleResolver(
|
||||||
StringUtils.parseLocaleString(this.mvcProperties.getLocale()));
|
StringUtils.parseLocaleString(this.mvcProperties.getLocale()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(prefix = "spring.mvc.", value = "date-format")
|
@ConditionalOnProperty(prefix = "spring.mvc", name = "date-format")
|
||||||
public Formatter<Date> dateFormatter() {
|
public Formatter<Date> dateFormatter() {
|
||||||
return new DateFormatter(this.mvcProperties.getDateFormat());
|
return new DateFormatter(this.mvcProperties.getDateFormat());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,23 +17,31 @@
|
||||||
package org.springframework.boot.autoconfigure.condition;
|
package org.springframework.boot.autoconfigure.condition;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
import org.springframework.boot.test.EnvironmentTestUtils;
|
import org.springframework.boot.test.EnvironmentTestUtils;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.internal.matchers.ThrowableMessageMatcher.hasMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ConditionalOnProperty}.
|
* Tests for {@link ConditionalOnProperty}.
|
||||||
*
|
*
|
||||||
* @author Maciej Walkowiak
|
* @author Maciej Walkowiak
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Phillip Webb
|
||||||
*/
|
*/
|
||||||
public class ConditionalOnPropertyTests {
|
public class ConditionalOnPropertyTests {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
private AnnotationConfigApplicationContext context;
|
private AnnotationConfigApplicationContext context;
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
@ -45,29 +53,28 @@ public class ConditionalOnPropertyTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void allPropertiesAreDefined() {
|
public void allPropertiesAreDefined() {
|
||||||
load(MultiplePropertiesRequiredConfiguration.class,
|
load(MultiplePropertiesRequiredConfiguration.class, "property1=value1",
|
||||||
"property1=value1", "property2=value2");
|
"property2=value2");
|
||||||
assertTrue(this.context.containsBean("foo"));
|
assertTrue(this.context.containsBean("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void notAllPropertiesAreDefined() {
|
public void notAllPropertiesAreDefined() {
|
||||||
load(MultiplePropertiesRequiredConfiguration.class,
|
load(MultiplePropertiesRequiredConfiguration.class, "property1=value1");
|
||||||
"property1=value1");
|
|
||||||
assertFalse(this.context.containsBean("foo"));
|
assertFalse(this.context.containsBean("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void propertyValueEqualsFalse() {
|
public void propertyValueEqualsFalse() {
|
||||||
load(MultiplePropertiesRequiredConfiguration.class,
|
load(MultiplePropertiesRequiredConfiguration.class, "property1=false",
|
||||||
"property1=false", "property2=value2");
|
"property2=value2");
|
||||||
assertFalse(this.context.containsBean("foo"));
|
assertFalse(this.context.containsBean("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void propertyValueEqualsFALSE() {
|
public void propertyValueEqualsFALSE() {
|
||||||
load(MultiplePropertiesRequiredConfiguration.class,
|
load(MultiplePropertiesRequiredConfiguration.class, "property1=FALSE",
|
||||||
"property1=FALSE", "property2=value2");
|
"property2=value2");
|
||||||
assertFalse(this.context.containsBean("foo"));
|
assertFalse(this.context.containsBean("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,12 +94,12 @@ public class ConditionalOnPropertyTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nonRelaxedName() throws Exception {
|
public void nonRelaxedName() throws Exception {
|
||||||
load(NonRelaxedPropertiesRequiredConfiguration.class,
|
load(NonRelaxedPropertiesRequiredConfiguration.class, "theRelaxedProperty=value1");
|
||||||
"theRelaxedProperty=value1");
|
|
||||||
assertFalse(this.context.containsBean("foo"));
|
assertFalse(this.context.containsBean("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // Enabled by default
|
@Test
|
||||||
|
// Enabled by default
|
||||||
public void enabledIfNotConfiguredOtherwise() {
|
public void enabledIfNotConfiguredOtherwise() {
|
||||||
load(EnabledIfNotConfiguredOtherwiseConfig.class);
|
load(EnabledIfNotConfiguredOtherwiseConfig.class);
|
||||||
assertTrue(this.context.containsBean("foo"));
|
assertTrue(this.context.containsBean("foo"));
|
||||||
|
|
@ -110,7 +117,8 @@ public class ConditionalOnPropertyTests {
|
||||||
assertFalse(this.context.containsBean("foo"));
|
assertFalse(this.context.containsBean("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // Disabled by default
|
@Test
|
||||||
|
// Disabled by default
|
||||||
public void disableIfNotConfiguredOtherwise() {
|
public void disableIfNotConfiguredOtherwise() {
|
||||||
load(DisabledIfNotConfiguredOtherwiseConfig.class);
|
load(DisabledIfNotConfiguredOtherwiseConfig.class);
|
||||||
assertFalse(this.context.containsBean("foo"));
|
assertFalse(this.context.containsBean("foo"));
|
||||||
|
|
@ -184,7 +192,8 @@ public class ConditionalOnPropertyTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void multiValuesAllSet() {
|
public void multiValuesAllSet() {
|
||||||
load(MultiValuesConfig.class, "simple.my-property:bar", "simple.my-another-property:bar");
|
load(MultiValuesConfig.class, "simple.my-property:bar",
|
||||||
|
"simple.my-another-property:bar");
|
||||||
assertTrue(this.context.containsBean("foo"));
|
assertTrue(this.context.containsBean("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -194,6 +203,28 @@ public class ConditionalOnPropertyTests {
|
||||||
assertFalse(this.context.containsBean("foo"));
|
assertFalse(this.context.containsBean("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void usingValueAttribute() throws Exception {
|
||||||
|
load(ValueAttribute.class, "some.property");
|
||||||
|
assertTrue(this.context.containsBean("foo"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void nameOrValueMustBeSpecified() throws Exception {
|
||||||
|
this.thrown.expect(IllegalStateException.class);
|
||||||
|
this.thrown.expectCause(hasMessage(containsString("The name or "
|
||||||
|
+ "value attribute of @ConditionalOnProperty must be specified")));
|
||||||
|
load(NoNameOrValueAttribute.class, "some.property");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void nameAndValueMustNotBeSpecified() throws Exception {
|
||||||
|
this.thrown.expect(IllegalStateException.class);
|
||||||
|
this.thrown.expectCause(hasMessage(containsString("The name and "
|
||||||
|
+ "value attributes of @ConditionalOnProperty are exclusive")));
|
||||||
|
load(NameAndValueAttribute.class, "some.property");
|
||||||
|
}
|
||||||
|
|
||||||
private void load(Class<?> config, String... environment) {
|
private void load(Class<?> config, String... environment) {
|
||||||
this.context = new AnnotationConfigApplicationContext();
|
this.context = new AnnotationConfigApplicationContext();
|
||||||
EnvironmentTestUtils.addEnvironment(this.context, environment);
|
EnvironmentTestUtils.addEnvironment(this.context, environment);
|
||||||
|
|
@ -201,9 +232,8 @@ public class ConditionalOnPropertyTests {
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty({ "property1", "property2" })
|
@ConditionalOnProperty(name = { "property1", "property2" })
|
||||||
protected static class MultiplePropertiesRequiredConfiguration {
|
protected static class MultiplePropertiesRequiredConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -214,7 +244,7 @@ public class ConditionalOnPropertyTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty(prefix = "spring.", value = "the-relaxed-property")
|
@ConditionalOnProperty(prefix = "spring.", name = "the-relaxed-property")
|
||||||
protected static class RelaxedPropertiesRequiredConfiguration {
|
protected static class RelaxedPropertiesRequiredConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -225,7 +255,7 @@ public class ConditionalOnPropertyTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty(prefix = "spring", value = "property")
|
@ConditionalOnProperty(prefix = "spring", name = "property")
|
||||||
protected static class RelaxedPropertiesRequiredConfigurationWithShortPrefix {
|
protected static class RelaxedPropertiesRequiredConfigurationWithShortPrefix {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -236,7 +266,7 @@ public class ConditionalOnPropertyTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty(value = "the-relaxed-property", relaxedNames = false)
|
@ConditionalOnProperty(name = "the-relaxed-property", relaxedNames = false)
|
||||||
protected static class NonRelaxedPropertiesRequiredConfiguration {
|
protected static class NonRelaxedPropertiesRequiredConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -246,8 +276,9 @@ public class ConditionalOnPropertyTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration // ${simple.myProperty:true}
|
@Configuration
|
||||||
@ConditionalOnProperty(prefix = "simple", value = "my-property", match = "true", defaultMatch = true)
|
// i.e ${simple.myProperty:true}
|
||||||
|
@ConditionalOnProperty(prefix = "simple", name = "my-property", havingValue = "true", matchIfMissing = true)
|
||||||
static class EnabledIfNotConfiguredOtherwiseConfig {
|
static class EnabledIfNotConfiguredOtherwiseConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -257,8 +288,9 @@ public class ConditionalOnPropertyTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration // ${simple.myProperty:false}
|
@Configuration
|
||||||
@ConditionalOnProperty(prefix = "simple", value = "my-property", match = "true", defaultMatch = false)
|
// i.e ${simple.myProperty:false}
|
||||||
|
@ConditionalOnProperty(prefix = "simple", name = "my-property", havingValue = "true", matchIfMissing = false)
|
||||||
static class DisabledIfNotConfiguredOtherwiseConfig {
|
static class DisabledIfNotConfiguredOtherwiseConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -269,7 +301,7 @@ public class ConditionalOnPropertyTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty(prefix = "simple", value = "my-property", match = "bar")
|
@ConditionalOnProperty(prefix = "simple", name = "my-property", havingValue = "bar")
|
||||||
static class SimpleValueConfig {
|
static class SimpleValueConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -280,7 +312,7 @@ public class ConditionalOnPropertyTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty(value = "simple.myProperty", match = "bar", defaultMatch = true)
|
@ConditionalOnProperty(name = "simple.myProperty", havingValue = "bar", matchIfMissing = true)
|
||||||
static class DefaultValueConfig {
|
static class DefaultValueConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -291,7 +323,7 @@ public class ConditionalOnPropertyTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty(prefix = "simple", value = "my-property", match = "bar")
|
@ConditionalOnProperty(prefix = "simple", name = "my-property", havingValue = "bar")
|
||||||
static class PrefixValueConfig {
|
static class PrefixValueConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -302,7 +334,7 @@ public class ConditionalOnPropertyTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty(prefix = "simple", value = "my-property", match = "bar", relaxedNames = false)
|
@ConditionalOnProperty(prefix = "simple", name = "my-property", havingValue = "bar", relaxedNames = false)
|
||||||
static class StrictNameConfig {
|
static class StrictNameConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -313,7 +345,8 @@ public class ConditionalOnPropertyTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty(prefix = "simple", value = {"my-property", "my-another-property"}, match = "bar")
|
@ConditionalOnProperty(prefix = "simple", name = { "my-property",
|
||||||
|
"my-another-property" }, havingValue = "bar")
|
||||||
static class MultiValuesConfig {
|
static class MultiValuesConfig {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -323,4 +356,36 @@ public class ConditionalOnPropertyTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnProperty("some.property")
|
||||||
|
protected static class ValueAttribute {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public String foo() {
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnProperty
|
||||||
|
protected static class NoNameOrValueAttribute {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public String foo() {
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConditionalOnProperty(value = "x", name = "y")
|
||||||
|
protected static class NameAndValueAttribute {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public String foo() {
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue