From 69ab2e462e7eaf0158cd3f96644c8fb46c5f5e9a Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Tue, 25 Apr 2017 10:52:25 -0700 Subject: [PATCH] Use new configuration properties in autoconfigure Update `spring-boot-autoconfigure` to use the new configuration properties support. See gh-9000 --- .../AutoConfigurationImportSelector.java | 31 ++------- .../autoconfigure/cache/CacheCondition.java | 31 +++++---- .../cache/EhCacheCacheConfiguration.java | 5 +- .../cache/JCacheCacheConfiguration.java | 7 +- .../condition/ResourceCondition.java | 23 +++---- .../couchbase/OnBootstrapHostsCondition.java | 66 +++++-------------- ...ExceptionTranslationAutoConfiguration.java | 13 ++-- .../CassandraDataAutoConfiguration.java | 16 ++--- .../hazelcast/HazelcastAutoConfiguration.java | 5 +- .../HazelcastConfigResourceCondition.java | 8 +-- .../info/ProjectInfoAutoConfiguration.java | 23 +++---- .../IntegrationAutoConfiguration.java | 17 +++-- .../autoconfigure/jdbc/DataSourceBuilder.java | 19 ++++-- .../jdbc/XADataSourceAutoConfiguration.java | 34 +++++++--- .../jmx/JmxAutoConfiguration.java | 18 ++--- .../MustacheEnvironmentCollector.java | 19 +----- .../MustacheTemplateAvailabilityProvider.java | 11 ++-- .../autoconfigure/orm/jpa/JpaProperties.java | 5 +- .../OAuth2RestOperationsConfiguration.java | 8 +-- .../OAuth2ResourceServerConfiguration.java | 33 ++++++---- ...ourceServerTokenServicesConfiguration.java | 28 ++++---- .../session/SessionCondition.java | 29 ++++---- ...PathBasedTemplateAvailabilityProvider.java | 24 +++---- .../TemplateAvailabilityProviders.java | 9 ++- ...ThymeleafTemplateAvailabilityProvider.java | 9 +-- .../ValidationAutoConfiguration.java | 13 ++-- .../web/OnEnabledResourceChainCondition.java | 8 +-- .../JspTemplateAvailabilityProvider.java | 9 +-- .../cache/CacheAutoConfigurationTests.java | 3 +- .../condition/ResourceConditionTests.java | 6 +- ...tionTranslationAutoConfigurationTests.java | 2 +- .../h2/H2ConsoleAutoConfigurationTests.java | 2 +- .../IntegrationAutoConfigurationTests.java | 8 ++- .../XADataSourceAutoConfigurationTests.java | 7 +- .../MustacheStandaloneIntegrationTests.java | 2 +- .../AbstractJpaAutoConfigurationTests.java | 2 + .../oauth2/OAuth2AutoConfigurationTests.java | 4 ++ ...ServerTokenServicesConfigurationTests.java | 3 +- .../SendGridAutoConfigurationTests.java | 4 +- .../SessionAutoConfigurationTests.java | 5 +- .../FacebookAutoConfigurationTests.java | 4 +- .../LinkedInAutoConfigurationTests.java | 4 +- .../MultiApiAutoConfigurationTests.java | 4 +- .../social/TwitterAutoConfigurationTests.java | 4 +- ...spatcherServletAutoConfigurationTests.java | 2 +- .../servlet/WebMvcAutoConfigurationTests.java | 2 +- .../WebServicesAutoConfigurationTests.java | 2 +- 47 files changed, 276 insertions(+), 315 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java index 4b5ebe85d1..6013b5de06 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/AutoConfigurationImportSelector.java @@ -20,10 +20,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -37,7 +35,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.boot.bind.RelaxedPropertyResolver; +import org.springframework.boot.context.properties.bind.Binder; import org.springframework.context.EnvironmentAware; import org.springframework.context.ResourceLoaderAware; import org.springframework.context.annotation.DeferredImportSelector; @@ -52,7 +50,6 @@ import org.springframework.core.type.classreading.CachingMetadataReaderFactory; import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; -import org.springframework.util.StringUtils; /** * {@link DeferredImportSelector} to handle {@link EnableAutoConfiguration @@ -211,28 +208,14 @@ public class AutoConfigurationImportSelector } private List getExcludeAutoConfigurationsProperty() { + String name = "spring.autoconfigure.exclude"; if (getEnvironment() instanceof ConfigurableEnvironment) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - this.environment, "spring.autoconfigure."); - Map properties = resolver.getSubProperties("exclude"); - if (properties.isEmpty()) { - return Collections.emptyList(); - } - List excludes = new ArrayList<>(); - for (Map.Entry entry : properties.entrySet()) { - String name = entry.getKey(); - Object value = entry.getValue(); - if (name.isEmpty() || name.startsWith("[") && value != null) { - excludes.addAll(new HashSet<>(Arrays.asList(StringUtils - .tokenizeToStringArray(String.valueOf(value), ",")))); - } - } - return excludes; + Binder binder = Binder.get(getEnvironment()); + return binder.bind(name, String[].class).map(Arrays::asList) + .orElse(Collections.emptyList()); } - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(getEnvironment(), - "spring.autoconfigure."); - String[] exclude = resolver.getProperty("exclude", String[].class); - return (Arrays.asList(exclude == null ? new String[0] : exclude)); + String[] excludes = getEnvironment().getProperty(name, String[].class); + return (excludes == null ? Collections.emptyList() : Arrays.asList(excludes)); } private List sort(List configurations, diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheCondition.java index a114ce1e14..2fcc93b394 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CacheCondition.java @@ -19,8 +19,11 @@ package org.springframework.boot.autoconfigure.cache; import org.springframework.boot.autoconfigure.condition.ConditionMessage; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; +import org.springframework.boot.context.properties.bind.BindException; +import org.springframework.boot.context.properties.bind.BindResult; +import org.springframework.boot.context.properties.bind.Binder; import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.env.Environment; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.ClassMetadata; @@ -30,6 +33,7 @@ import org.springframework.core.type.ClassMetadata; * * @author Stephane Nicoll * @author Phillip Webb + * @author Madhura Bhave * @since 1.3.0 */ class CacheCondition extends SpringBootCondition { @@ -43,18 +47,23 @@ class CacheCondition extends SpringBootCondition { } ConditionMessage.Builder message = ConditionMessage.forCondition("Cache", sourceClass); - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), "spring.cache."); - if (!resolver.containsProperty("type")) { - return ConditionOutcome.match(message.because("automatic cache type")); + Environment environment = context.getEnvironment(); + try { + BindResult specified = Binder.get(environment) + .bind("spring.cache.type", CacheType.class); + if (!specified.isBound()) { + return ConditionOutcome.match(message.because("automatic cache type")); + } + CacheType required = CacheConfigurations + .getType(((AnnotationMetadata) metadata).getClassName()); + if (specified.get() == required) { + return ConditionOutcome + .match(message.because(specified.get() + " cache type")); + } } - CacheType cacheType = CacheConfigurations - .getType(((AnnotationMetadata) metadata).getClassName()); - String value = resolver.getProperty("type").replace('-', '_').toUpperCase(); - if (value.equals(cacheType.name())) { - return ConditionOutcome.match(message.because(value + " cache type")); + catch (BindException ex) { } - return ConditionOutcome.noMatch(message.because(value + " cache type")); + return ConditionOutcome.noMatch(message.because("unknown cache type")); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/EhCacheCacheConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/EhCacheCacheConfiguration.java index f127750329..0c287c9353 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/EhCacheCacheConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/EhCacheCacheConfiguration.java @@ -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"); * you may not use this file except in compliance with the License. @@ -35,6 +35,7 @@ import org.springframework.core.io.Resource; * * @author Eddú Meléndez * @author Stephane Nicoll + * @author Madhura Bhave * @since 1.3.0 */ @Configuration @@ -78,7 +79,7 @@ class EhCacheCacheConfiguration { static class ConfigAvailableCondition extends ResourceCondition { ConfigAvailableCondition() { - super("EhCache", "spring.cache.ehcache", "config", "classpath:/ehcache.xml"); + super("EhCache", "spring.cache.ehcache.config", "classpath:/ehcache.xml"); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java index 4e76716d82..cbdf540f2c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java @@ -34,7 +34,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ConditionContext; @@ -53,6 +52,7 @@ import org.springframework.util.StringUtils; * Cache configuration for JSR-107 compliant providers. * * @author Stephane Nicoll + * @author Madhura Bhave * @since 1.3.0 */ @Configuration @@ -187,9 +187,8 @@ class JCacheCacheConfiguration { public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage.forCondition("JCache"); - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), "spring.cache.jcache."); - if (resolver.containsProperty("provider")) { + String providerProperty = "spring.cache.jcache.provider"; + if (context.getEnvironment().containsProperty(providerProperty)) { return ConditionOutcome .match(message.because("JCache provider specified")); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ResourceCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ResourceCondition.java index ee8c5324c5..5332382b5f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ResourceCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ResourceCondition.java @@ -22,7 +22,6 @@ import java.util.List; import org.springframework.boot.autoconfigure.condition.ConditionMessage.Builder; import org.springframework.boot.autoconfigure.condition.ConditionMessage.Style; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.annotation.ConditionContext; import org.springframework.core.io.Resource; import org.springframework.core.type.AnnotatedTypeMetadata; @@ -33,42 +32,38 @@ import org.springframework.core.type.AnnotatedTypeMetadata; * * @author Stephane Nicoll * @author Phillip Webb + * @author Madhura Bhave * @since 1.3.0 */ public abstract class ResourceCondition extends SpringBootCondition { private final String name; - private final String prefix; - - private final String propertyName; + private final String property; private final String[] resourceLocations; /** * Create a new condition. * @param name the name of the component - * @param prefix the prefix of the configuration key - * @param propertyName the name of the configuration key + * @param property the configuration property * @param resourceLocations default location(s) where the configuration file can be * found if the configuration key is not specified + * @since 2.0.0 */ - protected ResourceCondition(String name, String prefix, String propertyName, + protected ResourceCondition(String name, String property, String... resourceLocations) { this.name = name; - this.prefix = (prefix.endsWith(".") ? prefix : prefix + "."); - this.propertyName = propertyName; + this.property = property; this.resourceLocations = resourceLocations; } @Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), this.prefix); - if (resolver.containsProperty(this.propertyName)) { - return ConditionOutcome.match(startConditionMessage() - .foundExactly("property " + this.prefix + this.propertyName)); + if (context.getEnvironment().containsProperty(this.property)) { + return ConditionOutcome.match( + startConditionMessage().foundExactly("property " + this.property)); } return getResourceOutcome(context, metadata); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/OnBootstrapHostsCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/OnBootstrapHostsCondition.java index 0fcc190a37..2473ec6aa5 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/OnBootstrapHostsCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/OnBootstrapHostsCondition.java @@ -16,76 +16,42 @@ package org.springframework.boot.autoconfigure.couchbase; -import java.util.AbstractMap; -import java.util.HashMap; -import java.util.Map; +import java.util.List; import org.springframework.boot.autoconfigure.condition.ConditionMessage; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.PropertySourcesPropertyValues; -import org.springframework.boot.bind.RelaxedDataBinder; -import org.springframework.boot.bind.RelaxedNames; +import org.springframework.boot.context.properties.bind.BindResult; +import org.springframework.boot.context.properties.bind.Bindable; +import org.springframework.boot.context.properties.bind.Binder; import org.springframework.context.annotation.ConditionContext; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertySources; import org.springframework.core.type.AnnotatedTypeMetadata; -import org.springframework.validation.DataBinder; /** * Condition to determine if {@code spring.couchbase.bootstrap-hosts} is specified. * * @author Stephane Nicoll + * @author Madhura Bhave */ class OnBootstrapHostsCondition extends SpringBootCondition { + private static final Bindable> STRING_LIST = Bindable + .listOf(String.class); + @Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { - Environment environment = context.getEnvironment(); - PropertyResolver resolver = new PropertyResolver( - ((ConfigurableEnvironment) environment).getPropertySources(), - "spring.couchbase"); - Map.Entry entry = resolver.resolveProperty("bootstrap-hosts"); - if (entry != null) { + String name = "spring.couchbase.bootstrap-hosts"; + BindResult property = Binder.get(context.getEnvironment()).bind(name, + STRING_LIST); + if (property.isBound()) { return ConditionOutcome.match(ConditionMessage .forCondition(OnBootstrapHostsCondition.class.getName()) - .found("property").items("spring.couchbase.bootstrap-hosts")); + .found("property").items(name)); } - return ConditionOutcome.noMatch(ConditionMessage - .forCondition(OnBootstrapHostsCondition.class.getName()) - .didNotFind("property").items("spring.couchbase.bootstrap-hosts")); - } - - private static class PropertyResolver { - - private final String prefix; - - private final Map content; - - PropertyResolver(PropertySources propertySources, String prefix) { - this.prefix = prefix; - this.content = new HashMap<>(); - DataBinder binder = new RelaxedDataBinder(this.content, this.prefix); - binder.bind(new PropertySourcesPropertyValues(propertySources)); - } - - Map.Entry resolveProperty(String name) { - RelaxedNames prefixes = new RelaxedNames(this.prefix); - RelaxedNames keys = new RelaxedNames(name); - for (String prefix : prefixes) { - for (String relaxedKey : keys) { - String key = prefix + relaxedKey; - if (this.content.containsKey(relaxedKey)) { - return new AbstractMap.SimpleEntry<>(key, - this.content.get(relaxedKey)); - } - } - } - return null; - } - + return ConditionOutcome.noMatch( + ConditionMessage.forCondition(OnBootstrapHostsCondition.class.getName()) + .didNotFind("property").items(name)); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfiguration.java index 32084cb0da..3810e8a6f7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfiguration.java @@ -20,7 +20,6 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.annotation.Bean; import org.springframework.core.env.Environment; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; @@ -31,6 +30,7 @@ import org.springframework.dao.annotation.PersistenceExceptionTranslationPostPro * * @author Andy Wilkinson * @author Stephane Nicoll + * @author Madhura Bhave * @since 1.2.0 */ @ConditionalOnClass(PersistenceExceptionTranslationPostProcessor.class) @@ -42,15 +42,10 @@ public class PersistenceExceptionTranslationAutoConfiguration { public static PersistenceExceptionTranslationPostProcessor persistenceExceptionTranslationPostProcessor( Environment environment) { PersistenceExceptionTranslationPostProcessor postProcessor = new PersistenceExceptionTranslationPostProcessor(); - postProcessor.setProxyTargetClass(determineProxyTargetClass(environment)); + boolean proxyTargetClass = environment.getProperty( + "spring.aop.proxy-target-class", Boolean.class, Boolean.TRUE); + postProcessor.setProxyTargetClass(proxyTargetClass); return postProcessor; } - private static boolean determineProxyTargetClass(Environment environment) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, - "spring.aop."); - Boolean value = resolver.getProperty("proxyTargetClass", Boolean.class); - return (value != null ? value : true); - } - } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java index 55d515ab97..c37fae747d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java @@ -30,12 +30,11 @@ import org.springframework.boot.autoconfigure.cassandra.CassandraProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.domain.EntityScanPackages; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.context.properties.bind.Binder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertyResolver; import org.springframework.data.cassandra.config.CassandraEntityClassScanner; import org.springframework.data.cassandra.config.CassandraSessionFactoryBean; import org.springframework.data.cassandra.config.SchemaAction; @@ -54,6 +53,7 @@ import org.springframework.util.StringUtils; * @author Julien Dubois * @author Eddú Meléndez * @author Mark Paluch + * @author Madhura Bhave * @since 1.3.0 */ @Configuration @@ -68,15 +68,14 @@ public class CassandraDataAutoConfiguration { private final Cluster cluster; - private final PropertyResolver propertyResolver; + private final Environment environment; public CassandraDataAutoConfiguration(BeanFactory beanFactory, CassandraProperties properties, Cluster cluster, Environment environment) { this.beanFactory = beanFactory; this.properties = properties; this.cluster = cluster; - this.propertyResolver = new RelaxedPropertyResolver(environment, - "spring.data.cassandra."); + this.environment = environment; } @Bean @@ -112,10 +111,9 @@ public class CassandraDataAutoConfiguration { session.setCluster(this.cluster); session.setConverter(converter); session.setKeyspaceName(this.properties.getKeyspaceName()); - String name = this.propertyResolver.getProperty("schemaAction", - SchemaAction.NONE.name()); - SchemaAction schemaAction = SchemaAction.valueOf(name.toUpperCase()); - session.setSchemaAction(schemaAction); + Binder binder = Binder.get(this.environment); + binder.bind("spring.data.cassandra.schema-action", SchemaAction.class) + .ifBound(session::setSchemaAction); return session; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfiguration.java index 0f94847239..1eb7d23b81 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfiguration.java @@ -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"); * you may not use this file except in compliance with the License. @@ -38,6 +38,7 @@ import org.springframework.core.io.Resource; * configuration file is found in the environment. * * @author Stephane Nicoll + * @author Madhura Bhave * @since 1.3.0 * @see HazelcastConfigResourceCondition */ @@ -87,7 +88,7 @@ public class HazelcastAutoConfiguration { static class ConfigAvailableCondition extends HazelcastConfigResourceCondition { ConfigAvailableCondition() { - super("spring.hazelcast", "config"); + super("spring.hazelcast.config"); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java index 0dd8cc6961..0bec54d50a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastConfigResourceCondition.java @@ -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"); * you may not use this file except in compliance with the License. @@ -28,15 +28,15 @@ import org.springframework.core.type.AnnotatedTypeMetadata; * property referring to the resource to use has been set. * * @author Stephane Nicoll + * @author Madhura Bhave * @since 1.3.0 */ public abstract class HazelcastConfigResourceCondition extends ResourceCondition { static final String CONFIG_SYSTEM_PROPERTY = "hazelcast.config"; - protected HazelcastConfigResourceCondition(String prefix, String propertyName) { - super("Hazelcast", prefix, propertyName, "file:./hazelcast.xml", - "classpath:/hazelcast.xml"); + protected HazelcastConfigResourceCondition(String property) { + super("Hazelcast", property, "file:./hazelcast.xml", "classpath:/hazelcast.xml"); } @Override diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfiguration.java index 26690bb492..17f9c28f3e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfiguration.java @@ -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"); * you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnResource; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.GitProperties; @@ -33,7 +32,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.PropertyResolver; +import org.springframework.core.env.Environment; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; @@ -44,6 +43,7 @@ import org.springframework.core.type.AnnotatedTypeMetadata; * {@link EnableAutoConfiguration Auto-configuration} for various project information. * * @author Stephane Nicoll + * @author Madhura Bhave * @since 1.4.0 */ @Configuration @@ -91,19 +91,12 @@ public class ProjectInfoAutoConfiguration { public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ResourceLoader loader = context.getResourceLoader(); - if (loader == null) { - loader = this.defaultResourceLoader; - } - PropertyResolver propertyResolver = context.getEnvironment(); - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - propertyResolver, "spring.info.git."); - String location = resolver.getProperty("location"); + loader = (loader != null ? loader : this.defaultResourceLoader); + Environment environment = context.getEnvironment(); + String location = environment.getProperty("spring.info.git.location"); if (location == null) { - resolver = new RelaxedPropertyResolver(propertyResolver, "spring.git."); - location = resolver.getProperty("properties"); - if (location == null) { - location = "classpath:git.properties"; - } + location = environment.getProperty("spring.git.properties"); + location = (location != null ? location : "classpath:git.properties"); } ConditionMessage.Builder message = ConditionMessage .forCondition("GitResource"); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java index bdf301d8c2..21640d89df 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java @@ -29,7 +29,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.EnvironmentAware; import org.springframework.context.annotation.Bean; @@ -54,6 +53,7 @@ import org.springframework.util.StringUtils; * @author Dave Syer * @author Stephane Nicoll * @author Vedran Pavic + * @author Madhura Bhave * @since 1.1.0 */ @Configuration @@ -83,7 +83,7 @@ public class IntegrationAutoConfiguration { private BeanFactory beanFactory; - private RelaxedPropertyResolver propertyResolver; + private Environment environment; @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { @@ -92,21 +92,20 @@ public class IntegrationAutoConfiguration { @Override public void setEnvironment(Environment environment) { - this.propertyResolver = new RelaxedPropertyResolver(environment, - "spring.jmx."); + this.environment = environment; } @Bean public IntegrationMBeanExporter integrationMbeanExporter() { IntegrationMBeanExporter exporter = new IntegrationMBeanExporter(); - String defaultDomain = this.propertyResolver.getProperty("default-domain"); + String defaultDomain = this.environment + .getProperty("spring.jmx.default-domain"); if (StringUtils.hasLength(defaultDomain)) { exporter.setDefaultDomain(defaultDomain); } - String server = this.propertyResolver.getProperty("server", "mbeanServer"); - if (StringUtils.hasLength(server)) { - exporter.setServer(this.beanFactory.getBean(server, MBeanServer.class)); - } + String serverBean = this.environment.getProperty("spring.jmx.server", + "mbeanServer"); + exporter.setServer(this.beanFactory.getBean(serverBean, MBeanServer.class)); return exporter; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceBuilder.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceBuilder.java index 8419d95c03..930d4bc769 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceBuilder.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceBuilder.java @@ -22,8 +22,12 @@ import java.util.Map; import javax.sql.DataSource; import org.springframework.beans.BeanUtils; -import org.springframework.beans.MutablePropertyValues; -import org.springframework.boot.bind.RelaxedDataBinder; +import org.springframework.boot.context.properties.bind.Bindable; +import org.springframework.boot.context.properties.bind.Binder; +import org.springframework.boot.context.properties.source.ConfigurationPropertyName; +import org.springframework.boot.context.properties.source.ConfigurationPropertyNameAliases; +import org.springframework.boot.context.properties.source.ConfigurationPropertySource; +import org.springframework.boot.context.properties.source.MapConfigurationPropertySource; import org.springframework.boot.jdbc.DatabaseDriver; import org.springframework.util.ClassUtils; @@ -37,6 +41,7 @@ import org.springframework.util.ClassUtils; * {@code @ConfigurationProperties}. * * @author Dave Syer + * @author Madhura Bhave * @since 1.1.0 */ public class DataSourceBuilder { @@ -82,9 +87,13 @@ public class DataSourceBuilder { } private void bind(DataSource result) { - MutablePropertyValues properties = new MutablePropertyValues(this.properties); - new RelaxedDataBinder(result).withAlias("url", "jdbcUrl") - .withAlias("username", "user").bind(properties); + ConfigurationPropertySource source = new MapConfigurationPropertySource( + this.properties); + ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases(); + aliases.addAlaises("url", "jdbc-url"); + aliases.addAlaises("username", "user"); + Binder binder = new Binder(source.withAliases(aliases)); + binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(result)); } public DataSourceBuilder type(Class type) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java index 810b440a42..11c9721c7a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java @@ -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"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import javax.sql.XADataSource; import javax.transaction.TransactionManager; import org.springframework.beans.BeanUtils; -import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureBefore; @@ -29,8 +28,13 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.bind.RelaxedDataBinder; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.context.properties.bind.Bindable; +import org.springframework.boot.context.properties.bind.Binder; +import org.springframework.boot.context.properties.source.ConfigurationPropertyName; +import org.springframework.boot.context.properties.source.ConfigurationPropertyNameAliases; +import org.springframework.boot.context.properties.source.ConfigurationPropertySource; +import org.springframework.boot.context.properties.source.MapConfigurationPropertySource; import org.springframework.boot.jdbc.DatabaseDriver; import org.springframework.boot.jta.XADataSourceWrapper; import org.springframework.context.annotation.Bean; @@ -44,6 +48,7 @@ import org.springframework.util.StringUtils; * * @author Phillip Webb * @author Josh Long + * @author Madhura Bhave * @since 1.2.0 */ @AutoConfigureBefore(DataSourceAutoConfiguration.class) @@ -105,13 +110,22 @@ public class XADataSourceAutoConfiguration implements BeanClassLoaderAware { } } - private void bindXaProperties(XADataSource target, DataSourceProperties properties) { - MutablePropertyValues values = new MutablePropertyValues(); - values.add("user", this.properties.determineUsername()); - values.add("password", this.properties.determinePassword()); - values.add("url", this.properties.determineUrl()); - values.addPropertyValues(properties.getXa().getProperties()); - new RelaxedDataBinder(target).withAlias("user", "username").bind(values); + private void bindXaProperties(XADataSource target, + DataSourceProperties dataSourceProperties) { + Binder binder = new Binder(getBinderSource(dataSourceProperties)); + binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(target)); + } + + private ConfigurationPropertySource getBinderSource( + DataSourceProperties dataSourceProperties) { + MapConfigurationPropertySource source = new MapConfigurationPropertySource(); + source.put("user", this.properties.determineUsername()); + source.put("password", this.properties.determinePassword()); + source.put("url", this.properties.determineUrl()); + source.putAll(dataSourceProperties.getXa().getProperties()); + ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases(); + aliases.addAlaises("user", "username"); + return source.withAliases(aliases); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java index ab04327001..9b7f18e9e0 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.SearchStrategy; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.EnvironmentAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -49,19 +48,20 @@ import org.springframework.util.StringUtils; * To disable auto export of annotation beans set {@code spring.jmx.enabled: false}. * * @author Christian Dupuis + * @author Madhura Bhave */ @Configuration @ConditionalOnClass({ MBeanExporter.class }) @ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true) public class JmxAutoConfiguration implements EnvironmentAware, BeanFactoryAware { - private RelaxedPropertyResolver propertyResolver; + private Environment environment; private BeanFactory beanFactory; @Override public void setEnvironment(Environment environment) { - this.propertyResolver = new RelaxedPropertyResolver(environment, "spring.jmx."); + this.environment = environment; } @Override @@ -76,9 +76,10 @@ public class JmxAutoConfiguration implements EnvironmentAware, BeanFactoryAware AnnotationMBeanExporter exporter = new AnnotationMBeanExporter(); exporter.setRegistrationPolicy(RegistrationPolicy.FAIL_ON_EXISTING); exporter.setNamingStrategy(namingStrategy); - String server = this.propertyResolver.getProperty("server", "mbeanServer"); - if (StringUtils.hasLength(server)) { - exporter.setServer(this.beanFactory.getBean(server, MBeanServer.class)); + String serverBean = this.environment.getProperty("spring.jmx.server", + "mbeanServer"); + if (StringUtils.hasLength(serverBean)) { + exporter.setServer(this.beanFactory.getBean(serverBean, MBeanServer.class)); } return exporter; } @@ -88,7 +89,7 @@ public class JmxAutoConfiguration implements EnvironmentAware, BeanFactoryAware public ParentAwareNamingStrategy objectNamingStrategy() { ParentAwareNamingStrategy namingStrategy = new ParentAwareNamingStrategy( new AnnotationJmxAttributeSource()); - String defaultDomain = this.propertyResolver.getProperty("default-domain"); + String defaultDomain = this.environment.getProperty("spring.jmx.default-domain"); if (StringUtils.hasLength(defaultDomain)) { namingStrategy.setDefaultDomain(defaultDomain); } @@ -106,7 +107,6 @@ public class JmxAutoConfiguration implements EnvironmentAware, BeanFactoryAware factory.setLocateExistingServerIfPossible(true); factory.afterPropertiesSet(); return factory.getObject(); - } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java index e99691dcca..92c4170d47 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheEnvironmentCollector.java @@ -16,16 +16,10 @@ package org.springframework.boot.autoconfigure.mustache; -import java.util.HashMap; -import java.util.Map; - import com.samskivert.mustache.DefaultCollector; import com.samskivert.mustache.Mustache.Collector; import com.samskivert.mustache.Mustache.VariableFetcher; -import org.springframework.boot.bind.PropertySourcesPropertyValues; -import org.springframework.boot.bind.RelaxedDataBinder; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.EnvironmentAware; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; @@ -34,6 +28,7 @@ import org.springframework.core.env.Environment; * Mustache {@link Collector} to expose properties from the Spring {@link Environment}. * * @author Dave Syer + * @author Madhura Bhave * @since 1.2.2 */ public class MustacheEnvironmentCollector extends DefaultCollector @@ -41,19 +36,11 @@ public class MustacheEnvironmentCollector extends DefaultCollector private ConfigurableEnvironment environment; - private Map target; - - private RelaxedPropertyResolver propertyResolver; - private final VariableFetcher propertyFetcher = new PropertyVariableFetcher(); @Override public void setEnvironment(Environment environment) { this.environment = (ConfigurableEnvironment) environment; - this.target = new HashMap<>(); - new RelaxedDataBinder(this.target).bind( - new PropertySourcesPropertyValues(this.environment.getPropertySources())); - this.propertyResolver = new RelaxedPropertyResolver(environment); } @Override @@ -62,7 +49,7 @@ public class MustacheEnvironmentCollector extends DefaultCollector if (fetcher != null) { return fetcher; } - if (this.propertyResolver.containsProperty(name)) { + if (this.environment.containsProperty(name)) { return this.propertyFetcher; } return null; @@ -72,7 +59,7 @@ public class MustacheEnvironmentCollector extends DefaultCollector @Override public Object get(Object ctx, String name) throws Exception { - return MustacheEnvironmentCollector.this.propertyResolver.getProperty(name); + return MustacheEnvironmentCollector.this.environment.getProperty(name); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheTemplateAvailabilityProvider.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheTemplateAvailabilityProvider.java index 2454878863..0019f1020f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheTemplateAvailabilityProvider.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheTemplateAvailabilityProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,7 @@ package org.springframework.boot.autoconfigure.mustache; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertyResolver; import org.springframework.core.io.ResourceLoader; import org.springframework.util.ClassUtils; @@ -28,6 +26,7 @@ import org.springframework.util.ClassUtils; * Mustache view templates. * * @author Dave Syer + * @author Madhura Bhave * @since 1.2.2 */ public class MustacheTemplateAvailabilityProvider @@ -37,11 +36,9 @@ public class MustacheTemplateAvailabilityProvider public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader, ResourceLoader resourceLoader) { if (ClassUtils.isPresent("com.samskivert.mustache.Template", classLoader)) { - PropertyResolver resolver = new RelaxedPropertyResolver(environment, - "spring.mustache."); - String prefix = resolver.getProperty("prefix", + String prefix = environment.getProperty("spring.mustache.prefix", MustacheProperties.DEFAULT_PREFIX); - String suffix = resolver.getProperty("suffix", + String suffix = environment.getProperty("spring.mustache.suffix", MustacheProperties.DEFAULT_SUFFIX); return resourceLoader.getResource(prefix + view + suffix).exists(); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java index eb253ce916..ea105d9e10 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java @@ -34,6 +34,7 @@ import org.springframework.util.StringUtils; * @author Andy Wilkinson * @author Stephane Nicoll * @author Eddú Meléndez + * @author Madhura Bhave * @since 1.1.0 */ @ConfigurationProperties(prefix = "spring.jpa") @@ -169,11 +170,11 @@ public class JpaProperties { this.ddlAuto = ddlAuto; } - public boolean isUseNewIdGeneratorMappings() { + public Boolean isUseNewIdGeneratorMappings() { return this.useNewIdGeneratorMappings; } - public void setUseNewIdGeneratorMappings(boolean useNewIdGeneratorMappings) { + public void setUseNewIdGeneratorMappings(Boolean useNewIdGeneratorMappings) { this.useNewIdGeneratorMappings = useNewIdGeneratorMappings; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java index 929a6af72f..48be1385d7 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2RestOperationsConfiguration.java @@ -31,7 +31,6 @@ import org.springframework.boot.autoconfigure.condition.NoneNestedConditions; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2RestOperationsConfiguration.OAuth2ClientIdCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; @@ -42,7 +41,6 @@ import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.ScopedProxyMode; -import org.springframework.core.env.PropertyResolver; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -62,6 +60,7 @@ import org.springframework.util.StringUtils; * Configuration for OAuth2 Single Sign On REST operations. * * @author Dave Syer + * @author Madhura Bhave * @since 1.3.0 */ @Configuration @@ -159,9 +158,8 @@ public class OAuth2RestOperationsConfiguration { @Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { - PropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), "security.oauth2.client."); - String clientId = resolver.getProperty("client-id"); + String clientId = context.getEnvironment() + .getProperty("security.oauth2.client.client-id"); ConditionMessage.Builder message = ConditionMessage .forCondition("OAuth Client ID"); if (StringUtils.hasLength(clientId)) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java index a1d2a6e84e..58c68874df 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java @@ -16,6 +16,8 @@ package org.springframework.boot.autoconfigure.security.oauth2.resource; +import java.util.Map; + import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -28,7 +30,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2ResourceServerConfiguration.ResourceServerCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; +import org.springframework.boot.context.properties.bind.Bindable; +import org.springframework.boot.context.properties.bind.Binder; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; @@ -39,6 +42,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ConfigurationCondition; import org.springframework.context.annotation.Import; import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.StandardAnnotationMetadata; @@ -58,6 +62,7 @@ import org.springframework.util.StringUtils; * * @author Greg Turnquist * @author Dave Syer + * @author Madhura Bhave * @since 1.3.0 */ @Configuration @@ -150,6 +155,9 @@ public class OAuth2ResourceServerConfiguration { protected static class ResourceServerCondition extends SpringBootCondition implements ConfigurationCondition { + private static final Bindable> STRING_OBJECT_MAP = Bindable + .mapOf(String.class, Object.class); + private static final String AUTHORIZATION_ANNOTATION = "org.springframework." + "security.oauth2.config.annotation.web.configuration." + "AuthorizationServerEndpointsConfiguration"; @@ -165,24 +173,28 @@ public class OAuth2ResourceServerConfiguration { ConditionMessage.Builder message = ConditionMessage .forCondition("OAuth ResourceServer Condition"); Environment environment = context.getEnvironment(); - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, - "security.oauth2.resource."); + if (!(environment instanceof ConfigurableEnvironment)) { + return ConditionOutcome + .noMatch(message.didNotFind("A ConfigurableEnvironment").atAll()); + } if (hasOAuthClientId(environment)) { return ConditionOutcome.match(message.foundExactly("client-id property")); } - if (!resolver.getSubProperties("jwt").isEmpty()) { + Binder binder = Binder.get(environment); + String prefix = "security.oauth2.resource."; + if (binder.bind(prefix + "jwt", STRING_OBJECT_MAP).isBound()) { return ConditionOutcome .match(message.foundExactly("JWT resource configuration")); } - if (!resolver.getSubProperties("jwk").isEmpty()) { + if (binder.bind(prefix + "jwk", STRING_OBJECT_MAP).isBound()) { return ConditionOutcome .match(message.foundExactly("JWK resource configuration")); } - if (StringUtils.hasText(resolver.getProperty("user-info-uri"))) { + if (StringUtils.hasText(environment.getProperty(prefix + "user-info-uri"))) { return ConditionOutcome .match(message.foundExactly("user-info-uri property")); } - if (StringUtils.hasText(resolver.getProperty("token-info-uri"))) { + if (StringUtils.hasText(environment.getProperty(prefix + "token-info-uri"))) { return ConditionOutcome .match(message.foundExactly("token-info-uri property")); } @@ -194,14 +206,13 @@ public class OAuth2ResourceServerConfiguration { } } return ConditionOutcome.noMatch( - message.didNotFind("client id, JWT resource or authorization server") + message.didNotFind("client ID, JWT resource or authorization server") .atAll()); } private boolean hasOAuthClientId(Environment environment) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, - "security.oauth2.client."); - return StringUtils.hasLength(resolver.getProperty("client-id", "")); + return StringUtils.hasLength( + environment.getProperty("security.oauth2.client.client-id")); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java index 056a8b7775..112237ac47 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java @@ -30,7 +30,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; import org.springframework.boot.autoconfigure.condition.NoneNestedConditions; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ConditionContext; import org.springframework.context.annotation.Conditional; @@ -319,17 +318,17 @@ public class ResourceServerTokenServicesConfiguration { ConditionMessage.Builder message = ConditionMessage .forCondition("OAuth TokenInfo Condition"); Environment environment = context.getEnvironment(); - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, - "security.oauth2.resource."); - Boolean preferTokenInfo = resolver.getProperty("prefer-token-info", - Boolean.class); + Boolean preferTokenInfo = environment.getProperty( + "security.oauth2.resource.prefer-token-info", Boolean.class); if (preferTokenInfo == null) { preferTokenInfo = environment .resolvePlaceholders("${OAUTH2_RESOURCE_PREFERTOKENINFO:true}") .equals("true"); } - String tokenInfoUri = resolver.getProperty("token-info-uri"); - String userInfoUri = resolver.getProperty("user-info-uri"); + String tokenInfoUri = environment + .getProperty("security.oauth2.resource.token-info-uri"); + String userInfoUri = environment + .getProperty("security.oauth2.resource.user-info-uri"); if (!StringUtils.hasLength(userInfoUri) && !StringUtils.hasLength(tokenInfoUri)) { return ConditionOutcome @@ -351,10 +350,11 @@ public class ResourceServerTokenServicesConfiguration { AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage .forCondition("OAuth JWT Condition"); - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), "security.oauth2.resource.jwt."); - String keyValue = resolver.getProperty("key-value"); - String keyUri = resolver.getProperty("key-uri"); + Environment environment = context.getEnvironment(); + String keyValue = environment + .getProperty("security.oauth2.resource.jwt.key-value"); + String keyUri = environment + .getProperty("security.oauth2.resource.jwt.key-uri"); if (StringUtils.hasText(keyValue) || StringUtils.hasText(keyUri)) { return ConditionOutcome .match(message.foundExactly("provided public key")); @@ -372,9 +372,9 @@ public class ResourceServerTokenServicesConfiguration { AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage .forCondition("OAuth JWK Condition"); - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), "security.oauth2.resource.jwk."); - String keyUri = resolver.getProperty("key-set-uri"); + Environment environment = context.getEnvironment(); + String keyUri = environment + .getProperty("security.oauth2.resource.jwk.key-set-uri"); if (StringUtils.hasText(keyUri)) { return ConditionOutcome .match(message.foundExactly("provided jwk key set URI")); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionCondition.java index ea2f4cd7aa..5c142f104f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionCondition.java @@ -19,8 +19,10 @@ package org.springframework.boot.autoconfigure.session; import org.springframework.boot.autoconfigure.condition.ConditionMessage; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; +import org.springframework.boot.context.properties.bind.BindException; +import org.springframework.boot.context.properties.bind.Binder; import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.env.Environment; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.AnnotationMetadata; @@ -29,6 +31,7 @@ import org.springframework.core.type.AnnotationMetadata; * * @author Tommy Ludwig * @author Stephane Nicoll + * @author Madhura Bhave */ class SessionCondition extends SpringBootCondition { @@ -37,21 +40,25 @@ class SessionCondition extends SpringBootCondition { AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage .forCondition("Session Condition"); - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver( - context.getEnvironment(), "spring.session."); - StoreType sessionStoreType = SessionStoreMappings + Environment environment = context.getEnvironment(); + StoreType required = SessionStoreMappings .getType(((AnnotationMetadata) metadata).getClassName()); - if (!resolver.containsProperty("store-type")) { + if (!environment.containsProperty("spring.session.store-type")) { return ConditionOutcome.noMatch( message.didNotFind("spring.session.store-type property").atAll()); } - String value = resolver.getProperty("store-type").replace('-', '_').toUpperCase(); - if (value.equals(sessionStoreType.name())) { - return ConditionOutcome.match(message - .found("spring.session.store-type property").items(sessionStoreType)); + try { + Binder binder = Binder.get(environment); + return binder.bind("spring.session.store-type", StoreType.class) + .map((t) -> new ConditionOutcome(t == required, + message.found("spring.session.store-type property").items(t))) + .orElse(ConditionOutcome.noMatch(message + .didNotFind("spring.session.store-type property").atAll())); + } + catch (BindException ex) { + return ConditionOutcome.noMatch( + message.found("invalid spring.session.store-type property").atAll()); } - return ConditionOutcome.noMatch( - message.found("spring.session.store-type property").items(value)); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/PathBasedTemplateAvailabilityProvider.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/PathBasedTemplateAvailabilityProvider.java index 5079b660ec..9217b4f4ba 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/PathBasedTemplateAvailabilityProvider.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/PathBasedTemplateAvailabilityProvider.java @@ -18,10 +18,8 @@ package org.springframework.boot.autoconfigure.template; import java.util.List; -import org.springframework.beans.BeanUtils; -import org.springframework.boot.bind.PropertySourcesPropertyValues; -import org.springframework.boot.bind.RelaxedDataBinder; -import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.boot.autoconfigure.template.PathBasedTemplateAvailabilityProvider.TemplateAvailabilityProperties; +import org.springframework.boot.context.properties.bind.Binder; import org.springframework.core.env.Environment; import org.springframework.core.io.ResourceLoader; import org.springframework.util.ClassUtils; @@ -32,20 +30,20 @@ import org.springframework.util.ClassUtils; * * @author Andy Wilkinson * @author Phillip Webb + * @author Madhura Bhave * @since 1.4.6 */ -public abstract class PathBasedTemplateAvailabilityProvider +public abstract class PathBasedTemplateAvailabilityProvider implements TemplateAvailabilityProvider { private final String className; - private final Class propertiesClass; + private final Class propertiesClass; private final String propertyPrefix; public PathBasedTemplateAvailabilityProvider(String className, - Class propertiesClass, - String propertyPrefix) { + Class propertiesClass, String propertyPrefix) { this.className = className; this.propertiesClass = propertiesClass; this.propertyPrefix = propertyPrefix; @@ -55,12 +53,10 @@ public abstract class PathBasedTemplateAvailabilityProvider public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader, ResourceLoader resourceLoader) { if (ClassUtils.isPresent(this.className, classLoader)) { - TemplateAvailabilityProperties properties = BeanUtils - .instantiateClass(this.propertiesClass); - RelaxedDataBinder binder = new RelaxedDataBinder(properties, - this.propertyPrefix); - binder.bind(new PropertySourcesPropertyValues( - ((ConfigurableEnvironment) environment).getPropertySources())); + Binder binder = Binder.get(environment); + TemplateAvailabilityProperties properties = binder + .bind(this.propertyPrefix, this.propertiesClass) + .orElseCreate(this.propertiesClass); return isTemplateAvailable(view, resourceLoader, properties); } return false; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/TemplateAvailabilityProviders.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/TemplateAvailabilityProviders.java index 9b073f5409..3e729ab93f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/TemplateAvailabilityProviders.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/template/TemplateAvailabilityProviders.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.ApplicationContext; import org.springframework.core.env.Environment; import org.springframework.core.io.ResourceLoader; @@ -36,6 +35,7 @@ import org.springframework.util.Assert; * {@code spring.template.provider.cache} property is set to {@code false}. * * @author Phillip Webb + * @author Madhura Bhave * @since 1.4.0 */ public class TemplateAvailabilityProviders { @@ -134,10 +134,9 @@ public class TemplateAvailabilityProviders { Assert.notNull(environment, "Environment must not be null"); Assert.notNull(classLoader, "ClassLoader must not be null"); Assert.notNull(resourceLoader, "ResourceLoader must not be null"); - - RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver( - environment, "spring.template.provider."); - if (!propertyResolver.getProperty("cache", Boolean.class, true)) { + Boolean useCache = environment.getProperty("spring.template.provider.cache", + Boolean.class, true); + if (!useCache) { return findProvider(view, environment, classLoader, resourceLoader); } TemplateAvailabilityProvider provider = this.resolved.get(view); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafTemplateAvailabilityProvider.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafTemplateAvailabilityProvider.java index b99c3ac9d1..cb0b3eaf55 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafTemplateAvailabilityProvider.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafTemplateAvailabilityProvider.java @@ -17,9 +17,7 @@ package org.springframework.boot.autoconfigure.thymeleaf; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertyResolver; import org.springframework.core.io.ResourceLoader; import org.springframework.util.ClassUtils; @@ -28,6 +26,7 @@ import org.springframework.util.ClassUtils; * Thymeleaf view templates. * * @author Andy Wilkinson + * @author Madhura Bhave * @since 1.1.0 */ public class ThymeleafTemplateAvailabilityProvider @@ -38,11 +37,9 @@ public class ThymeleafTemplateAvailabilityProvider ClassLoader classLoader, ResourceLoader resourceLoader) { if (ClassUtils.isPresent("org.thymeleaf.spring5.SpringTemplateEngine", classLoader)) { - PropertyResolver resolver = new RelaxedPropertyResolver(environment, - "spring.thymeleaf."); - String prefix = resolver.getProperty("prefix", + String prefix = environment.getProperty("spring.thymeleaf.prefix", ThymeleafProperties.DEFAULT_PREFIX); - String suffix = resolver.getProperty("suffix", + String suffix = environment.getProperty("spring.thymeleaf.suffix", ThymeleafProperties.DEFAULT_SUFFIX); return resourceLoader.getResource(prefix + view + suffix).exists(); } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.java index 99c4efa6b9..32abaccad1 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.java @@ -24,7 +24,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnResource; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -36,6 +35,7 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess * infrastructure. * * @author Stephane Nicoll + * @author Madhura Bhave * @since 1.5.0 */ @Configuration @@ -51,16 +51,11 @@ public class ValidationAutoConfiguration { public static MethodValidationPostProcessor methodValidationPostProcessor( Environment environment, Validator validator) { MethodValidationPostProcessor processor = new MethodValidationPostProcessor(); - processor.setProxyTargetClass(determineProxyTargetClass(environment)); + boolean proxyTargetClass = environment + .getProperty("spring.aop.proxy-target-class", Boolean.class, true); + processor.setProxyTargetClass(proxyTargetClass); processor.setValidator(validator); return processor; } - private static boolean determineProxyTargetClass(Environment environment) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, - "spring.aop."); - Boolean value = resolver.getProperty("proxyTargetClass", Boolean.class); - return (value != null ? value : true); - } - } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/OnEnabledResourceChainCondition.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/OnEnabledResourceChainCondition.java index 52e702c5b6..b209d9d1dc 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/OnEnabledResourceChainCondition.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/OnEnabledResourceChainCondition.java @@ -19,11 +19,9 @@ package org.springframework.boot.autoconfigure.web; import org.springframework.boot.autoconfigure.condition.ConditionMessage; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.ConditionContext; import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.PropertyResolver; import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.util.ClassUtils; @@ -33,6 +31,7 @@ import org.springframework.util.ClassUtils; * * @author Stephane Nicoll * @author Phillip Webb + * @author Madhura Bhave * @see ConditionalOnEnabledResourceChain */ class OnEnabledResourceChainCondition extends SpringBootCondition { @@ -66,9 +65,8 @@ class OnEnabledResourceChainCondition extends SpringBootCondition { 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); + String name = "spring.resources.chain." + key + "enabled"; + return environment.getProperty(name, Boolean.class, defaultValue); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/JspTemplateAvailabilityProvider.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/JspTemplateAvailabilityProvider.java index b2d7b14386..b5298f99c3 100755 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/JspTemplateAvailabilityProvider.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/JspTemplateAvailabilityProvider.java @@ -17,9 +17,7 @@ package org.springframework.boot.autoconfigure.web.servlet; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; -import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertyResolver; import org.springframework.core.io.ResourceLoader; import org.springframework.util.ClassUtils; @@ -29,6 +27,7 @@ import org.springframework.util.ClassUtils; * * @author Andy Wilkinson * @author Stephane Nicoll + * @author Madhura Bhave * @since 1.1.0 */ public class JspTemplateAvailabilityProvider implements TemplateAvailabilityProvider { @@ -44,11 +43,9 @@ public class JspTemplateAvailabilityProvider implements TemplateAvailabilityProv } private String getResourceName(String view, Environment environment) { - PropertyResolver resolver = new RelaxedPropertyResolver(environment, - "spring.mvc.view."); - String prefix = resolver.getProperty("prefix", + String prefix = environment.getProperty("spring.mvc.view.prefix", WebMvcAutoConfiguration.DEFAULT_PREFIX); - String suffix = resolver.getProperty("suffix", + String suffix = environment.getProperty("spring.mvc.view.suffix", WebMvcAutoConfiguration.DEFAULT_SUFFIX); return prefix + view + suffix; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java index bfa4179224..65258ec12c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java @@ -145,8 +145,7 @@ public class CacheAutoConfigurationTests { @Test public void notSupportedCachingMode() { this.thrown.expect(BeanCreationException.class); - this.thrown.expectMessage("cache"); - this.thrown.expectMessage("foobar"); + this.thrown.expectMessage("Failed to bind properties under 'spring.cache.type'"); load(DefaultCacheConfiguration.class, "spring.cache.type=foobar"); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ResourceConditionTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ResourceConditionTests.java index 7cfd5440df..71f7a26a56 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ResourceConditionTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ResourceConditionTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -96,7 +96,7 @@ public class ResourceConditionTests { private static class DefaultLocationResourceCondition extends ResourceCondition { DefaultLocationResourceCondition() { - super("test", "spring.foo.test.", "config", "classpath:/logging.properties"); + super("test", "spring.foo.test.config", "classpath:/logging.properties"); } } @@ -105,7 +105,7 @@ public class ResourceConditionTests { extends ResourceCondition { UnknownDefaultLocationResourceCondition() { - super("test", "spring.foo.test", "config", + super("test", "spring.foo.test.config", "classpath:/this-file-does-not-exist.xml"); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfigurationTests.java index 495797452b..0e4c1fdc78 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/dao/PersistenceExceptionTranslationAutoConfigurationTests.java @@ -67,7 +67,7 @@ public class PersistenceExceptionTranslationAutoConfigurationTests { public void exceptionTranslationPostProcessorCanBeConfiguredToUseJdkProxy() { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, - "spring.aop.proxyTargetClass=false"); + "spring.aop.proxy-target-class=false"); this.context.register(PersistenceExceptionTranslationAutoConfiguration.class); this.context.refresh(); Map beans = this.context diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java index 02970419a3..86f3bd5c70 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java @@ -81,7 +81,7 @@ public class H2ConsoleAutoConfigurationTests { @Test public void customPathMustBeginWithASlash() { this.thrown.expect(BeanCreationException.class); - this.thrown.expectMessage("Path must start with /"); + this.thrown.expectMessage("Failed to bind properties under 'spring.h2.console'"); this.context.register(H2ConsoleAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "spring.h2.console.enabled:true", "spring.h2.console.path:custom"); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java index 5c09761344..8112cead18 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java @@ -31,6 +31,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerA import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -99,11 +100,12 @@ public class IntegrationAutoConfigurationTests { load(); AnnotationConfigApplicationContext parent = this.context; this.context = new AnnotationConfigApplicationContext(); + ConfigurationPropertySources.attach(this.context.getEnvironment()); this.context.setParent(parent); this.context.register(JmxAutoConfiguration.class, IntegrationAutoConfiguration.class); TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, - "SPRING_JMX_DEFAULT_DOMAIN=org.foo"); + "spring.jmx.default_domain=org.foo"); this.context.refresh(); assertThat(this.context.getBean(HeaderChannelRegistry.class)).isNotNull(); } @@ -129,7 +131,7 @@ public class IntegrationAutoConfigurationTests { @Test public void customizeJmxDomain() { - load("SPRING_JMX_DEFAULT_DOMAIN=org.foo"); + load("spring.jmx.default_domain=org.foo"); MBeanServer mBeanServer = this.context.getBean(MBeanServer.class); assertDomains(mBeanServer, true, "org.foo"); assertDomains(mBeanServer, false, "org.springframework.integration", @@ -209,6 +211,8 @@ public class IntegrationAutoConfigurationTests { if (configs != null) { ctx.register(configs); } + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(ctx, environment); + ConfigurationPropertySources.attach(ctx.getEnvironment()); ctx.register(JmxAutoConfiguration.class, IntegrationAutoConfiguration.class); ctx.refresh(); this.context = ctx; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfigurationTests.java index 6f84cddfa7..3d4032e84c 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfigurationTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -65,13 +65,12 @@ public class XADataSourceAutoConfigurationTests { public void createFromClass() throws Exception { ApplicationContext context = createContext(FromProperties.class, "spring.datasource.xa.data-source-class-name:org.hsqldb.jdbc.pool.JDBCXADataSource", - "spring.datasource.xa.properties.database-name:test"); + "spring.datasource.xa.properties.login-timeout:123"); context.getBean(DataSource.class); MockXADataSourceWrapper wrapper = context.getBean(MockXADataSourceWrapper.class); JDBCXADataSource dataSource = (JDBCXADataSource) wrapper.getXaDataSource(); assertThat(dataSource).isNotNull(); - assertThat(dataSource.getDatabaseName()).isEqualTo("test"); - + assertThat(dataSource.getLoginTimeout()).isEqualTo(123); } private ApplicationContext createContext(Class configuration, String... env) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java index ab05824c9f..e0debaae12 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheStandaloneIntegrationTests.java @@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @DirtiesContext -@SpringBootTest(webEnvironment = WebEnvironment.NONE, properties = { "env.foo=There", +@SpringBootTest(webEnvironment = WebEnvironment.NONE, properties = { "env.FOO=There", "foo=World" }) public class MustacheStandaloneIntegrationTests { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java index 84f5b3fa81..64a616898d 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java @@ -37,6 +37,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerA import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.test.City; import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -131,6 +132,7 @@ public abstract class AbstractJpaAutoConfigurationTests { EnvironmentTestUtils.addEnvironment(context, "spring.jpa.open_in_view:false"); context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, PropertyPlaceholderAutoConfiguration.class, getAutoConfigureClass()); + ConfigurationPropertySources.attach(context.getEnvironment()); context.refresh(); assertThat(getInterceptorBeans(context).length).isEqualTo(0); context.close(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java index 0f26a9c3df..038adcb0ca 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java @@ -38,6 +38,7 @@ import org.springframework.boot.autoconfigure.security.oauth2.resource.OAuth2Res import org.springframework.boot.autoconfigure.security.oauth2.resource.ResourceServerProperties; import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; @@ -244,6 +245,7 @@ public class OAuth2AutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.context, "security.oauth2.client.clientId=client", "security.oauth2.client.grantType=client_credentials"); + ConfigurationPropertySources.attach(this.context.getEnvironment()); this.context.refresh(); OAuth2ClientContext bean = this.context.getBean(OAuth2ClientContext.class); assertThat(bean.getAccessTokenRequest()).isNotNull(); @@ -259,6 +261,7 @@ public class OAuth2AutoConfigurationTests { EnvironmentTestUtils.addEnvironment(this.context, "security.oauth2.client.clientId=client", "security.oauth2.client.grantType=client_credentials"); + ConfigurationPropertySources.attach(this.context.getEnvironment()); this.context.refresh(); // The primary context is fine (not session scoped): OAuth2ClientContext bean = this.context.getBean(OAuth2ClientContext.class); @@ -291,6 +294,7 @@ public class OAuth2AutoConfigurationTests { MinimalSecureWebApplication.class); EnvironmentTestUtils.addEnvironment(this.context, "security.oauth2.resource.jwt.keyValue:DEADBEEF"); + ConfigurationPropertySources.attach(this.context.getEnvironment()); this.context.refresh(); assertThat(countBeans(RESOURCE_SERVER_CONFIG)).isEqualTo(1); assertThat(countBeans(AUTHORIZATION_SERVER_CONFIG)).isEqualTo(0); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java index 8d7648b1c6..af40e7e367 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java @@ -100,8 +100,7 @@ public class ResourceServerTokenServicesConfigurationTests { @Test public void useRemoteTokenServices() { EnvironmentTestUtils.addEnvironment(this.environment, - "security.oauth2.resource.tokenInfoUri:http://example.com", - "security.oauth2.resource.clientId=acme"); + "security.oauth2.resource.tokenInfoUri:http://example.com"); this.context = new SpringApplicationBuilder(ResourceConfiguration.class) .environment(this.environment).web(WebApplicationType.NONE).run(); RemoteTokenServices services = this.context.getBean(RemoteTokenServices.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfigurationTests.java index 74236bfd25..765371d27b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfigurationTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import org.junit.After; import org.junit.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -93,6 +94,7 @@ public class SendGridAutoConfigurationTests { private void loadContext(Class additionalConfiguration, String... environment) { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, environment); + ConfigurationPropertySources.attach(this.context.getEnvironment()); this.context.register(SendGridAutoConfiguration.class); if (additionalConfiguration != null) { this.context.register(additionalConfiguration); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java index d657112719..5eb06616b8 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationTests.java @@ -91,10 +91,9 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat @Test public void springSessionTimeoutIsNotAValidProperty() { + this.thrown.expect(BeanCreationException.class); + this.thrown.expectMessage("Could not bind"); load("spring.session.store-type=hash-map", "spring.session.timeout=3000"); - MapSessionRepository repository = validateSessionRepository( - MapSessionRepository.class); - assertThat(getSessionTimeout(repository)).isNull(); } @Test diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/FacebookAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/FacebookAutoConfigurationTests.java index f2af3edc66..71715e260a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/FacebookAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/FacebookAutoConfigurationTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.social; import org.junit.Test; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.social.facebook.api.Facebook; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; @@ -38,6 +39,7 @@ public class FacebookAutoConfigurationTests extends AbstractSocialAutoConfigurat "spring.social.facebook.appId:12345"); EnvironmentTestUtils.addEnvironment(this.context, "spring.social.facebook.appSecret:secret"); + ConfigurationPropertySources.attach(this.context.getEnvironment()); this.context.register(FacebookAutoConfiguration.class); this.context.register(SocialWebAutoConfiguration.class); this.context.refresh(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/LinkedInAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/LinkedInAutoConfigurationTests.java index eb38524ddd..149b7cad87 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/LinkedInAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/LinkedInAutoConfigurationTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.social; import org.junit.Test; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.social.linkedin.api.LinkedIn; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; @@ -38,6 +39,7 @@ public class LinkedInAutoConfigurationTests extends AbstractSocialAutoConfigurat "spring.social.linkedin.appId:12345"); EnvironmentTestUtils.addEnvironment(this.context, "spring.social.linkedin.appSecret:secret"); + ConfigurationPropertySources.attach(this.context.getEnvironment()); this.context.register(LinkedInAutoConfiguration.class); this.context.register(SocialWebAutoConfiguration.class); this.context.refresh(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/MultiApiAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/MultiApiAutoConfigurationTests.java index a9c0f9ef7e..a15f7e10f7 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/MultiApiAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/MultiApiAutoConfigurationTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.social; import org.junit.Test; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.social.facebook.api.Facebook; import org.springframework.social.linkedin.api.LinkedIn; @@ -111,6 +112,7 @@ public class MultiApiAutoConfigurationTests extends AbstractSocialAutoConfigurat private void setupContext(String... environment) { this.context = new AnnotationConfigWebApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, environment); + ConfigurationPropertySources.attach(this.context.getEnvironment()); this.context.register(TwitterAutoConfiguration.class); this.context.register(FacebookAutoConfiguration.class); this.context.register(LinkedInAutoConfiguration.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/TwitterAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/TwitterAutoConfigurationTests.java index e907f33be4..a83ff69035 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/TwitterAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/social/TwitterAutoConfigurationTests.java @@ -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"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.social; import org.junit.Test; +import org.springframework.boot.context.properties.source.ConfigurationPropertySources; import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.social.twitter.api.Twitter; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; @@ -38,6 +39,7 @@ public class TwitterAutoConfigurationTests extends AbstractSocialAutoConfigurati "spring.social.twitter.appId:12345"); EnvironmentTestUtils.addEnvironment(this.context, "spring.social.twitter.appSecret:secret"); + ConfigurationPropertySources.attach(this.context.getEnvironment()); this.context.register(TwitterAutoConfiguration.class); this.context.register(SocialWebAutoConfiguration.class); this.context.refresh(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfigurationTests.java index 1f413ca602..68c64f49d1 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfigurationTests.java @@ -118,7 +118,7 @@ public class DispatcherServletAutoConfigurationTests { this.context = new AnnotationConfigWebApplicationContext(); this.context.setServletContext(new MockServletContext()); this.context.register(DispatcherServletAutoConfiguration.class); - EnvironmentTestUtils.addEnvironment(this.context, "server.servlet_path:/spring"); + EnvironmentTestUtils.addEnvironment(this.context, "server.servlet.path:/spring"); this.context.refresh(); assertThat(this.context.getBean(DispatcherServlet.class)).isNotNull(); ServletRegistrationBean registration = this.context diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java index a71d48eb3a..206650331a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java @@ -332,7 +332,7 @@ public class WebMvcAutoConfigurationTests { @Test public void overrideDateFormat() throws Exception { - load(AllResources.class, "spring.mvc.dateFormat:dd*MM*yyyy"); + load(AllResources.class, "spring.mvc.date-format:dd*MM*yyyy"); FormattingConversionService cs = this.context .getBean(FormattingConversionService.class); Date date = new DateTime(1988, 6, 25, 20, 30).toDate(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java index 45f5839e59..24b65f027e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java @@ -59,7 +59,7 @@ public class WebServicesAutoConfigurationTests { @Test public void customPathMustBeginWithASlash() { this.thrown.expect(BeanCreationException.class); - this.thrown.expectMessage("Path must start with /"); + this.thrown.expectMessage("Failed to bind properties under 'spring.webservices'"); load(WebServicesAutoConfiguration.class, "spring.webservices.path=invalid"); }