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