Commit 69ab2e46 authored by Madhura Bhave's avatar Madhura Bhave Committed by Phillip Webb

Use new configuration properties in autoconfigure

Update `spring-boot-autoconfigure` to use the new configuration
properties support.

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