Update configuration properties to use Duration
Update appropriate configuration properties to use the `Duration` type, rather than an ad-hoc mix of milliseconds or seconds. Configuration properties can now be defined in a consistent and readable way. For example `server.session.timeout=5m`. Properties that were previously declared using seconds are annotated with `@DurationUnit` to ensure a smooth upgrade experience. For example `server.session.timeout=20` continues to mean 20 seconds. Fixes gh-11080
This commit is contained in:
@@ -100,7 +100,7 @@ public abstract class AbstractRabbitListenerContainerFactoryConfigurer<T extends
|
||||
factory.setDefaultRequeueRejected(configuration.getDefaultRequeueRejected());
|
||||
}
|
||||
if (configuration.getIdleEventInterval() != null) {
|
||||
factory.setIdleEventInterval(configuration.getIdleEventInterval());
|
||||
factory.setIdleEventInterval(configuration.getIdleEventInterval().toMillis());
|
||||
}
|
||||
ListenerRetry retryConfig = configuration.getRetry();
|
||||
if (retryConfig.isEnabled()) {
|
||||
|
||||
@@ -105,7 +105,8 @@ public class RabbitAutoConfiguration {
|
||||
factory.setVirtualHost(config.determineVirtualHost());
|
||||
}
|
||||
if (config.getRequestedHeartbeat() != null) {
|
||||
factory.setRequestedHeartbeat(config.getRequestedHeartbeat());
|
||||
factory.setRequestedHeartbeat(
|
||||
(int) config.getRequestedHeartbeat().getSeconds());
|
||||
}
|
||||
RabbitProperties.Ssl ssl = config.getSsl();
|
||||
if (ssl.isEnabled()) {
|
||||
@@ -121,7 +122,8 @@ public class RabbitAutoConfiguration {
|
||||
factory.setTrustStorePassphrase(ssl.getTrustStorePassword());
|
||||
}
|
||||
if (config.getConnectionTimeout() != null) {
|
||||
factory.setConnectionTimeout(config.getConnectionTimeout());
|
||||
factory.setConnectionTimeout(
|
||||
(int) config.getConnectionTimeout().toMillis());
|
||||
}
|
||||
factory.afterPropertiesSet();
|
||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.amqp;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
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.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -74,9 +77,11 @@ public class RabbitProperties {
|
||||
private String addresses;
|
||||
|
||||
/**
|
||||
* Requested heartbeat timeout, in seconds; zero for none.
|
||||
* Requested heartbeat timeout; zero for none. If a duration suffix is not specified,
|
||||
* seconds will be used.
|
||||
*/
|
||||
private Integer requestedHeartbeat;
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration requestedHeartbeat;
|
||||
|
||||
/**
|
||||
* Enable publisher confirms.
|
||||
@@ -89,9 +94,9 @@ public class RabbitProperties {
|
||||
private boolean publisherReturns;
|
||||
|
||||
/**
|
||||
* Connection timeout, in milliseconds; zero for infinite.
|
||||
* Connection timeout; zero for infinite.
|
||||
*/
|
||||
private Integer connectionTimeout;
|
||||
private Duration connectionTimeout;
|
||||
|
||||
/**
|
||||
* Cache configuration.
|
||||
@@ -258,11 +263,11 @@ public class RabbitProperties {
|
||||
this.virtualHost = ("".equals(virtualHost) ? "/" : virtualHost);
|
||||
}
|
||||
|
||||
public Integer getRequestedHeartbeat() {
|
||||
public Duration getRequestedHeartbeat() {
|
||||
return this.requestedHeartbeat;
|
||||
}
|
||||
|
||||
public void setRequestedHeartbeat(Integer requestedHeartbeat) {
|
||||
public void setRequestedHeartbeat(Duration requestedHeartbeat) {
|
||||
this.requestedHeartbeat = requestedHeartbeat;
|
||||
}
|
||||
|
||||
@@ -282,11 +287,11 @@ public class RabbitProperties {
|
||||
this.publisherReturns = publisherReturns;
|
||||
}
|
||||
|
||||
public Integer getConnectionTimeout() {
|
||||
public Duration getConnectionTimeout() {
|
||||
return this.connectionTimeout;
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(Integer connectionTimeout) {
|
||||
public void setConnectionTimeout(Duration connectionTimeout) {
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
}
|
||||
|
||||
@@ -557,9 +562,9 @@ public class RabbitProperties {
|
||||
private Boolean defaultRequeueRejected;
|
||||
|
||||
/**
|
||||
* How often idle container events should be published in milliseconds.
|
||||
* How often idle container events should be published.
|
||||
*/
|
||||
private Long idleEventInterval;
|
||||
private Duration idleEventInterval;
|
||||
|
||||
/**
|
||||
* Optional properties for a retry interceptor.
|
||||
@@ -598,11 +603,11 @@ public class RabbitProperties {
|
||||
this.defaultRequeueRejected = defaultRequeueRejected;
|
||||
}
|
||||
|
||||
public Long getIdleEventInterval() {
|
||||
public Duration getIdleEventInterval() {
|
||||
return this.idleEventInterval;
|
||||
}
|
||||
|
||||
public void setIdleEventInterval(Long idleEventInterval) {
|
||||
public void setIdleEventInterval(Duration idleEventInterval) {
|
||||
this.idleEventInterval = idleEventInterval;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.cache;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -141,24 +141,16 @@ public class CacheProperties {
|
||||
public static class Couchbase {
|
||||
|
||||
/**
|
||||
* Entry expiration in milliseconds. By default the entries never expire. Note
|
||||
* that this value is ultimately converted to seconds.
|
||||
* Entry expiration. By default the entries never expire. Note that this value is
|
||||
* ultimately converted to seconds.
|
||||
*/
|
||||
private int expiration;
|
||||
private Duration expiration;
|
||||
|
||||
public int getExpiration() {
|
||||
public Duration getExpiration() {
|
||||
return this.expiration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the expiration in seconds.
|
||||
* @return the expiration in seconds
|
||||
*/
|
||||
public int getExpirationSeconds() {
|
||||
return (int) TimeUnit.MILLISECONDS.toSeconds(this.expiration);
|
||||
}
|
||||
|
||||
public void setExpiration(int expiration) {
|
||||
public void setExpiration(Duration expiration) {
|
||||
this.expiration = expiration;
|
||||
}
|
||||
|
||||
@@ -246,9 +238,9 @@ public class CacheProperties {
|
||||
public static class Redis {
|
||||
|
||||
/**
|
||||
* Entry expiration in milliseconds. By default the entries never expire.
|
||||
* Entry expiration. By default the entries never expire.
|
||||
*/
|
||||
private long timeToLive = 0;
|
||||
private Duration timeToLive;
|
||||
|
||||
/**
|
||||
* Allow caching null values.
|
||||
@@ -265,11 +257,11 @@ public class CacheProperties {
|
||||
*/
|
||||
private boolean useKeyPrefix = true;
|
||||
|
||||
public long getTimeToLive() {
|
||||
public Duration getTimeToLive() {
|
||||
return this.timeToLive;
|
||||
}
|
||||
|
||||
public void setTimeToLive(long timeToLive) {
|
||||
public void setTimeToLive(Duration timeToLive) {
|
||||
this.timeToLive = timeToLive;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.cache;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
@@ -59,11 +60,13 @@ public class CouchbaseCacheConfiguration {
|
||||
@Bean
|
||||
public CouchbaseCacheManager cacheManager() {
|
||||
List<String> cacheNames = this.cacheProperties.getCacheNames();
|
||||
CouchbaseCacheManager cacheManager = new CouchbaseCacheManager(
|
||||
CacheBuilder.newInstance(this.bucket)
|
||||
.withExpiration(this.cacheProperties.getCouchbase()
|
||||
.getExpirationSeconds()),
|
||||
cacheNames.toArray(new String[cacheNames.size()]));
|
||||
CacheBuilder builder = CacheBuilder.newInstance(this.bucket);
|
||||
Duration expiration = this.cacheProperties.getCouchbase().getExpiration();
|
||||
if (expiration != null) {
|
||||
builder = builder.withExpiration((int) expiration.getSeconds());
|
||||
}
|
||||
String[] names = cacheNames.toArray(new String[cacheNames.size()]);
|
||||
CouchbaseCacheManager cacheManager = new CouchbaseCacheManager(builder, names);
|
||||
return this.customizers.customize(cacheManager);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.cache;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
@@ -73,7 +72,9 @@ class RedisCacheConfiguration {
|
||||
Redis redisProperties = this.cacheProperties.getRedis();
|
||||
org.springframework.data.redis.cache.RedisCacheConfiguration config = org.springframework.data.redis.cache.RedisCacheConfiguration
|
||||
.defaultCacheConfig();
|
||||
config = config.entryTtl(Duration.ofMillis(redisProperties.getTimeToLive()));
|
||||
if (redisProperties.getTimeToLive() != null) {
|
||||
config = config.entryTtl(redisProperties.getTimeToLive());
|
||||
}
|
||||
if (redisProperties.getKeyPrefix() != null) {
|
||||
config = config.prefixKeysWith(redisProperties.getKeyPrefix());
|
||||
}
|
||||
|
||||
@@ -125,17 +125,30 @@ public class CassandraAutoConfiguration {
|
||||
|
||||
private SocketOptions getSocketOptions() {
|
||||
SocketOptions options = new SocketOptions();
|
||||
options.setConnectTimeoutMillis(this.properties.getConnectTimeoutMillis());
|
||||
options.setReadTimeoutMillis(this.properties.getReadTimeoutMillis());
|
||||
if (this.properties.getConnectTimeout() != null) {
|
||||
options.setConnectTimeoutMillis(
|
||||
(int) this.properties.getConnectTimeout().toMillis());
|
||||
}
|
||||
if (this.properties.getReadTimeout() != null) {
|
||||
options.setReadTimeoutMillis(
|
||||
(int) this.properties.getReadTimeout().toMillis());
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
private PoolingOptions getPoolingOptions() {
|
||||
CassandraProperties.Pool pool = this.properties.getPool();
|
||||
PoolingOptions options = new PoolingOptions();
|
||||
options.setIdleTimeoutSeconds(pool.getIdleTimeout());
|
||||
options.setPoolTimeoutMillis(pool.getPoolTimeout());
|
||||
options.setHeartbeatIntervalSeconds(pool.getHeartbeatInterval());
|
||||
if (pool.getIdleTimeout() != null) {
|
||||
options.setIdleTimeoutSeconds((int) pool.getIdleTimeout().getSeconds());
|
||||
}
|
||||
if (pool.getPoolTimeout() != null) {
|
||||
options.setPoolTimeoutMillis((int) pool.getPoolTimeout().toMillis());
|
||||
}
|
||||
if (pool.getHeartbeatInterval() != null) {
|
||||
options.setHeartbeatIntervalSeconds(
|
||||
(int) pool.getHeartbeatInterval().getSeconds());
|
||||
}
|
||||
options.setMaxQueueSize(pool.getMaxQueueSize());
|
||||
return options;
|
||||
}
|
||||
|
||||
@@ -16,16 +16,19 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.cassandra;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import com.datastax.driver.core.ConsistencyLevel;
|
||||
import com.datastax.driver.core.ProtocolOptions;
|
||||
import com.datastax.driver.core.ProtocolOptions.Compression;
|
||||
import com.datastax.driver.core.QueryOptions;
|
||||
import com.datastax.driver.core.SocketOptions;
|
||||
import com.datastax.driver.core.policies.LoadBalancingPolicy;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Configuration properties for Cassandra.
|
||||
@@ -107,12 +110,12 @@ public class CassandraProperties {
|
||||
/**
|
||||
* Socket option: connection time out.
|
||||
*/
|
||||
private int connectTimeoutMillis = SocketOptions.DEFAULT_CONNECT_TIMEOUT_MILLIS;
|
||||
private Duration connectTimeout;
|
||||
|
||||
/**
|
||||
* Socket option: read time out.
|
||||
*/
|
||||
private int readTimeoutMillis = SocketOptions.DEFAULT_READ_TIMEOUT_MILLIS;
|
||||
private Duration readTimeout;
|
||||
|
||||
/**
|
||||
* Schema action to take at startup.
|
||||
@@ -235,20 +238,20 @@ public class CassandraProperties {
|
||||
this.retryPolicy = retryPolicy;
|
||||
}
|
||||
|
||||
public int getConnectTimeoutMillis() {
|
||||
return this.connectTimeoutMillis;
|
||||
public Duration getConnectTimeout() {
|
||||
return this.connectTimeout;
|
||||
}
|
||||
|
||||
public void setConnectTimeoutMillis(int connectTimeoutMillis) {
|
||||
this.connectTimeoutMillis = connectTimeoutMillis;
|
||||
public void setConnectTimeout(Duration connectTimeout) {
|
||||
this.connectTimeout = connectTimeout;
|
||||
}
|
||||
|
||||
public int getReadTimeoutMillis() {
|
||||
return this.readTimeoutMillis;
|
||||
public Duration getReadTimeout() {
|
||||
return this.readTimeout;
|
||||
}
|
||||
|
||||
public void setReadTimeoutMillis(int readTimeoutMillis) {
|
||||
this.readTimeoutMillis = readTimeoutMillis;
|
||||
public void setReadTimeout(Duration readTimeout) {
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
public boolean isSsl() {
|
||||
@@ -277,48 +280,51 @@ public class CassandraProperties {
|
||||
public static class Pool {
|
||||
|
||||
/**
|
||||
* Idle timeout (in seconds) before an idle connection is removed.
|
||||
* Idle timeout before an idle connection is removed. If a duration suffix is not
|
||||
* specified, seconds will be used.
|
||||
*/
|
||||
private int idleTimeout = 120;
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration idleTimeout = Duration.ofSeconds(120);
|
||||
|
||||
/**
|
||||
* Pool timeout (in milliseconds) when trying to acquire a connection from a
|
||||
* host's pool.
|
||||
* Pool timeout when trying to acquire a connection from a host's pool.
|
||||
*/
|
||||
private int poolTimeout = 5000;
|
||||
private Duration poolTimeout = Duration.ofMillis(5000);
|
||||
|
||||
/**
|
||||
* Heartbeat interval (in seconds) after which a message is sent on an idle
|
||||
* connection to make sure it's still alive.
|
||||
* Heartbeat interval after which a message is sent on an idle connection to make
|
||||
* sure it's still alive. If a duration suffix is not specified, seconds will be
|
||||
* used.
|
||||
*/
|
||||
private int heartbeatInterval = 30;
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration heartbeatInterval = Duration.ofSeconds(30);
|
||||
|
||||
/**
|
||||
* Maximum number of requests that get enqueued if no connection is available.
|
||||
*/
|
||||
private int maxQueueSize = 256;
|
||||
|
||||
public int getIdleTimeout() {
|
||||
public Duration getIdleTimeout() {
|
||||
return this.idleTimeout;
|
||||
}
|
||||
|
||||
public void setIdleTimeout(int idleTimeout) {
|
||||
public void setIdleTimeout(Duration idleTimeout) {
|
||||
this.idleTimeout = idleTimeout;
|
||||
}
|
||||
|
||||
public int getPoolTimeout() {
|
||||
public Duration getPoolTimeout() {
|
||||
return this.poolTimeout;
|
||||
}
|
||||
|
||||
public void setPoolTimeout(int poolTimeout) {
|
||||
public void setPoolTimeout(Duration poolTimeout) {
|
||||
this.poolTimeout = poolTimeout;
|
||||
}
|
||||
|
||||
public int getHeartbeatInterval() {
|
||||
public Duration getHeartbeatInterval() {
|
||||
return this.heartbeatInterval;
|
||||
}
|
||||
|
||||
public void setHeartbeatInterval(int heartbeatInterval) {
|
||||
public void setHeartbeatInterval(Duration heartbeatInterval) {
|
||||
this.heartbeatInterval = heartbeatInterval;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.context;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
|
||||
@@ -73,7 +75,9 @@ public class MessageSourceAutoConfiguration {
|
||||
messageSource.setDefaultEncoding(properties.getEncoding().name());
|
||||
}
|
||||
messageSource.setFallbackToSystemLocale(properties.isFallbackToSystemLocale());
|
||||
messageSource.setCacheSeconds(properties.getCacheSeconds());
|
||||
Duration cacheDuration = properties.getCacheDuration();
|
||||
messageSource.setCacheSeconds(
|
||||
cacheDuration == null ? -1 : (int) cacheDuration.getSeconds());
|
||||
messageSource.setAlwaysUseMessageFormat(properties.isAlwaysUseMessageFormat());
|
||||
messageSource.setUseCodeAsDefaultMessage(properties.isUseCodeAsDefaultMessage());
|
||||
return messageSource;
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.context;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
|
||||
/**
|
||||
* Configuration properties for Message Source.
|
||||
@@ -41,10 +42,10 @@ public class MessageSourceProperties {
|
||||
private Charset encoding = StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles
|
||||
* Loaded resource bundle files cache expiration, in seconds. When not set, bundles
|
||||
* are cached forever.
|
||||
*/
|
||||
private int cacheSeconds = -1;
|
||||
private Duration cacheDuration;
|
||||
|
||||
/**
|
||||
* Set whether to fall back to the system Locale if no files for a specific Locale
|
||||
@@ -81,12 +82,12 @@ public class MessageSourceProperties {
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
public int getCacheSeconds() {
|
||||
return this.cacheSeconds;
|
||||
public Duration getCacheDuration() {
|
||||
return this.cacheDuration;
|
||||
}
|
||||
|
||||
public void setCacheSeconds(int cacheSeconds) {
|
||||
this.cacheSeconds = cacheSeconds;
|
||||
public void setCacheDuration(Duration cacheDuration) {
|
||||
this.cacheDuration = cacheDuration;
|
||||
}
|
||||
|
||||
public boolean isFallbackToSystemLocale() {
|
||||
|
||||
@@ -98,13 +98,26 @@ public class CouchbaseAutoConfiguration {
|
||||
CouchbaseProperties.Endpoints endpoints = properties.getEnv().getEndpoints();
|
||||
CouchbaseProperties.Timeouts timeouts = properties.getEnv().getTimeouts();
|
||||
DefaultCouchbaseEnvironment.Builder builder = DefaultCouchbaseEnvironment
|
||||
.builder().connectTimeout(timeouts.getConnect())
|
||||
.kvEndpoints(endpoints.getKeyValue())
|
||||
.kvTimeout(timeouts.getKeyValue())
|
||||
.queryEndpoints(endpoints.getQuery())
|
||||
.queryTimeout(timeouts.getQuery()).viewEndpoints(endpoints.getView())
|
||||
.socketConnectTimeout(timeouts.getSocketConnect())
|
||||
.viewTimeout(timeouts.getView());
|
||||
.builder();
|
||||
if (timeouts.getConnect() != null) {
|
||||
builder = builder.connectTimeout(timeouts.getConnect().toMillis());
|
||||
}
|
||||
builder = builder.kvEndpoints(endpoints.getKeyValue());
|
||||
if (timeouts.getKeyValue() != null) {
|
||||
builder = builder.kvTimeout(timeouts.getKeyValue().toMillis());
|
||||
}
|
||||
builder = builder.queryEndpoints(endpoints.getQuery());
|
||||
if (timeouts.getQuery() != null) {
|
||||
builder = builder.queryTimeout(timeouts.getQuery().toMillis())
|
||||
.viewEndpoints(endpoints.getView());
|
||||
}
|
||||
if (timeouts.getSocketConnect() != null) {
|
||||
builder = builder.socketConnectTimeout(
|
||||
(int) timeouts.getSocketConnect().toMillis());
|
||||
}
|
||||
if (timeouts.getView() != null) {
|
||||
builder = builder.viewTimeout(timeouts.getView().toMillis());
|
||||
}
|
||||
CouchbaseProperties.Ssl ssl = properties.getEnv().getSsl();
|
||||
if (ssl.getEnabled()) {
|
||||
builder.sslEnabled(true);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.couchbase;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -199,67 +200,67 @@ public class CouchbaseProperties {
|
||||
public static class Timeouts {
|
||||
|
||||
/**
|
||||
* Bucket connections timeout in milliseconds.
|
||||
* Bucket connections timeout.
|
||||
*/
|
||||
private long connect = 5000;
|
||||
private Duration connect = Duration.ofMillis(5000);
|
||||
|
||||
/**
|
||||
* Blocking operations performed on a specific key timeout in milliseconds.
|
||||
* Blocking operations performed on a specific key timeout.
|
||||
*/
|
||||
private long keyValue = 2500;
|
||||
private Duration keyValue = Duration.ofMillis(2500);
|
||||
|
||||
/**
|
||||
* N1QL query operations timeout in milliseconds.
|
||||
* N1QL query operations timeout.
|
||||
*/
|
||||
private long query = 7500;
|
||||
private Duration query = Duration.ofMillis(7500);
|
||||
|
||||
/**
|
||||
* Socket connect connections timeout in milliseconds.
|
||||
* Socket connect connections timeout.
|
||||
*/
|
||||
private int socketConnect = 1000;
|
||||
private Duration socketConnect = Duration.ofMillis(1000);
|
||||
|
||||
/**
|
||||
* Regular and geospatial view operations timeout in milliseconds.
|
||||
* Regular and geospatial view operations timeout.
|
||||
*/
|
||||
private long view = 7500;
|
||||
private Duration view = Duration.ofMillis(7500);
|
||||
|
||||
public long getConnect() {
|
||||
public Duration getConnect() {
|
||||
return this.connect;
|
||||
}
|
||||
|
||||
public void setConnect(long connect) {
|
||||
public void setConnect(Duration connect) {
|
||||
this.connect = connect;
|
||||
}
|
||||
|
||||
public long getKeyValue() {
|
||||
public Duration getKeyValue() {
|
||||
return this.keyValue;
|
||||
}
|
||||
|
||||
public void setKeyValue(long keyValue) {
|
||||
public void setKeyValue(Duration keyValue) {
|
||||
this.keyValue = keyValue;
|
||||
}
|
||||
|
||||
public long getQuery() {
|
||||
public Duration getQuery() {
|
||||
return this.query;
|
||||
}
|
||||
|
||||
public void setQuery(long query) {
|
||||
public void setQuery(Duration query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
public int getSocketConnect() {
|
||||
public Duration getSocketConnect() {
|
||||
return this.socketConnect;
|
||||
}
|
||||
|
||||
public void setSocketConnect(int socketConnect) {
|
||||
public void setSocketConnect(Duration socketConnect) {
|
||||
this.socketConnect = socketConnect;
|
||||
}
|
||||
|
||||
public long getView() {
|
||||
public Duration getView() {
|
||||
return this.view;
|
||||
}
|
||||
|
||||
public void setView(long view) {
|
||||
public void setView(Duration view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
|
||||
@@ -100,8 +100,8 @@ class JedisConnectionConfiguration extends RedisConnectionConfiguration {
|
||||
if (this.properties.isSsl()) {
|
||||
builder.useSsl();
|
||||
}
|
||||
if (this.properties.getTimeout() != 0) {
|
||||
Duration timeout = Duration.ofMillis(this.properties.getTimeout());
|
||||
if (this.properties.getTimeout() != null) {
|
||||
Duration timeout = this.properties.getTimeout();
|
||||
builder.readTimeout(timeout).connectTimeout(timeout);
|
||||
}
|
||||
return builder;
|
||||
@@ -117,7 +117,9 @@ class JedisConnectionConfiguration extends RedisConnectionConfiguration {
|
||||
config.setMaxTotal(pool.getMaxActive());
|
||||
config.setMaxIdle(pool.getMaxIdle());
|
||||
config.setMinIdle(pool.getMinIdle());
|
||||
config.setMaxWaitMillis(pool.getMaxWait());
|
||||
if (pool.getMaxWait() != null) {
|
||||
config.setMaxWaitMillis(pool.getMaxWait().toMillis());
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.boot.autoconfigure.data.redis;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -116,14 +115,15 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
|
||||
if (this.properties.isSsl()) {
|
||||
builder.useSsl();
|
||||
}
|
||||
if (this.properties.getTimeout() != 0) {
|
||||
builder.commandTimeout(Duration.ofMillis(this.properties.getTimeout()));
|
||||
if (this.properties.getTimeout() != null) {
|
||||
builder.commandTimeout(this.properties.getTimeout());
|
||||
}
|
||||
if (this.properties.getLettuce() != null) {
|
||||
RedisProperties.Lettuce lettuce = this.properties.getLettuce();
|
||||
if (lettuce.getShutdownTimeout() >= 0) {
|
||||
builder.shutdownTimeout(Duration
|
||||
.ofMillis(this.properties.getLettuce().getShutdownTimeout()));
|
||||
if (lettuce.getShutdownTimeout() != null
|
||||
&& !lettuce.getShutdownTimeout().isZero()) {
|
||||
builder.shutdownTimeout(
|
||||
this.properties.getLettuce().getShutdownTimeout());
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
@@ -159,7 +159,9 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
|
||||
config.setMaxTotal(properties.getMaxActive());
|
||||
config.setMaxIdle(properties.getMaxIdle());
|
||||
config.setMinIdle(properties.getMinIdle());
|
||||
config.setMaxWaitMillis(properties.getMaxWait());
|
||||
if (properties.getMaxWait() != null) {
|
||||
config.setMaxWaitMillis(properties.getMaxWait().toMillis());
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.data.redis;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@@ -64,9 +65,9 @@ public class RedisProperties {
|
||||
private boolean ssl;
|
||||
|
||||
/**
|
||||
* Connection timeout in milliseconds.
|
||||
* Connection timeout.
|
||||
*/
|
||||
private int timeout;
|
||||
private Duration timeout;
|
||||
|
||||
private Sentinel sentinel;
|
||||
|
||||
@@ -124,11 +125,11 @@ public class RedisProperties {
|
||||
this.ssl = ssl;
|
||||
}
|
||||
|
||||
public void setTimeout(int timeout) {
|
||||
public void setTimeout(Duration timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
public Duration getTimeout() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
@@ -180,11 +181,11 @@ public class RedisProperties {
|
||||
private int maxActive = 8;
|
||||
|
||||
/**
|
||||
* Maximum amount of time (in milliseconds) a connection allocation should block
|
||||
* before throwing an exception when the pool is exhausted. Use a negative value
|
||||
* to block indefinitely.
|
||||
* Maximum amount of time a connection allocation should block before throwing an
|
||||
* exception when the pool is exhausted. Use a negative value to block
|
||||
* indefinitely.
|
||||
*/
|
||||
private int maxWait = -1;
|
||||
private Duration maxWait = Duration.ofMillis(-1);
|
||||
|
||||
public int getMaxIdle() {
|
||||
return this.maxIdle;
|
||||
@@ -210,11 +211,11 @@ public class RedisProperties {
|
||||
this.maxActive = maxActive;
|
||||
}
|
||||
|
||||
public int getMaxWait() {
|
||||
public Duration getMaxWait() {
|
||||
return this.maxWait;
|
||||
}
|
||||
|
||||
public void setMaxWait(int maxWait) {
|
||||
public void setMaxWait(Duration maxWait) {
|
||||
this.maxWait = maxWait;
|
||||
}
|
||||
|
||||
@@ -314,20 +315,20 @@ public class RedisProperties {
|
||||
public static class Lettuce {
|
||||
|
||||
/**
|
||||
* Shutdown timeout in milliseconds.
|
||||
* Shutdown timeout.
|
||||
*/
|
||||
private int shutdownTimeout = 100;
|
||||
private Duration shutdownTimeout = Duration.ofMillis(100);
|
||||
|
||||
/**
|
||||
* Lettuce pool configuration.
|
||||
*/
|
||||
private Pool pool;
|
||||
|
||||
public int getShutdownTimeout() {
|
||||
public Duration getShutdownTimeout() {
|
||||
return this.shutdownTimeout;
|
||||
}
|
||||
|
||||
public void setShutdownTimeout(int shutdownTimeout) {
|
||||
public void setShutdownTimeout(Duration shutdownTimeout) {
|
||||
this.shutdownTimeout = shutdownTimeout;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,8 +87,12 @@ public class JestAutoConfiguration {
|
||||
builder.gson(gson);
|
||||
}
|
||||
builder.multiThreaded(this.properties.isMultiThreaded());
|
||||
builder.connTimeout(this.properties.getConnectionTimeout())
|
||||
.readTimeout(this.properties.getReadTimeout());
|
||||
if (this.properties.getConnectionTimeout() != null) {
|
||||
builder.connTimeout((int) this.properties.getConnectionTimeout().toMillis());
|
||||
}
|
||||
if (this.properties.getReadTimeout() != null) {
|
||||
builder.readTimeout((int) this.properties.getReadTimeout().toMillis());
|
||||
}
|
||||
customize(builder);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.elasticsearch.jest;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -53,14 +54,14 @@ public class JestProperties {
|
||||
private boolean multiThreaded = true;
|
||||
|
||||
/**
|
||||
* Connection timeout in milliseconds.
|
||||
* Connection timeout.
|
||||
*/
|
||||
private int connectionTimeout = 3000;
|
||||
private Duration connectionTimeout = Duration.ofSeconds(3);
|
||||
|
||||
/**
|
||||
* Read timeout in milliseconds.
|
||||
* Read timeout.
|
||||
*/
|
||||
private int readTimeout = 3000;
|
||||
private Duration readTimeout = Duration.ofSeconds(3);
|
||||
|
||||
/**
|
||||
* Proxy settings.
|
||||
@@ -99,19 +100,19 @@ public class JestProperties {
|
||||
this.multiThreaded = multiThreaded;
|
||||
}
|
||||
|
||||
public int getConnectionTimeout() {
|
||||
public Duration getConnectionTimeout() {
|
||||
return this.connectionTimeout;
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(int connectionTimeout) {
|
||||
public void setConnectionTimeout(Duration connectionTimeout) {
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
}
|
||||
|
||||
public int getReadTimeout() {
|
||||
public Duration getReadTimeout() {
|
||||
return this.readTimeout;
|
||||
}
|
||||
|
||||
public void setReadTimeout(int readTimeout) {
|
||||
public void setReadTimeout(Duration readTimeout) {
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,11 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jdbc;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Configuration properties for JDBC.
|
||||
@@ -51,10 +55,11 @@ public class JdbcProperties {
|
||||
private int maxRows = -1;
|
||||
|
||||
/**
|
||||
* Query timeout in seconds. Use -1 to use the JDBC driver's default
|
||||
* configuration.
|
||||
* Query timeout. Default is to use the JDBC driver's default configuration. If a
|
||||
* duration suffix is not specified, seconds will be used.
|
||||
*/
|
||||
private int queryTimeout = -1;
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration queryTimeout;
|
||||
|
||||
public int getFetchSize() {
|
||||
return this.fetchSize;
|
||||
@@ -72,11 +77,11 @@ public class JdbcProperties {
|
||||
this.maxRows = maxRows;
|
||||
}
|
||||
|
||||
public int getQueryTimeout() {
|
||||
public Duration getQueryTimeout() {
|
||||
return this.queryTimeout;
|
||||
}
|
||||
|
||||
public void setQueryTimeout(int queryTimeout) {
|
||||
public void setQueryTimeout(Duration queryTimeout) {
|
||||
this.queryTimeout = queryTimeout;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,10 @@ public class JdbcTemplateAutoConfiguration {
|
||||
JdbcProperties.Template template = this.properties.getTemplate();
|
||||
jdbcTemplate.setFetchSize(template.getFetchSize());
|
||||
jdbcTemplate.setMaxRows(template.getMaxRows());
|
||||
jdbcTemplate.setQueryTimeout(template.getQueryTimeout());
|
||||
if (template.getQueryTimeout() != null) {
|
||||
jdbcTemplate
|
||||
.setQueryTimeout((int) template.getQueryTimeout().getSeconds());
|
||||
}
|
||||
return jdbcTemplate;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class JmsAutoConfiguration {
|
||||
jmsTemplate.setDefaultDestinationName(template.getDefaultDestination());
|
||||
}
|
||||
if (template.getDeliveryDelay() != null) {
|
||||
jmsTemplate.setDeliveryDelay(template.getDeliveryDelay());
|
||||
jmsTemplate.setDeliveryDelay(template.getDeliveryDelay().toMillis());
|
||||
}
|
||||
jmsTemplate.setExplicitQosEnabled(template.determineQosEnabled());
|
||||
if (template.getDeliveryMode() != null) {
|
||||
@@ -94,10 +94,10 @@ public class JmsAutoConfiguration {
|
||||
jmsTemplate.setPriority(template.getPriority());
|
||||
}
|
||||
if (template.getTimeToLive() != null) {
|
||||
jmsTemplate.setTimeToLive(template.getTimeToLive());
|
||||
jmsTemplate.setTimeToLive(template.getTimeToLive().toMillis());
|
||||
}
|
||||
if (template.getReceiveTimeout() != null) {
|
||||
jmsTemplate.setReceiveTimeout(template.getReceiveTimeout());
|
||||
jmsTemplate.setReceiveTimeout(template.getReceiveTimeout().toMillis());
|
||||
}
|
||||
return jmsTemplate;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jms;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
@@ -142,9 +144,9 @@ public class JmsProperties {
|
||||
private String defaultDestination;
|
||||
|
||||
/**
|
||||
* Delivery delay to use for send calls in milliseconds.
|
||||
* Delivery delay to use for send calls.
|
||||
*/
|
||||
private Long deliveryDelay;
|
||||
private Duration deliveryDelay;
|
||||
|
||||
/**
|
||||
* Delivery mode. Enable QoS when set.
|
||||
@@ -157,9 +159,9 @@ public class JmsProperties {
|
||||
private Integer priority;
|
||||
|
||||
/**
|
||||
* Time-to-live of a message when sending in milliseconds. Enable QoS when set.
|
||||
* Time-to-live of a message when sending. Enable QoS when set.
|
||||
*/
|
||||
private Long timeToLive;
|
||||
private Duration timeToLive;
|
||||
|
||||
/**
|
||||
* Enable explicit QoS when sending a message. When enabled, the delivery mode,
|
||||
@@ -169,9 +171,9 @@ public class JmsProperties {
|
||||
private Boolean qosEnabled;
|
||||
|
||||
/**
|
||||
* Timeout to use for receive calls in milliseconds.
|
||||
* Timeout to use for receive calls.
|
||||
*/
|
||||
private Long receiveTimeout;
|
||||
private Duration receiveTimeout;
|
||||
|
||||
public String getDefaultDestination() {
|
||||
return this.defaultDestination;
|
||||
@@ -181,11 +183,11 @@ public class JmsProperties {
|
||||
this.defaultDestination = defaultDestination;
|
||||
}
|
||||
|
||||
public Long getDeliveryDelay() {
|
||||
public Duration getDeliveryDelay() {
|
||||
return this.deliveryDelay;
|
||||
}
|
||||
|
||||
public void setDeliveryDelay(Long deliveryDelay) {
|
||||
public void setDeliveryDelay(Duration deliveryDelay) {
|
||||
this.deliveryDelay = deliveryDelay;
|
||||
}
|
||||
|
||||
@@ -205,11 +207,11 @@ public class JmsProperties {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public Long getTimeToLive() {
|
||||
public Duration getTimeToLive() {
|
||||
return this.timeToLive;
|
||||
}
|
||||
|
||||
public void setTimeToLive(Long timeToLive) {
|
||||
public void setTimeToLive(Duration timeToLive) {
|
||||
this.timeToLive = timeToLive;
|
||||
}
|
||||
|
||||
@@ -229,11 +231,11 @@ public class JmsProperties {
|
||||
this.qosEnabled = qosEnabled;
|
||||
}
|
||||
|
||||
public Long getReceiveTimeout() {
|
||||
public Duration getReceiveTimeout() {
|
||||
return this.receiveTimeout;
|
||||
}
|
||||
|
||||
public void setReceiveTimeout(Long receiveTimeout) {
|
||||
public void setReceiveTimeout(Duration receiveTimeout) {
|
||||
this.receiveTimeout = receiveTimeout;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,19 +67,29 @@ class ActiveMQConnectionFactoryConfiguration {
|
||||
ActiveMQConnectionFactory.class));
|
||||
ActiveMQProperties.Pool pool = properties.getPool();
|
||||
pooledConnectionFactory.setBlockIfSessionPoolIsFull(pool.isBlockIfFull());
|
||||
pooledConnectionFactory
|
||||
.setBlockIfSessionPoolIsFullTimeout(pool.getBlockIfFullTimeout());
|
||||
if (pool.getBlockIfFullTimeout() != null) {
|
||||
pooledConnectionFactory.setBlockIfSessionPoolIsFullTimeout(
|
||||
pool.getBlockIfFullTimeout().toMillis());
|
||||
}
|
||||
pooledConnectionFactory
|
||||
.setCreateConnectionOnStartup(pool.isCreateConnectionOnStartup());
|
||||
pooledConnectionFactory.setExpiryTimeout(pool.getExpiryTimeout());
|
||||
pooledConnectionFactory.setIdleTimeout(pool.getIdleTimeout());
|
||||
if (pool.getExpiryTimeout() != null) {
|
||||
pooledConnectionFactory
|
||||
.setExpiryTimeout(pool.getExpiryTimeout().toMillis());
|
||||
}
|
||||
if (pool.getIdleTimeout() != null) {
|
||||
pooledConnectionFactory
|
||||
.setIdleTimeout((int) pool.getIdleTimeout().toMillis());
|
||||
}
|
||||
pooledConnectionFactory.setMaxConnections(pool.getMaxConnections());
|
||||
pooledConnectionFactory.setMaximumActiveSessionPerConnection(
|
||||
pool.getMaximumActiveSessionPerConnection());
|
||||
pooledConnectionFactory
|
||||
.setReconnectOnException(pool.isReconnectOnException());
|
||||
pooledConnectionFactory.setTimeBetweenExpirationCheckMillis(
|
||||
pool.getTimeBetweenExpirationCheck());
|
||||
if (pool.getTimeBetweenExpirationCheck() != null) {
|
||||
pooledConnectionFactory.setTimeBetweenExpirationCheckMillis(
|
||||
pool.getTimeBetweenExpirationCheck().toMillis());
|
||||
}
|
||||
pooledConnectionFactory
|
||||
.setUseAnonymousProducers(pool.isUseAnonymousProducers());
|
||||
return pooledConnectionFactory;
|
||||
|
||||
@@ -66,9 +66,13 @@ class ActiveMQConnectionFactoryFactory {
|
||||
private <T extends ActiveMQConnectionFactory> T doCreateConnectionFactory(
|
||||
Class<T> factoryClass) throws Exception {
|
||||
T factory = createConnectionFactoryInstance(factoryClass);
|
||||
factory.setCloseTimeout(this.properties.getCloseTimeout());
|
||||
if (this.properties.getCloseTimeout() != null) {
|
||||
factory.setCloseTimeout((int) this.properties.getCloseTimeout().toMillis());
|
||||
}
|
||||
factory.setNonBlockingRedelivery(this.properties.isNonBlockingRedelivery());
|
||||
factory.setSendTimeout(this.properties.getSendTimeout());
|
||||
if (this.properties.getSendTimeout() != null) {
|
||||
factory.setSendTimeout((int) this.properties.getSendTimeout().toMillis());
|
||||
}
|
||||
Packages packages = this.properties.getPackages();
|
||||
if (packages.getTrustAll() != null) {
|
||||
factory.setTrustAllPackages(packages.getTrustAll());
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jms.activemq;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -54,9 +55,9 @@ public class ActiveMQProperties {
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* Time to wait, in milliseconds, before considering a close complete.
|
||||
* Time to wait before considering a close complete.
|
||||
*/
|
||||
private int closeTimeout = 15000;
|
||||
private Duration closeTimeout = Duration.ofSeconds(15);
|
||||
|
||||
/**
|
||||
* Do not stop message delivery before re-delivering messages from a rolled back
|
||||
@@ -66,10 +67,10 @@ public class ActiveMQProperties {
|
||||
private boolean nonBlockingRedelivery = false;
|
||||
|
||||
/**
|
||||
* Time to wait, in milliseconds, on Message sends for a response. Set it to 0 to
|
||||
* indicate to wait forever.
|
||||
* Time to wait on Message sends for a response. Set it to 0 to indicate to wait
|
||||
* forever.
|
||||
*/
|
||||
private int sendTimeout = 0;
|
||||
private Duration sendTimeout = Duration.ofMillis(0);
|
||||
|
||||
private Pool pool = new Pool();
|
||||
|
||||
@@ -107,11 +108,11 @@ public class ActiveMQProperties {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public int getCloseTimeout() {
|
||||
public Duration getCloseTimeout() {
|
||||
return this.closeTimeout;
|
||||
}
|
||||
|
||||
public void setCloseTimeout(int closeTimeout) {
|
||||
public void setCloseTimeout(Duration closeTimeout) {
|
||||
this.closeTimeout = closeTimeout;
|
||||
}
|
||||
|
||||
@@ -123,11 +124,11 @@ public class ActiveMQProperties {
|
||||
this.nonBlockingRedelivery = nonBlockingRedelivery;
|
||||
}
|
||||
|
||||
public int getSendTimeout() {
|
||||
public Duration getSendTimeout() {
|
||||
return this.sendTimeout;
|
||||
}
|
||||
|
||||
public void setSendTimeout(int sendTimeout) {
|
||||
public void setSendTimeout(Duration sendTimeout) {
|
||||
this.sendTimeout = sendTimeout;
|
||||
}
|
||||
|
||||
@@ -158,10 +159,9 @@ public class ActiveMQProperties {
|
||||
private boolean blockIfFull = true;
|
||||
|
||||
/**
|
||||
* Blocking period, in milliseconds, before throwing an exception if the pool is
|
||||
* still full.
|
||||
* Blocking period, before throwing an exception if the pool is still full.
|
||||
*/
|
||||
private long blockIfFullTimeout = -1;
|
||||
private Duration blockIfFullTimeout = Duration.ofMillis(-1);
|
||||
|
||||
/**
|
||||
* Create a connection on startup. Can be used to warm-up the pool on startup.
|
||||
@@ -169,14 +169,14 @@ public class ActiveMQProperties {
|
||||
private boolean createConnectionOnStartup = true;
|
||||
|
||||
/**
|
||||
* Connection expiration timeout in milliseconds.
|
||||
* Connection expiration timeout.
|
||||
*/
|
||||
private long expiryTimeout = 0;
|
||||
private Duration expiryTimeout = Duration.ofMillis(0);
|
||||
|
||||
/**
|
||||
* Connection idle timeout in milliseconds.
|
||||
* Connection idle timeout.
|
||||
*/
|
||||
private int idleTimeout = 30000;
|
||||
private Duration idleTimeout = Duration.ofSeconds(30);
|
||||
|
||||
/**
|
||||
* Maximum number of pooled connections.
|
||||
@@ -194,10 +194,10 @@ public class ActiveMQProperties {
|
||||
private boolean reconnectOnException = true;
|
||||
|
||||
/**
|
||||
* Time to sleep, in milliseconds, between runs of the idle connection eviction
|
||||
* thread. When negative, no idle connection eviction thread runs.
|
||||
* Time to sleep between runs of the idle connection eviction thread. When
|
||||
* negative, no idle connection eviction thread runs.
|
||||
*/
|
||||
private long timeBetweenExpirationCheck = -1;
|
||||
private Duration timeBetweenExpirationCheck = Duration.ofMillis(-1);
|
||||
|
||||
/**
|
||||
* Use only one anonymous "MessageProducer" instance. Set it to false to create
|
||||
@@ -221,11 +221,11 @@ public class ActiveMQProperties {
|
||||
this.blockIfFull = blockIfFull;
|
||||
}
|
||||
|
||||
public long getBlockIfFullTimeout() {
|
||||
public Duration getBlockIfFullTimeout() {
|
||||
return this.blockIfFullTimeout;
|
||||
}
|
||||
|
||||
public void setBlockIfFullTimeout(long blockIfFullTimeout) {
|
||||
public void setBlockIfFullTimeout(Duration blockIfFullTimeout) {
|
||||
this.blockIfFullTimeout = blockIfFullTimeout;
|
||||
}
|
||||
|
||||
@@ -237,19 +237,19 @@ public class ActiveMQProperties {
|
||||
this.createConnectionOnStartup = createConnectionOnStartup;
|
||||
}
|
||||
|
||||
public long getExpiryTimeout() {
|
||||
public Duration getExpiryTimeout() {
|
||||
return this.expiryTimeout;
|
||||
}
|
||||
|
||||
public void setExpiryTimeout(long expiryTimeout) {
|
||||
public void setExpiryTimeout(Duration expiryTimeout) {
|
||||
this.expiryTimeout = expiryTimeout;
|
||||
}
|
||||
|
||||
public int getIdleTimeout() {
|
||||
public Duration getIdleTimeout() {
|
||||
return this.idleTimeout;
|
||||
}
|
||||
|
||||
public void setIdleTimeout(int idleTimeout) {
|
||||
public void setIdleTimeout(Duration idleTimeout) {
|
||||
this.idleTimeout = idleTimeout;
|
||||
}
|
||||
|
||||
@@ -278,11 +278,11 @@ public class ActiveMQProperties {
|
||||
this.reconnectOnException = reconnectOnException;
|
||||
}
|
||||
|
||||
public long getTimeBetweenExpirationCheck() {
|
||||
public Duration getTimeBetweenExpirationCheck() {
|
||||
return this.timeBetweenExpirationCheck;
|
||||
}
|
||||
|
||||
public void setTimeBetweenExpirationCheck(long timeBetweenExpirationCheck) {
|
||||
public void setTimeBetweenExpirationCheck(Duration timeBetweenExpirationCheck) {
|
||||
this.timeBetweenExpirationCheck = timeBetweenExpirationCheck;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,10 +89,10 @@ public class ConcurrentKafkaListenerContainerFactoryConfigurer {
|
||||
containerProperties.setAckCount(container.getAckCount());
|
||||
}
|
||||
if (container.getAckTime() != null) {
|
||||
containerProperties.setAckTime(container.getAckTime());
|
||||
containerProperties.setAckTime(container.getAckTime().toMillis());
|
||||
}
|
||||
if (container.getPollTimeout() != null) {
|
||||
containerProperties.setPollTimeout(container.getPollTimeout());
|
||||
containerProperties.setPollTimeout(container.getPollTimeout().toMillis());
|
||||
}
|
||||
if (container.getConcurrency() != null) {
|
||||
listenerContainerFactory.setConcurrency(container.getConcurrency());
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.autoconfigure.kafka;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -222,10 +223,10 @@ public class KafkaProperties {
|
||||
private final Ssl ssl = new Ssl();
|
||||
|
||||
/**
|
||||
* Frequency in milliseconds that the consumer offsets are auto-committed to Kafka
|
||||
* if 'enable.auto.commit' true.
|
||||
* Frequency that the consumer offsets are auto-committed to Kafka if
|
||||
* 'enable.auto.commit' true.
|
||||
*/
|
||||
private Integer autoCommitInterval;
|
||||
private Duration autoCommitInterval;
|
||||
|
||||
/**
|
||||
* What to do when there is no initial offset in Kafka or if the current offset
|
||||
@@ -250,11 +251,11 @@ public class KafkaProperties {
|
||||
private Boolean enableAutoCommit;
|
||||
|
||||
/**
|
||||
* Maximum amount of time in milliseconds the server will block before answering
|
||||
* the fetch request if there isn't sufficient data to immediately satisfy the
|
||||
* requirement given by "fetch.min.bytes".
|
||||
* Maximum amount of time the server will block before answering the fetch request
|
||||
* if there isn't sufficient data to immediately satisfy the requirement given by
|
||||
* "fetch.min.bytes".
|
||||
*/
|
||||
private Integer fetchMaxWait;
|
||||
private Duration fetchMaxWait;
|
||||
|
||||
/**
|
||||
* Minimum amount of data the server should return for a fetch request in bytes.
|
||||
@@ -267,9 +268,9 @@ public class KafkaProperties {
|
||||
private String groupId;
|
||||
|
||||
/**
|
||||
* Expected time in milliseconds between heartbeats to the consumer coordinator.
|
||||
* Expected time between heartbeats to the consumer coordinator.
|
||||
*/
|
||||
private Integer heartbeatInterval;
|
||||
private Duration heartbeatInterval;
|
||||
|
||||
/**
|
||||
* Deserializer class for keys.
|
||||
@@ -295,11 +296,11 @@ public class KafkaProperties {
|
||||
return this.ssl;
|
||||
}
|
||||
|
||||
public Integer getAutoCommitInterval() {
|
||||
public Duration getAutoCommitInterval() {
|
||||
return this.autoCommitInterval;
|
||||
}
|
||||
|
||||
public void setAutoCommitInterval(Integer autoCommitInterval) {
|
||||
public void setAutoCommitInterval(Duration autoCommitInterval) {
|
||||
this.autoCommitInterval = autoCommitInterval;
|
||||
}
|
||||
|
||||
@@ -335,11 +336,11 @@ public class KafkaProperties {
|
||||
this.enableAutoCommit = enableAutoCommit;
|
||||
}
|
||||
|
||||
public Integer getFetchMaxWait() {
|
||||
public Duration getFetchMaxWait() {
|
||||
return this.fetchMaxWait;
|
||||
}
|
||||
|
||||
public void setFetchMaxWait(Integer fetchMaxWait) {
|
||||
public void setFetchMaxWait(Duration fetchMaxWait) {
|
||||
this.fetchMaxWait = fetchMaxWait;
|
||||
}
|
||||
|
||||
@@ -359,11 +360,11 @@ public class KafkaProperties {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public Integer getHeartbeatInterval() {
|
||||
public Duration getHeartbeatInterval() {
|
||||
return this.heartbeatInterval;
|
||||
}
|
||||
|
||||
public void setHeartbeatInterval(Integer heartbeatInterval) {
|
||||
public void setHeartbeatInterval(Duration heartbeatInterval) {
|
||||
this.heartbeatInterval = heartbeatInterval;
|
||||
}
|
||||
|
||||
@@ -399,7 +400,7 @@ public class KafkaProperties {
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
if (this.autoCommitInterval != null) {
|
||||
properties.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG,
|
||||
this.autoCommitInterval);
|
||||
(int) this.autoCommitInterval.toMillis());
|
||||
}
|
||||
if (this.autoOffsetReset != null) {
|
||||
properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
|
||||
@@ -418,7 +419,7 @@ public class KafkaProperties {
|
||||
}
|
||||
if (this.fetchMaxWait != null) {
|
||||
properties.put(ConsumerConfig.FETCH_MAX_WAIT_MS_CONFIG,
|
||||
this.fetchMaxWait);
|
||||
(int) this.fetchMaxWait.toMillis());
|
||||
}
|
||||
if (this.fetchMinSize != null) {
|
||||
properties.put(ConsumerConfig.FETCH_MIN_BYTES_CONFIG, this.fetchMinSize);
|
||||
@@ -428,7 +429,7 @@ public class KafkaProperties {
|
||||
}
|
||||
if (this.heartbeatInterval != null) {
|
||||
properties.put(ConsumerConfig.HEARTBEAT_INTERVAL_MS_CONFIG,
|
||||
this.heartbeatInterval);
|
||||
(int) this.heartbeatInterval.toMillis());
|
||||
}
|
||||
if (this.keyDeserializer != null) {
|
||||
properties.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
|
||||
@@ -800,9 +801,9 @@ public class KafkaProperties {
|
||||
private Integer concurrency;
|
||||
|
||||
/**
|
||||
* Timeout in milliseconds to use when polling the consumer.
|
||||
* Timeout to use when polling the consumer.
|
||||
*/
|
||||
private Long pollTimeout;
|
||||
private Duration pollTimeout;
|
||||
|
||||
/**
|
||||
* Number of records between offset commits when ackMode is "COUNT" or
|
||||
@@ -811,10 +812,9 @@ public class KafkaProperties {
|
||||
private Integer ackCount;
|
||||
|
||||
/**
|
||||
* Time in milliseconds between offset commits when ackMode is "TIME" or
|
||||
* "COUNT_TIME".
|
||||
* Time between offset commits when ackMode is "TIME" or "COUNT_TIME".
|
||||
*/
|
||||
private Long ackTime;
|
||||
private Duration ackTime;
|
||||
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
@@ -840,11 +840,11 @@ public class KafkaProperties {
|
||||
this.concurrency = concurrency;
|
||||
}
|
||||
|
||||
public Long getPollTimeout() {
|
||||
public Duration getPollTimeout() {
|
||||
return this.pollTimeout;
|
||||
}
|
||||
|
||||
public void setPollTimeout(Long pollTimeout) {
|
||||
public void setPollTimeout(Duration pollTimeout) {
|
||||
this.pollTimeout = pollTimeout;
|
||||
}
|
||||
|
||||
@@ -856,11 +856,11 @@ public class KafkaProperties {
|
||||
this.ackCount = ackCount;
|
||||
}
|
||||
|
||||
public Long getAckTime() {
|
||||
public Duration getAckTime() {
|
||||
return this.ackTime;
|
||||
}
|
||||
|
||||
public void setAckTime(Long ackTime) {
|
||||
public void setAckTime(Duration ackTime) {
|
||||
this.ackTime = ackTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.session;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import com.hazelcast.core.HazelcastInstance;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -52,9 +54,9 @@ class HazelcastSessionConfiguration {
|
||||
@Autowired
|
||||
public void customize(SessionProperties sessionProperties,
|
||||
HazelcastSessionProperties hazelcastSessionProperties) {
|
||||
Integer timeout = sessionProperties.getTimeout();
|
||||
Duration timeout = sessionProperties.getTimeout();
|
||||
if (timeout != null) {
|
||||
setMaxInactiveIntervalInSeconds(timeout);
|
||||
setMaxInactiveIntervalInSeconds((int) timeout.getSeconds());
|
||||
}
|
||||
setSessionMapName(hazelcastSessionProperties.getMapName());
|
||||
setHazelcastFlushMode(hazelcastSessionProperties.getFlushMode());
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.session;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -63,9 +65,9 @@ class JdbcSessionConfiguration {
|
||||
@Autowired
|
||||
public void customize(SessionProperties sessionProperties,
|
||||
JdbcSessionProperties jdbcSessionProperties) {
|
||||
Integer timeout = sessionProperties.getTimeout();
|
||||
Duration timeout = sessionProperties.getTimeout();
|
||||
if (timeout != null) {
|
||||
setMaxInactiveIntervalInSeconds(timeout);
|
||||
setMaxInactiveIntervalInSeconds((int) timeout.getSeconds());
|
||||
}
|
||||
setTableName(jdbcSessionProperties.getTableName());
|
||||
setCleanupCron(jdbcSessionProperties.getCleanupCron());
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.session;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -47,9 +49,9 @@ class MongoReactiveSessionConfiguration {
|
||||
@Autowired
|
||||
public void customize(SessionProperties sessionProperties,
|
||||
MongoSessionProperties mongoSessionProperties) {
|
||||
Integer timeout = sessionProperties.getTimeout();
|
||||
Duration timeout = sessionProperties.getTimeout();
|
||||
if (timeout != null) {
|
||||
setMaxInactiveIntervalInSeconds(timeout);
|
||||
setMaxInactiveIntervalInSeconds((int) timeout.getSeconds());
|
||||
}
|
||||
setCollectionName(mongoSessionProperties.getCollectionName());
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.session;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -48,9 +50,9 @@ class MongoSessionConfiguration {
|
||||
@Autowired
|
||||
public void customize(SessionProperties sessionProperties,
|
||||
MongoSessionProperties mongoSessionProperties) {
|
||||
Integer timeout = sessionProperties.getTimeout();
|
||||
Duration timeout = sessionProperties.getTimeout();
|
||||
if (timeout != null) {
|
||||
setMaxInactiveIntervalInSeconds(timeout);
|
||||
setMaxInactiveIntervalInSeconds((int) timeout.getSeconds());
|
||||
}
|
||||
setCollectionName(mongoSessionProperties.getCollectionName());
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.session;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -52,9 +54,9 @@ class RedisReactiveSessionConfiguration {
|
||||
public void customize(SessionProperties sessionProperties,
|
||||
RedisSessionProperties redisSessionProperties) {
|
||||
this.sessionProperties = sessionProperties;
|
||||
Integer timeout = this.sessionProperties.getTimeout();
|
||||
Duration timeout = this.sessionProperties.getTimeout();
|
||||
if (timeout != null) {
|
||||
setMaxInactiveIntervalInSeconds(timeout);
|
||||
setMaxInactiveIntervalInSeconds((int) timeout.getSeconds());
|
||||
}
|
||||
setRedisNamespace(redisSessionProperties.getNamespace());
|
||||
setRedisFlushMode(redisSessionProperties.getFlushMode());
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.session;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@@ -56,9 +58,9 @@ class RedisSessionConfiguration {
|
||||
public void customize(SessionProperties sessionProperties,
|
||||
RedisSessionProperties redisSessionProperties) {
|
||||
this.sessionProperties = sessionProperties;
|
||||
Integer timeout = this.sessionProperties.getTimeout();
|
||||
Duration timeout = this.sessionProperties.getTimeout();
|
||||
if (timeout != null) {
|
||||
setMaxInactiveIntervalInSeconds(timeout);
|
||||
setMaxInactiveIntervalInSeconds((int) timeout.getSeconds());
|
||||
}
|
||||
setRedisNamespace(redisSessionProperties.getNamespace());
|
||||
setRedisFlushMode(redisSessionProperties.getFlushMode());
|
||||
|
||||
@@ -16,12 +16,14 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.session;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties.Session;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.web.servlet.DispatcherType;
|
||||
import org.springframework.session.web.http.SessionRepositoryFilter;
|
||||
@@ -42,13 +44,17 @@ public class SessionProperties {
|
||||
*/
|
||||
private StoreType storeType;
|
||||
|
||||
private final Integer timeout;
|
||||
/**
|
||||
* Session timeout.
|
||||
*/
|
||||
private final Duration timeout;
|
||||
|
||||
private Servlet servlet = new Servlet();
|
||||
|
||||
public SessionProperties(ObjectProvider<ServerProperties> serverProperties) {
|
||||
ServerProperties properties = serverProperties.getIfUnique();
|
||||
this.timeout = (properties != null ? properties.getSession().getTimeout() : null);
|
||||
Session session = (properties == null ? null : properties.getSession());
|
||||
this.timeout = (session == null ? null : session.getTimeout());
|
||||
}
|
||||
|
||||
public StoreType getStoreType() {
|
||||
@@ -60,11 +66,11 @@ public class SessionProperties {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the session timeout in seconds.
|
||||
* @return the session timeout in seconds
|
||||
* Return the session timeout.
|
||||
* @return the session timeout
|
||||
* @see ServerProperties#getSession()
|
||||
*/
|
||||
public Integer getTimeout() {
|
||||
public Duration getTimeout() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,11 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.transaction;
|
||||
|
||||
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.transaction.support.AbstractPlatformTransactionManager;
|
||||
|
||||
/**
|
||||
@@ -32,20 +36,22 @@ public class TransactionProperties implements
|
||||
PlatformTransactionManagerCustomizer<AbstractPlatformTransactionManager> {
|
||||
|
||||
/**
|
||||
* Default transaction timeout in seconds.
|
||||
* Default transaction timeout. If a duration suffix is not specified, seconds will be
|
||||
* used.
|
||||
*/
|
||||
private Integer defaultTimeout;
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration defaultTimeout;
|
||||
|
||||
/**
|
||||
* Perform the rollback on commit failures.
|
||||
*/
|
||||
private Boolean rollbackOnCommitFailure;
|
||||
|
||||
public Integer getDefaultTimeout() {
|
||||
public Duration getDefaultTimeout() {
|
||||
return this.defaultTimeout;
|
||||
}
|
||||
|
||||
public void setDefaultTimeout(Integer defaultTimeout) {
|
||||
public void setDefaultTimeout(Duration defaultTimeout) {
|
||||
this.defaultTimeout = defaultTimeout;
|
||||
}
|
||||
|
||||
@@ -60,7 +66,7 @@ public class TransactionProperties implements
|
||||
@Override
|
||||
public void customize(AbstractPlatformTransactionManager transactionManager) {
|
||||
if (this.defaultTimeout != null) {
|
||||
transactionManager.setDefaultTimeout(this.defaultTimeout);
|
||||
transactionManager.setDefaultTimeout((int) this.defaultTimeout.getSeconds());
|
||||
}
|
||||
if (this.rollbackOnCommitFailure != null) {
|
||||
transactionManager.setRollbackOnCommitFailure(this.rollbackOnCommitFailure);
|
||||
|
||||
@@ -16,7 +16,11 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.web;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Properties used to configure resource handling.
|
||||
@@ -41,9 +45,11 @@ public class ResourceProperties {
|
||||
private String[] staticLocations = CLASSPATH_RESOURCE_LOCATIONS;
|
||||
|
||||
/**
|
||||
* Cache period for the resources served by the resource handler, in seconds.
|
||||
* Cache period for the resources served by the resource handler. If a duration suffix
|
||||
* is not specified, seconds will be used.
|
||||
*/
|
||||
private Integer cachePeriod;
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration cachePeriod;
|
||||
|
||||
/**
|
||||
* Enable default resource handling.
|
||||
@@ -69,11 +75,11 @@ public class ResourceProperties {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
public Integer getCachePeriod() {
|
||||
public Duration getCachePeriod() {
|
||||
return this.cachePeriod;
|
||||
}
|
||||
|
||||
public void setCachePeriod(Integer cachePeriod) {
|
||||
public void setCachePeriod(Duration cachePeriod) {
|
||||
this.cachePeriod = cachePeriod;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ package org.springframework.boot.autoconfigure.web;
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -30,6 +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.web.server.Compression;
|
||||
import org.springframework.boot.web.server.Http2;
|
||||
import org.springframework.boot.web.server.Ssl;
|
||||
@@ -89,11 +92,11 @@ public class ServerProperties {
|
||||
private int maxHttpHeaderSize = 0; // bytes
|
||||
|
||||
/**
|
||||
* Time in milliseconds that connectors will wait for another HTTP request before
|
||||
* closing the connection. When not set, the connector's server-specific default will
|
||||
* be used. Use a value of -1 to indicate no (i.e. infinite) timeout.
|
||||
* Time that connectors will wait for another HTTP request before closing the
|
||||
* connection. When not set, the connector's server-specific default will be used. Use
|
||||
* a value of -1 to indicate no (i.e. infinite) timeout.
|
||||
*/
|
||||
private Integer connectionTimeout;
|
||||
private Duration connectionTimeout;
|
||||
|
||||
private Session session = new Session();
|
||||
|
||||
@@ -162,11 +165,11 @@ public class ServerProperties {
|
||||
this.maxHttpHeaderSize = maxHttpHeaderSize;
|
||||
}
|
||||
|
||||
public Integer getConnectionTimeout() {
|
||||
public Duration getConnectionTimeout() {
|
||||
return this.connectionTimeout;
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(Integer connectionTimeout) {
|
||||
public void setConnectionTimeout(Duration connectionTimeout) {
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
}
|
||||
|
||||
@@ -335,9 +338,10 @@ public class ServerProperties {
|
||||
public static class Session {
|
||||
|
||||
/**
|
||||
* Session timeout in seconds.
|
||||
* Session timeout. If a duration suffix is not specified, seconds will be used.
|
||||
*/
|
||||
private Integer timeout;
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration timeout;
|
||||
|
||||
/**
|
||||
* Session tracking modes (one or more of the following: "cookie", "url", "ssl").
|
||||
@@ -360,12 +364,12 @@ public class ServerProperties {
|
||||
return this.cookie;
|
||||
}
|
||||
|
||||
public Integer getTimeout() {
|
||||
public Duration getTimeout() {
|
||||
return this.timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(Integer sessionTimeout) {
|
||||
this.timeout = sessionTimeout;
|
||||
public void setTimeout(Duration timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public Set<SessionTrackingMode> getTrackingModes() {
|
||||
@@ -428,9 +432,10 @@ public class ServerProperties {
|
||||
private Boolean secure;
|
||||
|
||||
/**
|
||||
* Maximum age of the session cookie in seconds.
|
||||
* Maximum age of the session cookie.
|
||||
*/
|
||||
private Integer maxAge;
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration maxAge;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
@@ -480,11 +485,11 @@ public class ServerProperties {
|
||||
this.secure = secure;
|
||||
}
|
||||
|
||||
public Integer getMaxAge() {
|
||||
public Duration getMaxAge() {
|
||||
return this.maxAge;
|
||||
}
|
||||
|
||||
public void setMaxAge(Integer maxAge) {
|
||||
public void setMaxAge(Duration maxAge) {
|
||||
this.maxAge = maxAge;
|
||||
}
|
||||
|
||||
@@ -562,29 +567,31 @@ public class ServerProperties {
|
||||
private File basedir;
|
||||
|
||||
/**
|
||||
* Delay in seconds between the invocation of backgroundProcess methods.
|
||||
* Delay between the invocation of backgroundProcess methods. If a duration suffix
|
||||
* is not specified, seconds will be used.
|
||||
*/
|
||||
private int backgroundProcessorDelay = 30; // seconds
|
||||
@DurationUnit(ChronoUnit.SECONDS)
|
||||
private Duration backgroundProcessorDelay = Duration.ofSeconds(30);
|
||||
|
||||
/**
|
||||
* Maximum amount of worker threads.
|
||||
*/
|
||||
private int maxThreads = 0; // Number of threads in protocol handler
|
||||
private int maxThreads = 0;
|
||||
|
||||
/**
|
||||
* Minimum amount of worker threads.
|
||||
*/
|
||||
private int minSpareThreads = 0; // Minimum spare threads in protocol handler
|
||||
private int minSpareThreads = 0;
|
||||
|
||||
/**
|
||||
* Maximum size in bytes of the HTTP post content.
|
||||
*/
|
||||
private int maxHttpPostSize = 0; // bytes
|
||||
private int maxHttpPostSize = 0;
|
||||
|
||||
/**
|
||||
* Maximum size in bytes of the HTTP message header.
|
||||
*/
|
||||
private int maxHttpHeaderSize = 0; // bytes
|
||||
private int maxHttpHeaderSize = 0;
|
||||
|
||||
/**
|
||||
* Whether requests to the context root should be redirected by appending a / to
|
||||
@@ -650,11 +657,11 @@ public class ServerProperties {
|
||||
return this.accesslog;
|
||||
}
|
||||
|
||||
public int getBackgroundProcessorDelay() {
|
||||
public Duration getBackgroundProcessorDelay() {
|
||||
return this.backgroundProcessorDelay;
|
||||
}
|
||||
|
||||
public void setBackgroundProcessorDelay(int backgroundProcessorDelay) {
|
||||
public void setBackgroundProcessorDelay(Duration backgroundProcessorDelay) {
|
||||
this.backgroundProcessorDelay = backgroundProcessorDelay;
|
||||
}
|
||||
|
||||
@@ -903,15 +910,15 @@ public class ServerProperties {
|
||||
public static class Resource {
|
||||
|
||||
/**
|
||||
* Time-to-live in milliseconds of the static resource cache.
|
||||
* Time-to-live of the static resource cache.
|
||||
*/
|
||||
private Long cacheTtl;
|
||||
private Duration cacheTtl;
|
||||
|
||||
public Long getCacheTtl() {
|
||||
public Duration getCacheTtl() {
|
||||
return this.cacheTtl;
|
||||
}
|
||||
|
||||
public void setCacheTtl(Long cacheTtl) {
|
||||
public void setCacheTtl(Duration cacheTtl) {
|
||||
this.cacheTtl = cacheTtl;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.reactive;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -145,14 +146,14 @@ public class WebFluxAutoConfiguration {
|
||||
logger.debug("Default resource handling disabled");
|
||||
return;
|
||||
}
|
||||
Integer cachePeriod = this.resourceProperties.getCachePeriod();
|
||||
Duration cachePeriod = this.resourceProperties.getCachePeriod();
|
||||
if (!registry.hasMappingForPattern("/webjars/**")) {
|
||||
ResourceHandlerRegistration registration = registry
|
||||
.addResourceHandler("/webjars/**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
if (cachePeriod != null) {
|
||||
registration.setCacheControl(
|
||||
CacheControl.maxAge(cachePeriod, TimeUnit.SECONDS));
|
||||
registration.setCacheControl(CacheControl
|
||||
.maxAge(cachePeriod.toMillis(), TimeUnit.MILLISECONDS));
|
||||
}
|
||||
customizeResourceHandlerRegistration(registration);
|
||||
}
|
||||
@@ -162,8 +163,8 @@ public class WebFluxAutoConfiguration {
|
||||
.addResourceHandler(staticPathPattern).addResourceLocations(
|
||||
this.resourceProperties.getStaticLocations());
|
||||
if (cachePeriod != null) {
|
||||
registration.setCacheControl(
|
||||
CacheControl.maxAge(cachePeriod, TimeUnit.SECONDS));
|
||||
registration.setCacheControl(CacheControl
|
||||
.maxAge(cachePeriod.toMillis(), TimeUnit.MILLISECONDS));
|
||||
}
|
||||
customizeResourceHandlerRegistration(registration);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.servlet;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -195,7 +196,7 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
config.setSecure(cookie.getSecure());
|
||||
}
|
||||
if (cookie.getMaxAge() != null) {
|
||||
config.setMaxAge(cookie.getMaxAge());
|
||||
config.setMaxAge((int) cookie.getMaxAge().getSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,13 +218,14 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
|
||||
public static void customizeTomcat(ServerProperties serverProperties,
|
||||
Environment environment, TomcatServletWebServerFactory factory) {
|
||||
|
||||
ServerProperties.Tomcat tomcatProperties = serverProperties.getTomcat();
|
||||
if (tomcatProperties.getBasedir() != null) {
|
||||
factory.setBaseDirectory(tomcatProperties.getBasedir());
|
||||
}
|
||||
factory.setBackgroundProcessorDelay(
|
||||
tomcatProperties.getBackgroundProcessorDelay());
|
||||
if (tomcatProperties.getBackgroundProcessorDelay() != null) {
|
||||
factory.setBackgroundProcessorDelay((int) tomcatProperties
|
||||
.getBackgroundProcessorDelay().getSeconds());
|
||||
}
|
||||
customizeRemoteIpValve(serverProperties, environment, factory);
|
||||
if (tomcatProperties.getMaxThreads() > 0) {
|
||||
customizeMaxThreads(factory, tomcatProperties.getMaxThreads());
|
||||
@@ -290,12 +292,12 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private static void customizeConnectionTimeout(
|
||||
TomcatServletWebServerFactory factory, final int connectionTimeout) {
|
||||
TomcatServletWebServerFactory factory, Duration connectionTimeout) {
|
||||
factory.addConnectorCustomizers((connector) -> {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
|
||||
protocol.setConnectionTimeout(connectionTimeout);
|
||||
protocol.setConnectionTimeout((int) connectionTimeout.toMillis());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -398,7 +400,8 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
factory.addContextCustomizers((context) -> {
|
||||
context.addLifecycleListener((event) -> {
|
||||
if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
|
||||
context.getResources().setCacheTtl(resource.getCacheTtl());
|
||||
long ttl = resource.getCacheTtl().toMillis();
|
||||
context.getResources().setCacheTtl(ttl);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -453,9 +456,10 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private static void customizeConnectionTimeout(
|
||||
UndertowServletWebServerFactory factory, final int connectionTimeout) {
|
||||
UndertowServletWebServerFactory factory, Duration connectionTimeout) {
|
||||
factory.addBuilderCustomizers((builder) -> builder.setSocketOption(
|
||||
UndertowOptions.NO_REQUEST_TIMEOUT, connectionTimeout));
|
||||
UndertowOptions.NO_REQUEST_TIMEOUT,
|
||||
(int) connectionTimeout.toMillis()));
|
||||
}
|
||||
|
||||
private static void customizeMaxHttpHeaderSize(
|
||||
@@ -503,12 +507,13 @@ public class DefaultServletWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private static void customizeConnectionTimeout(
|
||||
JettyServletWebServerFactory factory, final int connectionTimeout) {
|
||||
JettyServletWebServerFactory factory, Duration connectionTimeout) {
|
||||
factory.addServerCustomizers((server) -> {
|
||||
for (org.eclipse.jetty.server.Connector connector : server
|
||||
.getConnectors()) {
|
||||
if (connector instanceof AbstractConnector) {
|
||||
((AbstractConnector) connector).setIdleTimeout(connectionTimeout);
|
||||
((AbstractConnector) connector)
|
||||
.setIdleTimeout(connectionTimeout.toMillis());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.servlet;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -207,9 +208,9 @@ public class WebMvcAutoConfiguration {
|
||||
|
||||
@Override
|
||||
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
|
||||
Long timeout = this.mvcProperties.getAsync().getRequestTimeout();
|
||||
Duration timeout = this.mvcProperties.getAsync().getRequestTimeout();
|
||||
if (timeout != null) {
|
||||
configurer.setDefaultTimeout(timeout);
|
||||
configurer.setDefaultTimeout(timeout.toMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,13 +306,13 @@ public class WebMvcAutoConfiguration {
|
||||
logger.debug("Default resource handling disabled");
|
||||
return;
|
||||
}
|
||||
Integer cachePeriod = this.resourceProperties.getCachePeriod();
|
||||
Duration cachePeriod = this.resourceProperties.getCachePeriod();
|
||||
if (!registry.hasMappingForPattern("/webjars/**")) {
|
||||
customizeResourceHandlerRegistration(
|
||||
registry.addResourceHandler("/webjars/**")
|
||||
.addResourceLocations(
|
||||
"classpath:/META-INF/resources/webjars/")
|
||||
.setCachePeriod(cachePeriod));
|
||||
.setCachePeriod(getSeconds(cachePeriod)));
|
||||
}
|
||||
String staticPathPattern = this.mvcProperties.getStaticPathPattern();
|
||||
if (!registry.hasMappingForPattern(staticPathPattern)) {
|
||||
@@ -319,10 +320,14 @@ public class WebMvcAutoConfiguration {
|
||||
registry.addResourceHandler(staticPathPattern)
|
||||
.addResourceLocations(getResourceLocations(
|
||||
this.resourceProperties.getStaticLocations()))
|
||||
.setCachePeriod(cachePeriod));
|
||||
.setCachePeriod(getSeconds(cachePeriod)));
|
||||
}
|
||||
}
|
||||
|
||||
private Integer getSeconds(Duration cachePeriod) {
|
||||
return (cachePeriod == null ? null : (int) cachePeriod.getSeconds());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WelcomePageHandlerMapping welcomePageHandlerMapping() {
|
||||
return new WelcomePageHandlerMapping(getWelcomePage(),
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.web.servlet;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -204,17 +205,17 @@ public class WebMvcProperties {
|
||||
public static class Async {
|
||||
|
||||
/**
|
||||
* Amount of time (in milliseconds) before asynchronous request handling times
|
||||
* out. If this value is not set, the default timeout of the underlying
|
||||
* implementation is used, e.g. 10 seconds on Tomcat with Servlet 3.
|
||||
* Amount of time before asynchronous request handling times out. If this value is
|
||||
* not set, the default timeout of the underlying implementation is used, e.g. 10
|
||||
* seconds on Tomcat with Servlet 3.
|
||||
*/
|
||||
private Long requestTimeout;
|
||||
private Duration requestTimeout;
|
||||
|
||||
public Long getRequestTimeout() {
|
||||
public Duration getRequestTimeout() {
|
||||
return this.requestTimeout;
|
||||
}
|
||||
|
||||
public void setRequestTimeout(Long requestTimeout) {
|
||||
public void setRequestTimeout(Duration requestTimeout) {
|
||||
this.requestTimeout = requestTimeout;
|
||||
}
|
||||
|
||||
|
||||
@@ -1036,6 +1036,24 @@
|
||||
"level": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spring.data.cassandra.connect-timeout-millis",
|
||||
"type": "java.lang.Integer",
|
||||
"description": "Socket option: connection time out.",
|
||||
"deprecation": {
|
||||
"replacement": "spring.data.cassandra.connect-timeout",
|
||||
"level": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spring.data.cassandra.read-timeout-millis",
|
||||
"type": "java.lang.Integer",
|
||||
"description": "Socket option: read time out.",
|
||||
"deprecation": {
|
||||
"replacement": "spring.data.cassandra.read-timeout",
|
||||
"level": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spring.data.neo4j.compiler",
|
||||
"type": "java.lang.String",
|
||||
@@ -1130,6 +1148,15 @@
|
||||
"level": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spring.messages.cache-seconds",
|
||||
"type": "java.lang.Integer",
|
||||
"description": "Loaded resource bundle files cache expiration, in seconds. When set to -1, bundles are cached forever",
|
||||
"deprecation": {
|
||||
"replacement": "spring.messages.cache-duration",
|
||||
"level": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spring.redis.pool.max-active",
|
||||
"type": "java.lang.Integer",
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.boot.autoconfigure.jms;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -72,7 +74,7 @@ public class JmsPropertiesTests {
|
||||
@Test
|
||||
public void setTimeToLiveEnablesQoS() {
|
||||
JmsProperties properties = new JmsProperties();
|
||||
properties.getTemplate().setTimeToLive(5000L);
|
||||
properties.getTemplate().setTimeToLive(Duration.ofSeconds(5));
|
||||
assertThat(properties.getTemplate().determineQosEnabled()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.web;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -72,8 +73,9 @@ public class ServerPropertiesTests {
|
||||
|
||||
@Test
|
||||
public void testConnectionTimeout() throws Exception {
|
||||
bind("server.connection-timeout", "60000");
|
||||
assertThat(this.properties.getConnectionTimeout()).isEqualTo(60000);
|
||||
bind("server.connection-timeout", "60s");
|
||||
assertThat(this.properties.getConnectionTimeout())
|
||||
.isEqualTo(Duration.ofMillis(60000));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,7 +117,8 @@ public class ServerPropertiesTests {
|
||||
assertThat(tomcat.getProtocolHeader()).isEqualTo("X-Forwarded-Protocol");
|
||||
assertThat(tomcat.getInternalProxies())
|
||||
.isEqualTo("10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
|
||||
assertThat(tomcat.getBackgroundProcessorDelay()).isEqualTo(10);
|
||||
assertThat(tomcat.getBackgroundProcessorDelay())
|
||||
.isEqualTo(Duration.ofSeconds(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.web.servlet;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
@@ -212,7 +213,7 @@ public class DefaultServletWebServerFactoryCustomizerTests {
|
||||
given(servletContext.getSessionCookieConfig()).willReturn(sessionCookieConfig);
|
||||
this.customizer.customize(factory);
|
||||
triggerInitializers(factory, servletContext);
|
||||
verify(factory).setSessionTimeout(123);
|
||||
verify(factory).setSessionTimeout(Duration.ofSeconds(123));
|
||||
verify(servletContext).setSessionTrackingModes(
|
||||
EnumSet.of(SessionTrackingMode.COOKIE, SessionTrackingMode.URL));
|
||||
verify(sessionCookieConfig).setName("testname");
|
||||
|
||||
Reference in New Issue
Block a user