Add ApplicationConversionService and fix binder

Create a new `ApplicationConversionService` similar in design to the
DefaultFormattingConversionService from Spring Framework. The new
conversion service provides a central place for custom conversion logic
supported by Spring Boot.

Also replace the `BindingConversionService` with an internal
`BindConverter` class that now invokes the `SimpleTypeConverter`
directly. Binding for `@ConfigurationProperties` has been updated so
that any custom property editors registered with the BeanFactory can
be used.

Fixes gh-12095
This commit is contained in:
Phillip Webb
2018-02-17 08:21:49 -08:00
parent 61f44179cb
commit 20109e27be
75 changed files with 2706 additions and 1354 deletions

View File

@@ -24,7 +24,7 @@ import java.util.List;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -80,7 +80,7 @@ public class RabbitProperties {
* Requested heartbeat timeout; zero for none. If a duration suffix is not specified,
* seconds will be used.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration requestedHeartbeat;
/**

View File

@@ -31,7 +31,7 @@ import com.datastax.driver.core.policies.ReconnectionPolicy;
import com.datastax.driver.core.policies.RetryPolicy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.boot.convert.DurationUnit;
/**
* Configuration properties for Cassandra.
@@ -283,7 +283,7 @@ public class CassandraProperties {
* Idle timeout before an idle connection is removed. If a duration suffix is not
* specified, seconds will be used.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration idleTimeout = Duration.ofSeconds(120);
/**
@@ -296,7 +296,7 @@ public class CassandraProperties {
* sure it's still alive. If a duration suffix is not specified, seconds will be
* used.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration heartbeatInterval = Duration.ofSeconds(30);
/**

View File

@@ -20,7 +20,7 @@ import java.time.Duration;
import java.time.temporal.ChronoUnit;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.boot.convert.DurationUnit;
/**
* Configuration properties for JDBC.
@@ -58,7 +58,7 @@ public class JdbcProperties {
* Query timeout. Default is to use the JDBC driver's default configuration. If a
* duration suffix is not specified, seconds will be used.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration queryTimeout;
public int getFetchSize() {

View File

@@ -33,7 +33,7 @@ import org.apache.kafka.common.serialization.StringDeserializer;
import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.core.io.Resource;
import org.springframework.kafka.listener.AbstractMessageListenerContainer.AckMode;
import org.springframework.kafka.security.jaas.KafkaJaasLoginModuleInitializer;
@@ -840,7 +840,7 @@ public class KafkaProperties {
* Time between checks for non-responsive consumers. If a duration suffix is not
* specified, seconds will be used.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration monitorInterval;
/**

View File

@@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.Delimiter;
import org.springframework.boot.convert.Delimiter;
import org.springframework.core.io.Resource;
/**

View File

@@ -22,7 +22,7 @@ import java.util.Map;
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Provider;
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties.Registration;
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.boot.context.properties.bind.convert.BinderConversionService;
import org.springframework.boot.convert.ApplicationConversionService;
import org.springframework.core.convert.ConversionException;
import org.springframework.security.config.oauth2.client.CommonOAuth2Provider;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
@@ -107,7 +107,7 @@ final class OAuth2ClientPropertiesRegistrationAdapter {
private static CommonOAuth2Provider getCommonProvider(String providerId) {
try {
return new BinderConversionService(null).convert(providerId,
return ApplicationConversionService.getSharedInstance().convert(providerId,
CommonOAuth2Provider.class);
}
catch (ConversionException ex) {

View File

@@ -20,7 +20,7 @@ import java.time.Duration;
import java.time.temporal.ChronoUnit;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
/**
@@ -39,7 +39,7 @@ public class TransactionProperties implements
* Default transaction timeout. If a duration suffix is not specified, seconds will be
* used.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration defaultTimeout;
/**

View File

@@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.http.CacheControl;
/**
@@ -277,7 +277,7 @@ public class ResourceProperties {
* suffix is not specified, seconds will be used. Can be overridden by the
* 'spring.resources.cache.cachecontrol' properties.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration period;
/**
@@ -307,7 +307,7 @@ public class ResourceProperties {
* Maximum time the response should be cached, in seconds if no duration
* suffix is not specified.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration maxAge;
/**
@@ -354,21 +354,21 @@ public class ResourceProperties {
* Maximum time the response can be served after it becomes stale, in seconds
* if no duration suffix is not specified.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration staleWhileRevalidate;
/**
* Maximum time the response may be used when errors are encountered, in
* seconds if no duration suffix is not specified.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration staleIfError;
/**
* Maximum time the response should be cached by shared caches, in seconds if
* no duration suffix is not specified.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration sMaxAge;
public Duration getMaxAge() {

View File

@@ -31,7 +31,7 @@ import java.util.TimeZone;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
import org.springframework.boot.convert.DurationUnit;
import org.springframework.boot.web.server.Compression;
import org.springframework.boot.web.server.Http2;
import org.springframework.boot.web.server.Ssl;
@@ -373,7 +373,7 @@ public class ServerProperties {
* Delay between the invocation of backgroundProcess methods. If a duration suffix
* is not specified, seconds will be used.
*/
@DefaultDurationUnit(ChronoUnit.SECONDS)
@DurationUnit(ChronoUnit.SECONDS)
private Duration backgroundProcessorDelay = Duration.ofSeconds(30);
/**