mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Rename @DurationUnit -> @DefaultDurationUnit
Rename `@DurationUnit` to `@DefaultDurationUnit` to make it clearer that it only changes the unit if one isn't specified by the user. Closes gh-11078
This commit is contained in:
parent
6f3ca459ea
commit
64c5e8b6ed
@ -22,7 +22,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.convert.DurationUnit;
|
||||
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
|
||||
|
||||
/**
|
||||
* Configuration properties for MVC endpoints' CORS support.
|
||||
@ -64,7 +64,7 @@ public class CorsEndpointProperties {
|
||||
* How long the response from a pre-flight request can be cached by clients. If a
|
||||
* duration suffix is not specified, seconds will be used.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration maxAge = Duration.ofSeconds(1800);
|
||||
|
||||
public List<String> getAllowedOrigins() {
|
||||
|
@ -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.DurationUnit;
|
||||
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
|
||||
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.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration requestedHeartbeat;
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,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.DurationUnit;
|
||||
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(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.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration heartbeatInterval = Duration.ofSeconds(30);
|
||||
|
||||
/**
|
||||
|
@ -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.DurationUnit;
|
||||
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration queryTimeout;
|
||||
|
||||
public int getFetchSize() {
|
||||
|
@ -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.DurationUnit;
|
||||
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
|
||||
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.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration defaultTimeout;
|
||||
|
||||
/**
|
||||
|
@ -21,7 +21,7 @@ import java.time.temporal.ChronoUnit;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.convert.DurationUnit;
|
||||
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
|
||||
import org.springframework.http.CacheControl;
|
||||
|
||||
/**
|
||||
@ -52,7 +52,7 @@ public class ResourceProperties {
|
||||
* If a duration suffix is not specified, seconds will be used.
|
||||
* Can be overridden by the {@code cache-control} property.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration cachePeriod;
|
||||
|
||||
/**
|
||||
@ -300,7 +300,7 @@ public class ResourceProperties {
|
||||
* Maximum time the response should be cached,
|
||||
* in seconds if no duration suffix is not specified.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration maxAge;
|
||||
|
||||
/**
|
||||
@ -347,21 +347,21 @@ public class ResourceProperties {
|
||||
* Maximum time the response can be served after it becomes stale,
|
||||
* in seconds if no duration suffix is not specified.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(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.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration staleIfError;
|
||||
|
||||
/**
|
||||
* Maximum time the response should be cached by shared caches,
|
||||
* in seconds if no duration suffix is not specified.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration sMaxAge;
|
||||
|
||||
public Duration getMaxAge() {
|
||||
|
@ -32,7 +32,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.DurationUnit;
|
||||
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
|
||||
import org.springframework.boot.web.server.Compression;
|
||||
import org.springframework.boot.web.server.Http2;
|
||||
import org.springframework.boot.web.server.Ssl;
|
||||
@ -340,7 +340,7 @@ public class ServerProperties {
|
||||
/**
|
||||
* Session timeout. If a duration suffix is not specified, seconds will be used.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration timeout;
|
||||
|
||||
/**
|
||||
@ -434,7 +434,7 @@ public class ServerProperties {
|
||||
/**
|
||||
* Maximum age of the session cookie.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration maxAge;
|
||||
|
||||
public String getName() {
|
||||
@ -570,7 +570,7 @@ public class ServerProperties {
|
||||
* Delay between the invocation of backgroundProcess methods. If a duration suffix
|
||||
* is not specified, seconds will be used.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration backgroundProcessorDelay = Duration.ofSeconds(30);
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ import java.time.temporal.ChronoUnit;
|
||||
@Target(ElementType.FIELD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface DurationUnit {
|
||||
public @interface DefaultDurationUnit {
|
||||
|
||||
/**
|
||||
* The duration unit to use if one is not specified.
|
@ -77,10 +77,10 @@ class DurationConverter implements GenericConverter {
|
||||
return null;
|
||||
}
|
||||
return toDuration(source.toString(),
|
||||
targetType.getAnnotation(DurationUnit.class));
|
||||
targetType.getAnnotation(DefaultDurationUnit.class));
|
||||
}
|
||||
|
||||
private Duration toDuration(String source, DurationUnit defaultUnit) {
|
||||
private Duration toDuration(String source, DefaultDurationUnit defaultUnit) {
|
||||
try {
|
||||
if (!StringUtils.hasLength(source)) {
|
||||
return null;
|
||||
@ -100,7 +100,7 @@ class DurationConverter implements GenericConverter {
|
||||
}
|
||||
}
|
||||
|
||||
private ChronoUnit getUnit(String value, DurationUnit defaultUnit) {
|
||||
private ChronoUnit getUnit(String value, DefaultDurationUnit defaultUnit) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return (defaultUnit != null ? defaultUnit.value() : ChronoUnit.MILLIS);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.bind.convert.DurationUnit;
|
||||
import org.springframework.boot.context.properties.bind.convert.DefaultDurationUnit;
|
||||
|
||||
/**
|
||||
* Subset of Narayana properties which can be configured via Spring configuration. Use
|
||||
@ -59,21 +59,21 @@ public class NarayanaProperties {
|
||||
/**
|
||||
* Transaction timeout. If a duration suffix is not specified, seconds will be used.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration defaultTimeout = Duration.ofSeconds(60);
|
||||
|
||||
/**
|
||||
* Interval in which periodic recovery scans are performed. If a duration suffix is
|
||||
* not specified, seconds will be used.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration periodicRecoveryPeriod = Duration.ofSeconds(120);
|
||||
|
||||
/**
|
||||
* Back off period between first and second phases of the recovery scan. If a duration
|
||||
* suffix is not specified, seconds will be used.
|
||||
*/
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
@DefaultDurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration recoveryBackoffPeriod = Duration.ofSeconds(10);
|
||||
|
||||
/**
|
||||
|
@ -138,9 +138,9 @@ public class DurationConverterTests {
|
||||
|
||||
private Duration convert(String source, ChronoUnit defaultUnit) {
|
||||
TypeDescriptor targetType = mock(TypeDescriptor.class);
|
||||
DurationUnit annotation = AnnotationUtils.synthesizeAnnotation(
|
||||
Collections.singletonMap("value", defaultUnit), DurationUnit.class, null);
|
||||
given(targetType.getAnnotation(DurationUnit.class)).willReturn(annotation);
|
||||
DefaultDurationUnit annotation = AnnotationUtils.synthesizeAnnotation(
|
||||
Collections.singletonMap("value", defaultUnit), DefaultDurationUnit.class, null);
|
||||
given(targetType.getAnnotation(DefaultDurationUnit.class)).willReturn(annotation);
|
||||
return (Duration) this.converter.convert(source, TypeDescriptor.forObject(source),
|
||||
targetType);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user