Remove APIs that were deprecated for removal in 3.4.0
Closes gh-41435
This commit is contained in:
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.context.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link ApplicationContextInitializer} that delegates to other initializers that are
|
||||
* specified under a {@literal context.initializer.classes} environment property.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @since 1.0.0
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 as property based initialization is no
|
||||
* longer recommended
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public class DelegatingApplicationContextInitializer
|
||||
implements ApplicationContextInitializer<ConfigurableApplicationContext>, Ordered {
|
||||
|
||||
// NOTE: Similar to org.springframework.web.context.ContextLoader
|
||||
|
||||
private static final String PROPERTY_NAME = "context.initializer.classes";
|
||||
|
||||
private int order = 0;
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext context) {
|
||||
ConfigurableEnvironment environment = context.getEnvironment();
|
||||
List<Class<?>> initializerClasses = getInitializerClasses(environment);
|
||||
if (!initializerClasses.isEmpty()) {
|
||||
applyInitializerClasses(context, initializerClasses);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Class<?>> getInitializerClasses(ConfigurableEnvironment env) {
|
||||
String classNames = env.getProperty(PROPERTY_NAME);
|
||||
List<Class<?>> classes = new ArrayList<>();
|
||||
if (StringUtils.hasLength(classNames)) {
|
||||
for (String className : StringUtils.tokenizeToStringArray(classNames, ",")) {
|
||||
classes.add(getInitializerClass(className));
|
||||
}
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
|
||||
private Class<?> getInitializerClass(String className) throws LinkageError {
|
||||
try {
|
||||
Class<?> initializerClass = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
|
||||
Assert.isAssignable(ApplicationContextInitializer.class, initializerClass);
|
||||
return initializerClass;
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new ApplicationContextException("Failed to load context initializer class [" + className + "]", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyInitializerClasses(ConfigurableApplicationContext context, List<Class<?>> initializerClasses) {
|
||||
Class<?> contextClass = context.getClass();
|
||||
List<ApplicationContextInitializer<?>> initializers = new ArrayList<>();
|
||||
for (Class<?> initializerClass : initializerClasses) {
|
||||
initializers.add(instantiateInitializer(contextClass, initializerClass));
|
||||
}
|
||||
applyInitializers(context, initializers);
|
||||
}
|
||||
|
||||
private ApplicationContextInitializer<?> instantiateInitializer(Class<?> contextClass, Class<?> initializerClass) {
|
||||
Class<?> requireContextClass = GenericTypeResolver.resolveTypeArgument(initializerClass,
|
||||
ApplicationContextInitializer.class);
|
||||
Assert.isAssignable(requireContextClass, contextClass,
|
||||
() -> String.format(
|
||||
"Could not add context initializer [%s] as its generic parameter [%s] is not assignable "
|
||||
+ "from the type of application context used by this context loader [%s]: ",
|
||||
initializerClass.getName(), requireContextClass.getName(), contextClass.getName()));
|
||||
return (ApplicationContextInitializer<?>) BeanUtils.instantiateClass(initializerClass);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private void applyInitializers(ConfigurableApplicationContext context,
|
||||
List<ApplicationContextInitializer<?>> initializers) {
|
||||
initializers.sort(new AnnotationAwareOrderComparator());
|
||||
for (ApplicationContextInitializer initializer : initializers) {
|
||||
initializer.initialize(context);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.context.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.event.SimpleApplicationEventMulticaster;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link ApplicationListener} that delegates to other listeners that are specified under
|
||||
* a {@literal context.listener.classes} environment property.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @since 1.0.0
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 as property based initialization is no
|
||||
* longer recommended
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public class DelegatingApplicationListener implements ApplicationListener<ApplicationEvent>, Ordered {
|
||||
|
||||
// NOTE: Similar to org.springframework.web.context.ContextLoader
|
||||
|
||||
private static final String PROPERTY_NAME = "context.listener.classes";
|
||||
|
||||
private int order = 0;
|
||||
|
||||
private SimpleApplicationEventMulticaster multicaster;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (event instanceof ApplicationEnvironmentPreparedEvent preparedEvent) {
|
||||
List<ApplicationListener<ApplicationEvent>> delegates = getListeners(preparedEvent.getEnvironment());
|
||||
if (delegates.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
this.multicaster = new SimpleApplicationEventMulticaster();
|
||||
for (ApplicationListener<ApplicationEvent> listener : delegates) {
|
||||
this.multicaster.addApplicationListener(listener);
|
||||
}
|
||||
}
|
||||
if (this.multicaster != null) {
|
||||
this.multicaster.multicastEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<ApplicationListener<ApplicationEvent>> getListeners(ConfigurableEnvironment environment) {
|
||||
if (environment == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
String classNames = environment.getProperty(PROPERTY_NAME);
|
||||
List<ApplicationListener<ApplicationEvent>> listeners = new ArrayList<>();
|
||||
if (StringUtils.hasLength(classNames)) {
|
||||
for (String className : StringUtils.commaDelimitedListToSet(classNames)) {
|
||||
try {
|
||||
Class<?> clazz = ClassUtils.forName(className, ClassUtils.getDefaultClassLoader());
|
||||
Assert.isAssignable(ApplicationListener.class, clazz,
|
||||
() -> "class [" + className + "] must implement ApplicationListener");
|
||||
listeners.add((ApplicationListener<ApplicationEvent>) BeanUtils.instantiateClass(clazz));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new ApplicationContextException("Failed to load context listener class [" + className + "]",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
AnnotationAwareOrderComparator.sort(listeners);
|
||||
return listeners;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -44,117 +44,6 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class LoggingSystemProperties {
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the process ID.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#PID}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String PID_KEY = LoggingSystemProperty.PID.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the exception conversion word.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#EXCEPTION_CONVERSION_WORD}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String EXCEPTION_CONVERSION_WORD = LoggingSystemProperty.EXCEPTION_CONVERSION_WORD
|
||||
.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the log file.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#LOG_FILE}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String LOG_FILE = LoggingSystemProperty.LOG_FILE.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the log path.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#LOG_PATH}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String LOG_PATH = LoggingSystemProperty.LOG_PATH.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the console log pattern.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#CONSOLE_PATTERN}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String CONSOLE_LOG_PATTERN = LoggingSystemProperty.CONSOLE_PATTERN.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the console log charset.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#CONSOLE_CHARSET}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String CONSOLE_LOG_CHARSET = LoggingSystemProperty.CONSOLE_CHARSET.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The log level threshold for console log.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#CONSOLE_THRESHOLD}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String CONSOLE_LOG_THRESHOLD = LoggingSystemProperty.CONSOLE_THRESHOLD
|
||||
.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the file log pattern.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#FILE_PATTERN}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String FILE_LOG_PATTERN = LoggingSystemProperty.FILE_PATTERN.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the file log charset.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#FILE_CHARSET}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String FILE_LOG_CHARSET = LoggingSystemProperty.FILE_CHARSET.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The log level threshold for file log.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#FILE_THRESHOLD}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String FILE_LOG_THRESHOLD = LoggingSystemProperty.FILE_THRESHOLD.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the log level pattern.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#LEVEL_PATTERN}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String LOG_LEVEL_PATTERN = LoggingSystemProperty.LEVEL_PATTERN.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the log date-format pattern.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link LoggingSystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link LoggingSystemProperty#DATEFORMAT_PATTERN}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String LOG_DATEFORMAT_PATTERN = LoggingSystemProperty.DATEFORMAT_PATTERN
|
||||
.getEnvironmentVariableName();
|
||||
|
||||
private static final BiConsumer<String, String> systemPropertySetter = (name, value) -> {
|
||||
if (System.getProperty(name) == null && value != null) {
|
||||
System.setProperty(name, value);
|
||||
@@ -300,35 +189,6 @@ public class LoggingSystemProperties {
|
||||
return input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a system property.
|
||||
* @param resolver the resolver used to get the property value
|
||||
* @param systemPropertyName the system property name
|
||||
* @param propertyName the application property name
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 with no replacement
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
protected final void setSystemProperty(PropertyResolver resolver, String systemPropertyName, String propertyName) {
|
||||
setSystemProperty(resolver, systemPropertyName, propertyName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a system property.
|
||||
* @param resolver the resolver used to get the property value
|
||||
* @param systemPropertyName the system property name
|
||||
* @param propertyName the application property name
|
||||
* @param defaultValue the default value if none can be resolved
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 with no replacement
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
protected final void setSystemProperty(PropertyResolver resolver, String systemPropertyName, String propertyName,
|
||||
String defaultValue) {
|
||||
String value = resolver.getProperty(propertyName);
|
||||
value = (value != null) ? value : this.defaultValueResolver.apply(systemPropertyName);
|
||||
value = (value != null) ? value : defaultValue;
|
||||
setSystemProperty(systemPropertyName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a system property.
|
||||
* @param name the property name
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,57 +43,6 @@ public class LogbackLoggingSystemProperties extends LoggingSystemProperties {
|
||||
private static final boolean JBOSS_LOGGING_PRESENT = ClassUtils.isPresent("org.jboss.logging.Logger",
|
||||
LogbackLoggingSystemProperties.class.getClassLoader());
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the rolled-over log file name
|
||||
* pattern.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link RollingPolicySystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link RollingPolicySystemProperty#FILE_NAME_PATTERN}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String ROLLINGPOLICY_FILE_NAME_PATTERN = RollingPolicySystemProperty.FILE_NAME_PATTERN
|
||||
.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the clean history on start flag.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link RollingPolicySystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link RollingPolicySystemProperty#CLEAN_HISTORY_ON_START}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String ROLLINGPOLICY_CLEAN_HISTORY_ON_START = RollingPolicySystemProperty.CLEAN_HISTORY_ON_START
|
||||
.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the file log max size.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link RollingPolicySystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link RollingPolicySystemProperty#MAX_FILE_SIZE}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String ROLLINGPOLICY_MAX_FILE_SIZE = RollingPolicySystemProperty.MAX_FILE_SIZE
|
||||
.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the file total size cap.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link RollingPolicySystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link RollingPolicySystemProperty#TOTAL_SIZE_CAP}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String ROLLINGPOLICY_TOTAL_SIZE_CAP = RollingPolicySystemProperty.TOTAL_SIZE_CAP
|
||||
.getEnvironmentVariableName();
|
||||
|
||||
/**
|
||||
* The name of the System property that contains the file log max history.
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of calling
|
||||
* {@link RollingPolicySystemProperty#getEnvironmentVariableName()} on
|
||||
* {@link RollingPolicySystemProperty#MAX_HISTORY}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public static final String ROLLINGPOLICY_MAX_HISTORY = RollingPolicySystemProperty.MAX_HISTORY
|
||||
.getEnvironmentVariableName();
|
||||
|
||||
public LogbackLoggingSystemProperties(Environment environment) {
|
||||
super(environment);
|
||||
}
|
||||
|
||||
@@ -52,22 +52,7 @@ public class PemSslStoreBundle implements SslStoreBundle {
|
||||
* @param trustStoreDetails the trust store details
|
||||
*/
|
||||
public PemSslStoreBundle(PemSslStoreDetails keyStoreDetails, PemSslStoreDetails trustStoreDetails) {
|
||||
this(keyStoreDetails, trustStoreDetails, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link PemSslStoreBundle} instance.
|
||||
* @param keyStoreDetails the key store details
|
||||
* @param trustStoreDetails the trust store details
|
||||
* @param alias the alias to use or {@code null} to use a default alias
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of
|
||||
* {@link PemSslStoreDetails#alias()} in the {@code keyStoreDetails} and
|
||||
* {@code trustStoreDetails}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public PemSslStoreBundle(PemSslStoreDetails keyStoreDetails, PemSslStoreDetails trustStoreDetails, String alias) {
|
||||
this.keyStore = createKeyStore("key", PemSslStore.load(keyStoreDetails), alias);
|
||||
this.trustStore = createKeyStore("trust", PemSslStore.load(trustStoreDetails), alias);
|
||||
this(PemSslStore.load(keyStoreDetails), PemSslStore.load(trustStoreDetails));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,12 +62,8 @@ public class PemSslStoreBundle implements SslStoreBundle {
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public PemSslStoreBundle(PemSslStore pemKeyStore, PemSslStore pemTrustStore) {
|
||||
this(pemKeyStore, pemTrustStore, null);
|
||||
}
|
||||
|
||||
private PemSslStoreBundle(PemSslStore pemKeyStore, PemSslStore pemTrustStore, String alias) {
|
||||
this.keyStore = createKeyStore("key", pemKeyStore, alias);
|
||||
this.trustStore = createKeyStore("trust", pemTrustStore, alias);
|
||||
this.keyStore = createKeyStore("key", pemKeyStore);
|
||||
this.trustStore = createKeyStore("trust", pemTrustStore);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,14 +81,13 @@ public class PemSslStoreBundle implements SslStoreBundle {
|
||||
return this.trustStore;
|
||||
}
|
||||
|
||||
private static KeyStore createKeyStore(String name, PemSslStore pemSslStore, String alias) {
|
||||
private static KeyStore createKeyStore(String name, PemSslStore pemSslStore) {
|
||||
if (pemSslStore == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Assert.notEmpty(pemSslStore.certificates(), "Certificates must not be empty");
|
||||
alias = (pemSslStore.alias() != null) ? pemSslStore.alias() : alias;
|
||||
alias = (alias != null) ? alias : DEFAULT_ALIAS;
|
||||
String alias = (pemSslStore.alias() != null) ? pemSslStore.alias() : DEFAULT_ALIAS;
|
||||
KeyStore store = createKeyStore(pemSslStore.type());
|
||||
List<X509Certificate> certificates = pemSslStore.certificates();
|
||||
PrivateKey privateKey = pemSslStore.privateKey();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -89,16 +89,6 @@ public record PemSslStoreDetails(String type, String alias, String password, Str
|
||||
this(type, certificate, privateKey, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the certificate content.
|
||||
* @return the certificate content
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of {@link #certificates()}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public String certificate() {
|
||||
return certificates();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new {@link PemSslStoreDetails} instance with a new alias.
|
||||
* @param alias the new alias
|
||||
|
||||
@@ -1,330 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.task;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.core.task.TaskDecorator;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Builder that can be used to configure and create a {@link TaskExecutor}. Provides
|
||||
* convenience methods to set common {@link ThreadPoolTaskExecutor} settings and register
|
||||
* {@link #taskDecorator(TaskDecorator)}). For advanced configuration, consider using
|
||||
* {@link TaskExecutorCustomizer}.
|
||||
* <p>
|
||||
* In a typical auto-configured Spring Boot application this builder is available as a
|
||||
* bean and can be injected whenever a {@link TaskExecutor} is needed.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Filip Hrisafov
|
||||
* @since 2.1.0
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of
|
||||
* {@link ThreadPoolTaskExecutorBuilder}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public class TaskExecutorBuilder {
|
||||
|
||||
private final Integer queueCapacity;
|
||||
|
||||
private final Integer corePoolSize;
|
||||
|
||||
private final Integer maxPoolSize;
|
||||
|
||||
private final Boolean allowCoreThreadTimeOut;
|
||||
|
||||
private final Duration keepAlive;
|
||||
|
||||
private final Boolean awaitTermination;
|
||||
|
||||
private final Duration awaitTerminationPeriod;
|
||||
|
||||
private final String threadNamePrefix;
|
||||
|
||||
private final TaskDecorator taskDecorator;
|
||||
|
||||
private final Set<TaskExecutorCustomizer> customizers;
|
||||
|
||||
public TaskExecutorBuilder() {
|
||||
this.queueCapacity = null;
|
||||
this.corePoolSize = null;
|
||||
this.maxPoolSize = null;
|
||||
this.allowCoreThreadTimeOut = null;
|
||||
this.keepAlive = null;
|
||||
this.awaitTermination = null;
|
||||
this.awaitTerminationPeriod = null;
|
||||
this.threadNamePrefix = null;
|
||||
this.taskDecorator = null;
|
||||
this.customizers = null;
|
||||
}
|
||||
|
||||
private TaskExecutorBuilder(Integer queueCapacity, Integer corePoolSize, Integer maxPoolSize,
|
||||
Boolean allowCoreThreadTimeOut, Duration keepAlive, Boolean awaitTermination,
|
||||
Duration awaitTerminationPeriod, String threadNamePrefix, TaskDecorator taskDecorator,
|
||||
Set<TaskExecutorCustomizer> customizers) {
|
||||
this.queueCapacity = queueCapacity;
|
||||
this.corePoolSize = corePoolSize;
|
||||
this.maxPoolSize = maxPoolSize;
|
||||
this.allowCoreThreadTimeOut = allowCoreThreadTimeOut;
|
||||
this.keepAlive = keepAlive;
|
||||
this.awaitTermination = awaitTermination;
|
||||
this.awaitTerminationPeriod = awaitTerminationPeriod;
|
||||
this.threadNamePrefix = threadNamePrefix;
|
||||
this.taskDecorator = taskDecorator;
|
||||
this.customizers = customizers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the capacity of the queue. An unbounded capacity does not increase the pool and
|
||||
* therefore ignores {@link #maxPoolSize(int) maxPoolSize}.
|
||||
* @param queueCapacity the queue capacity to set
|
||||
* @return a new builder instance
|
||||
*/
|
||||
public TaskExecutorBuilder queueCapacity(int queueCapacity) {
|
||||
return new TaskExecutorBuilder(queueCapacity, this.corePoolSize, this.maxPoolSize, this.allowCoreThreadTimeOut,
|
||||
this.keepAlive, this.awaitTermination, this.awaitTerminationPeriod, this.threadNamePrefix,
|
||||
this.taskDecorator, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the core number of threads. Effectively that maximum number of threads as long
|
||||
* as the queue is not full.
|
||||
* <p>
|
||||
* Core threads can grow and shrink if {@link #allowCoreThreadTimeOut(boolean)} is
|
||||
* enabled.
|
||||
* @param corePoolSize the core pool size to set
|
||||
* @return a new builder instance
|
||||
*/
|
||||
public TaskExecutorBuilder corePoolSize(int corePoolSize) {
|
||||
return new TaskExecutorBuilder(this.queueCapacity, corePoolSize, this.maxPoolSize, this.allowCoreThreadTimeOut,
|
||||
this.keepAlive, this.awaitTermination, this.awaitTerminationPeriod, this.threadNamePrefix,
|
||||
this.taskDecorator, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum allowed number of threads. When the {@link #queueCapacity(int)
|
||||
* queue} is full, the pool can expand up to that size to accommodate the load.
|
||||
* <p>
|
||||
* If the {@link #queueCapacity(int) queue capacity} is unbounded, this setting is
|
||||
* ignored.
|
||||
* @param maxPoolSize the max pool size to set
|
||||
* @return a new builder instance
|
||||
*/
|
||||
public TaskExecutorBuilder maxPoolSize(int maxPoolSize) {
|
||||
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize, maxPoolSize, this.allowCoreThreadTimeOut,
|
||||
this.keepAlive, this.awaitTermination, this.awaitTerminationPeriod, this.threadNamePrefix,
|
||||
this.taskDecorator, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether core threads are allowed to time out. When enabled, this enables
|
||||
* dynamic growing and shrinking of the pool.
|
||||
* @param allowCoreThreadTimeOut if core threads are allowed to time out
|
||||
* @return a new builder instance
|
||||
*/
|
||||
public TaskExecutorBuilder allowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) {
|
||||
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize, this.maxPoolSize, allowCoreThreadTimeOut,
|
||||
this.keepAlive, this.awaitTermination, this.awaitTerminationPeriod, this.threadNamePrefix,
|
||||
this.taskDecorator, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the time limit for which threads may remain idle before being terminated.
|
||||
* @param keepAlive the keep alive to set
|
||||
* @return a new builder instance
|
||||
*/
|
||||
public TaskExecutorBuilder keepAlive(Duration keepAlive) {
|
||||
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize, this.maxPoolSize,
|
||||
this.allowCoreThreadTimeOut, keepAlive, this.awaitTermination, this.awaitTerminationPeriod,
|
||||
this.threadNamePrefix, this.taskDecorator, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the executor should wait for scheduled tasks to complete on shutdown,
|
||||
* not interrupting running tasks and executing all tasks in the queue.
|
||||
* @param awaitTermination whether the executor needs to wait for the tasks to
|
||||
* complete on shutdown
|
||||
* @return a new builder instance
|
||||
* @see #awaitTerminationPeriod(Duration)
|
||||
*/
|
||||
public TaskExecutorBuilder awaitTermination(boolean awaitTermination) {
|
||||
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize, this.maxPoolSize,
|
||||
this.allowCoreThreadTimeOut, this.keepAlive, awaitTermination, this.awaitTerminationPeriod,
|
||||
this.threadNamePrefix, this.taskDecorator, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum time the executor is supposed to block on shutdown. When set, the
|
||||
* executor blocks on shutdown in order to wait for remaining tasks to complete their
|
||||
* execution before the rest of the container continues to shut down. This is
|
||||
* particularly useful if your remaining tasks are likely to need access to other
|
||||
* resources that are also managed by the container.
|
||||
* @param awaitTerminationPeriod the await termination period to set
|
||||
* @return a new builder instance
|
||||
*/
|
||||
public TaskExecutorBuilder awaitTerminationPeriod(Duration awaitTerminationPeriod) {
|
||||
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize, this.maxPoolSize,
|
||||
this.allowCoreThreadTimeOut, this.keepAlive, this.awaitTermination, awaitTerminationPeriod,
|
||||
this.threadNamePrefix, this.taskDecorator, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the prefix to use for the names of newly created threads.
|
||||
* @param threadNamePrefix the thread name prefix to set
|
||||
* @return a new builder instance
|
||||
*/
|
||||
public TaskExecutorBuilder threadNamePrefix(String threadNamePrefix) {
|
||||
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize, this.maxPoolSize,
|
||||
this.allowCoreThreadTimeOut, this.keepAlive, this.awaitTermination, this.awaitTerminationPeriod,
|
||||
threadNamePrefix, this.taskDecorator, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link TaskDecorator} to use or {@code null} to not use any.
|
||||
* @param taskDecorator the task decorator to use
|
||||
* @return a new builder instance
|
||||
*/
|
||||
public TaskExecutorBuilder taskDecorator(TaskDecorator taskDecorator) {
|
||||
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize, this.maxPoolSize,
|
||||
this.allowCoreThreadTimeOut, this.keepAlive, this.awaitTermination, this.awaitTerminationPeriod,
|
||||
this.threadNamePrefix, taskDecorator, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link TaskExecutorCustomizer TaskExecutorCustomizers} that should be
|
||||
* applied to the {@link ThreadPoolTaskExecutor}. Customizers are applied in the order
|
||||
* that they were added after builder configuration has been applied. Setting this
|
||||
* value will replace any previously configured customizers.
|
||||
* @param customizers the customizers to set
|
||||
* @return a new builder instance
|
||||
* @see #additionalCustomizers(TaskExecutorCustomizer...)
|
||||
*/
|
||||
public TaskExecutorBuilder customizers(TaskExecutorCustomizer... customizers) {
|
||||
Assert.notNull(customizers, "Customizers must not be null");
|
||||
return customizers(Arrays.asList(customizers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link TaskExecutorCustomizer TaskExecutorCustomizers} that should be
|
||||
* applied to the {@link ThreadPoolTaskExecutor}. Customizers are applied in the order
|
||||
* that they were added after builder configuration has been applied. Setting this
|
||||
* value will replace any previously configured customizers.
|
||||
* @param customizers the customizers to set
|
||||
* @return a new builder instance
|
||||
* @see #additionalCustomizers(TaskExecutorCustomizer...)
|
||||
*/
|
||||
public TaskExecutorBuilder customizers(Iterable<TaskExecutorCustomizer> customizers) {
|
||||
Assert.notNull(customizers, "Customizers must not be null");
|
||||
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize, this.maxPoolSize,
|
||||
this.allowCoreThreadTimeOut, this.keepAlive, this.awaitTermination, this.awaitTerminationPeriod,
|
||||
this.threadNamePrefix, this.taskDecorator, append(null, customizers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {@link TaskExecutorCustomizer TaskExecutorCustomizers} that should be applied
|
||||
* to the {@link ThreadPoolTaskExecutor}. Customizers are applied in the order that
|
||||
* they were added after builder configuration has been applied.
|
||||
* @param customizers the customizers to add
|
||||
* @return a new builder instance
|
||||
* @see #customizers(TaskExecutorCustomizer...)
|
||||
*/
|
||||
public TaskExecutorBuilder additionalCustomizers(TaskExecutorCustomizer... customizers) {
|
||||
Assert.notNull(customizers, "Customizers must not be null");
|
||||
return additionalCustomizers(Arrays.asList(customizers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {@link TaskExecutorCustomizer TaskExecutorCustomizers} that should be applied
|
||||
* to the {@link ThreadPoolTaskExecutor}. Customizers are applied in the order that
|
||||
* they were added after builder configuration has been applied.
|
||||
* @param customizers the customizers to add
|
||||
* @return a new builder instance
|
||||
* @see #customizers(TaskExecutorCustomizer...)
|
||||
*/
|
||||
public TaskExecutorBuilder additionalCustomizers(Iterable<TaskExecutorCustomizer> customizers) {
|
||||
Assert.notNull(customizers, "Customizers must not be null");
|
||||
return new TaskExecutorBuilder(this.queueCapacity, this.corePoolSize, this.maxPoolSize,
|
||||
this.allowCoreThreadTimeOut, this.keepAlive, this.awaitTermination, this.awaitTerminationPeriod,
|
||||
this.threadNamePrefix, this.taskDecorator, append(this.customizers, customizers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new {@link ThreadPoolTaskExecutor} instance and configure it using this
|
||||
* builder.
|
||||
* @return a configured {@link ThreadPoolTaskExecutor} instance.
|
||||
* @see #build(Class)
|
||||
* @see #configure(ThreadPoolTaskExecutor)
|
||||
*/
|
||||
public ThreadPoolTaskExecutor build() {
|
||||
return configure(new ThreadPoolTaskExecutor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new {@link ThreadPoolTaskExecutor} instance of the specified type and
|
||||
* configure it using this builder.
|
||||
* @param <T> the type of task executor
|
||||
* @param taskExecutorClass the template type to create
|
||||
* @return a configured {@link ThreadPoolTaskExecutor} instance.
|
||||
* @see #build()
|
||||
* @see #configure(ThreadPoolTaskExecutor)
|
||||
*/
|
||||
public <T extends ThreadPoolTaskExecutor> T build(Class<T> taskExecutorClass) {
|
||||
return configure(BeanUtils.instantiateClass(taskExecutorClass));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the provided {@link ThreadPoolTaskExecutor} instance using this builder.
|
||||
* @param <T> the type of task executor
|
||||
* @param taskExecutor the {@link ThreadPoolTaskExecutor} to configure
|
||||
* @return the task executor instance
|
||||
* @see #build()
|
||||
* @see #build(Class)
|
||||
*/
|
||||
public <T extends ThreadPoolTaskExecutor> T configure(T taskExecutor) {
|
||||
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
||||
map.from(this.queueCapacity).to(taskExecutor::setQueueCapacity);
|
||||
map.from(this.corePoolSize).to(taskExecutor::setCorePoolSize);
|
||||
map.from(this.maxPoolSize).to(taskExecutor::setMaxPoolSize);
|
||||
map.from(this.keepAlive).asInt(Duration::getSeconds).to(taskExecutor::setKeepAliveSeconds);
|
||||
map.from(this.allowCoreThreadTimeOut).to(taskExecutor::setAllowCoreThreadTimeOut);
|
||||
map.from(this.awaitTermination).to(taskExecutor::setWaitForTasksToCompleteOnShutdown);
|
||||
map.from(this.awaitTerminationPeriod).as(Duration::toMillis).to(taskExecutor::setAwaitTerminationMillis);
|
||||
map.from(this.threadNamePrefix).whenHasText().to(taskExecutor::setThreadNamePrefix);
|
||||
map.from(this.taskDecorator).to(taskExecutor::setTaskDecorator);
|
||||
if (!CollectionUtils.isEmpty(this.customizers)) {
|
||||
this.customizers.forEach((customizer) -> customizer.customize(taskExecutor));
|
||||
}
|
||||
return taskExecutor;
|
||||
}
|
||||
|
||||
private <T> Set<T> append(Set<T> set, Iterable<? extends T> additions) {
|
||||
Set<T> result = new LinkedHashSet<>((set != null) ? set : Collections.emptySet());
|
||||
additions.forEach(result::add);
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.task;
|
||||
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
/**
|
||||
* Callback interface that can be used to customize a {@link ThreadPoolTaskExecutor}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.1.0
|
||||
* @see TaskExecutorBuilder
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of
|
||||
* {@link ThreadPoolTaskExecutorCustomizer}
|
||||
*/
|
||||
@FunctionalInterface
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public interface TaskExecutorCustomizer {
|
||||
|
||||
/**
|
||||
* Callback to customize a {@link ThreadPoolTaskExecutor} instance.
|
||||
* @param taskExecutor the task executor to customize
|
||||
*/
|
||||
void customize(ThreadPoolTaskExecutor taskExecutor);
|
||||
|
||||
}
|
||||
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.task;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.boot.context.properties.PropertyMapper;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Builder that can be used to configure and create a {@link TaskScheduler}. Provides
|
||||
* convenience methods to set common {@link ThreadPoolTaskScheduler} settings. For
|
||||
* advanced configuration, consider using {@link TaskSchedulerCustomizer}.
|
||||
* <p>
|
||||
* In a typical auto-configured Spring Boot application this builder is available as a
|
||||
* bean and can be injected whenever a {@link TaskScheduler} is needed.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.1.0
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of
|
||||
* {@link ThreadPoolTaskSchedulerBuilder}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
public class TaskSchedulerBuilder {
|
||||
|
||||
private final Integer poolSize;
|
||||
|
||||
private final Boolean awaitTermination;
|
||||
|
||||
private final Duration awaitTerminationPeriod;
|
||||
|
||||
private final String threadNamePrefix;
|
||||
|
||||
private final Set<TaskSchedulerCustomizer> customizers;
|
||||
|
||||
public TaskSchedulerBuilder() {
|
||||
this.poolSize = null;
|
||||
this.awaitTermination = null;
|
||||
this.awaitTerminationPeriod = null;
|
||||
this.threadNamePrefix = null;
|
||||
this.customizers = null;
|
||||
}
|
||||
|
||||
public TaskSchedulerBuilder(Integer poolSize, Boolean awaitTermination, Duration awaitTerminationPeriod,
|
||||
String threadNamePrefix, Set<TaskSchedulerCustomizer> taskSchedulerCustomizers) {
|
||||
this.poolSize = poolSize;
|
||||
this.awaitTermination = awaitTermination;
|
||||
this.awaitTerminationPeriod = awaitTerminationPeriod;
|
||||
this.threadNamePrefix = threadNamePrefix;
|
||||
this.customizers = taskSchedulerCustomizers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum allowed number of threads.
|
||||
* @param poolSize the pool size to set
|
||||
* @return a new builder instance
|
||||
*/
|
||||
public TaskSchedulerBuilder poolSize(int poolSize) {
|
||||
return new TaskSchedulerBuilder(poolSize, this.awaitTermination, this.awaitTerminationPeriod,
|
||||
this.threadNamePrefix, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the executor should wait for scheduled tasks to complete on shutdown,
|
||||
* not interrupting running tasks and executing all tasks in the queue.
|
||||
* @param awaitTermination whether the executor needs to wait for the tasks to
|
||||
* complete on shutdown
|
||||
* @return a new builder instance
|
||||
* @see #awaitTerminationPeriod(Duration)
|
||||
*/
|
||||
public TaskSchedulerBuilder awaitTermination(boolean awaitTermination) {
|
||||
return new TaskSchedulerBuilder(this.poolSize, awaitTermination, this.awaitTerminationPeriod,
|
||||
this.threadNamePrefix, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum time the executor is supposed to block on shutdown. When set, the
|
||||
* executor blocks on shutdown in order to wait for remaining tasks to complete their
|
||||
* execution before the rest of the container continues to shut down. This is
|
||||
* particularly useful if your remaining tasks are likely to need access to other
|
||||
* resources that are also managed by the container.
|
||||
* @param awaitTerminationPeriod the await termination period to set
|
||||
* @return a new builder instance
|
||||
*/
|
||||
public TaskSchedulerBuilder awaitTerminationPeriod(Duration awaitTerminationPeriod) {
|
||||
return new TaskSchedulerBuilder(this.poolSize, this.awaitTermination, awaitTerminationPeriod,
|
||||
this.threadNamePrefix, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the prefix to use for the names of newly created threads.
|
||||
* @param threadNamePrefix the thread name prefix to set
|
||||
* @return a new builder instance
|
||||
*/
|
||||
public TaskSchedulerBuilder threadNamePrefix(String threadNamePrefix) {
|
||||
return new TaskSchedulerBuilder(this.poolSize, this.awaitTermination, this.awaitTerminationPeriod,
|
||||
threadNamePrefix, this.customizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link TaskSchedulerCustomizer TaskSchedulerCustomizers} that should be
|
||||
* applied to the {@link ThreadPoolTaskScheduler}. Customizers are applied in the
|
||||
* order that they were added after builder configuration has been applied. Setting
|
||||
* this value will replace any previously configured customizers.
|
||||
* @param customizers the customizers to set
|
||||
* @return a new builder instance
|
||||
* @see #additionalCustomizers(TaskSchedulerCustomizer...)
|
||||
*/
|
||||
public TaskSchedulerBuilder customizers(TaskSchedulerCustomizer... customizers) {
|
||||
Assert.notNull(customizers, "Customizers must not be null");
|
||||
return customizers(Arrays.asList(customizers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link TaskSchedulerCustomizer taskSchedulerCustomizers} that should be
|
||||
* applied to the {@link ThreadPoolTaskScheduler}. Customizers are applied in the
|
||||
* order that they were added after builder configuration has been applied. Setting
|
||||
* this value will replace any previously configured customizers.
|
||||
* @param customizers the customizers to set
|
||||
* @return a new builder instance
|
||||
* @see #additionalCustomizers(TaskSchedulerCustomizer...)
|
||||
*/
|
||||
public TaskSchedulerBuilder customizers(Iterable<TaskSchedulerCustomizer> customizers) {
|
||||
Assert.notNull(customizers, "Customizers must not be null");
|
||||
return new TaskSchedulerBuilder(this.poolSize, this.awaitTermination, this.awaitTerminationPeriod,
|
||||
this.threadNamePrefix, append(null, customizers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {@link TaskSchedulerCustomizer taskSchedulerCustomizers} that should be applied
|
||||
* to the {@link ThreadPoolTaskScheduler}. Customizers are applied in the order that
|
||||
* they were added after builder configuration has been applied.
|
||||
* @param customizers the customizers to add
|
||||
* @return a new builder instance
|
||||
* @see #customizers(TaskSchedulerCustomizer...)
|
||||
*/
|
||||
public TaskSchedulerBuilder additionalCustomizers(TaskSchedulerCustomizer... customizers) {
|
||||
Assert.notNull(customizers, "Customizers must not be null");
|
||||
return additionalCustomizers(Arrays.asList(customizers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {@link TaskSchedulerCustomizer taskSchedulerCustomizers} that should be applied
|
||||
* to the {@link ThreadPoolTaskScheduler}. Customizers are applied in the order that
|
||||
* they were added after builder configuration has been applied.
|
||||
* @param customizers the customizers to add
|
||||
* @return a new builder instance
|
||||
* @see #customizers(TaskSchedulerCustomizer...)
|
||||
*/
|
||||
public TaskSchedulerBuilder additionalCustomizers(Iterable<TaskSchedulerCustomizer> customizers) {
|
||||
Assert.notNull(customizers, "Customizers must not be null");
|
||||
return new TaskSchedulerBuilder(this.poolSize, this.awaitTermination, this.awaitTerminationPeriod,
|
||||
this.threadNamePrefix, append(this.customizers, customizers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a new {@link ThreadPoolTaskScheduler} instance and configure it using this
|
||||
* builder.
|
||||
* @return a configured {@link ThreadPoolTaskScheduler} instance.
|
||||
* @see #configure(ThreadPoolTaskScheduler)
|
||||
*/
|
||||
public ThreadPoolTaskScheduler build() {
|
||||
return configure(new ThreadPoolTaskScheduler());
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the provided {@link ThreadPoolTaskScheduler} instance using this builder.
|
||||
* @param <T> the type of task scheduler
|
||||
* @param taskScheduler the {@link ThreadPoolTaskScheduler} to configure
|
||||
* @return the task scheduler instance
|
||||
* @see #build()
|
||||
*/
|
||||
public <T extends ThreadPoolTaskScheduler> T configure(T taskScheduler) {
|
||||
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
||||
map.from(this.poolSize).to(taskScheduler::setPoolSize);
|
||||
map.from(this.awaitTermination).to(taskScheduler::setWaitForTasksToCompleteOnShutdown);
|
||||
map.from(this.awaitTerminationPeriod).asInt(Duration::getSeconds).to(taskScheduler::setAwaitTerminationSeconds);
|
||||
map.from(this.threadNamePrefix).to(taskScheduler::setThreadNamePrefix);
|
||||
if (!CollectionUtils.isEmpty(this.customizers)) {
|
||||
this.customizers.forEach((customizer) -> customizer.customize(taskScheduler));
|
||||
}
|
||||
return taskScheduler;
|
||||
}
|
||||
|
||||
private <T> Set<T> append(Set<T> set, Iterable<? extends T> additions) {
|
||||
Set<T> result = new LinkedHashSet<>((set != null) ? set : Collections.emptySet());
|
||||
additions.forEach(result::add);
|
||||
return Collections.unmodifiableSet(result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.task;
|
||||
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
/**
|
||||
* Callback interface that can be used to customize a {@link ThreadPoolTaskScheduler}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.1.0
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of
|
||||
* {@link ThreadPoolTaskSchedulerCustomizer}
|
||||
*/
|
||||
@FunctionalInterface
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public interface TaskSchedulerCustomizer {
|
||||
|
||||
/**
|
||||
* Callback to customize a {@link ThreadPoolTaskScheduler} instance.
|
||||
* @param taskScheduler the task scheduler to customize
|
||||
*/
|
||||
void customize(ThreadPoolTaskScheduler taskScheduler);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,36 +40,7 @@ public record ClientHttpRequestFactorySettings(Duration connectTimeout, Duration
|
||||
* the implementation.
|
||||
*/
|
||||
public static final ClientHttpRequestFactorySettings DEFAULTS = new ClientHttpRequestFactorySettings(null, null,
|
||||
null, null);
|
||||
|
||||
/**
|
||||
* Create a new {@link ClientHttpRequestFactorySettings} instance.
|
||||
* @param connectTimeout the connection timeout
|
||||
* @param readTimeout the read timeout
|
||||
* @param bufferRequestBody if request body buffering is used
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 as support for buffering has been
|
||||
* removed in Spring Framework 6.1
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public ClientHttpRequestFactorySettings(Duration connectTimeout, Duration readTimeout, Boolean bufferRequestBody) {
|
||||
this(connectTimeout, readTimeout, (SslBundle) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ClientHttpRequestFactorySettings} instance.
|
||||
* @param connectTimeout the connection timeout
|
||||
* @param readTimeout the read timeout
|
||||
* @param bufferRequestBody if request body buffering is used
|
||||
* @param sslBundle the ssl bundle
|
||||
* @since 3.1.0
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 as support for buffering has been
|
||||
* removed in Spring Framework 6.1
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public ClientHttpRequestFactorySettings(Duration connectTimeout, Duration readTimeout, Boolean bufferRequestBody,
|
||||
SslBundle sslBundle) {
|
||||
this(connectTimeout, readTimeout, sslBundle);
|
||||
}
|
||||
null);
|
||||
|
||||
/**
|
||||
* Return a new {@link ClientHttpRequestFactorySettings} instance with an updated
|
||||
@@ -92,18 +63,6 @@ public record ClientHttpRequestFactorySettings(Duration connectTimeout, Duration
|
||||
return new ClientHttpRequestFactorySettings(this.connectTimeout, readTimeout, this.sslBundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Has no effect as support for buffering has been removed in Spring Framework 6.1.
|
||||
* @param bufferRequestBody the new buffer request body setting
|
||||
* @return a new {@link ClientHttpRequestFactorySettings} instance
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 as support for buffering has been
|
||||
* removed in Spring Framework 6.1
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public ClientHttpRequestFactorySettings withBufferRequestBody(Boolean bufferRequestBody) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new {@link ClientHttpRequestFactorySettings} instance with an updated SSL
|
||||
* bundle setting.
|
||||
@@ -115,15 +74,4 @@ public record ClientHttpRequestFactorySettings(Duration connectTimeout, Duration
|
||||
return new ClientHttpRequestFactorySettings(this.connectTimeout, this.readTimeout, sslBundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether request body buffering is used.
|
||||
* @return whether request body buffering is used
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 as support for buffering has been
|
||||
* removed in Spring Framework 6.1
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public Boolean bufferRequestBody() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,8 +35,6 @@ import org.springframework.boot.ssl.SslBundle;
|
||||
import org.springframework.http.client.ClientHttpRequest;
|
||||
import org.springframework.http.client.ClientHttpRequestFactory;
|
||||
import org.springframework.http.client.ClientHttpRequestInterceptor;
|
||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -436,21 +434,6 @@ public class RestTemplateBuilder {
|
||||
this.customizers, this.requestCustomizers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Has no effect as support for buffering has been removed in Spring Framework 6.1.
|
||||
* @param bufferRequestBody value of the bufferRequestBody parameter
|
||||
* @return a new builder instance.
|
||||
* @since 2.2.0
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 as support for buffering has been
|
||||
* removed in Spring Framework 6.1
|
||||
* @see SimpleClientHttpRequestFactory#setBufferRequestBody(boolean)
|
||||
* @see HttpComponentsClientHttpRequestFactory#setBufferRequestBody(boolean)
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public RestTemplateBuilder setBufferRequestBody(boolean bufferRequestBody) {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SSL bundle on the underlying {@link ClientHttpRequestFactory}.
|
||||
* @param sslBundle the SSL bundle
|
||||
|
||||
@@ -31,12 +31,6 @@ import org.springframework.web.util.UriTemplateHandler;
|
||||
*/
|
||||
public class RootUriBuilderFactory extends RootUriTemplateHandler implements UriBuilderFactory {
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
RootUriBuilderFactory(String rootUri) {
|
||||
super(rootUri);
|
||||
}
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
RootUriBuilderFactory(String rootUri, UriTemplateHandler delegate) {
|
||||
super(rootUri, delegate);
|
||||
}
|
||||
|
||||
@@ -18,12 +18,9 @@ package org.springframework.boot.web.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
import org.springframework.web.util.UriTemplateHandler;
|
||||
|
||||
/**
|
||||
@@ -45,24 +42,7 @@ public class RootUriTemplateHandler implements UriTemplateHandler {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link RootUriTemplateHandler} instance.
|
||||
* @param rootUri the root URI to be used to prefix relative URLs
|
||||
* @deprecated since 3.2.3 for removal in 3.4.0, with no replacement
|
||||
*/
|
||||
@Deprecated(since = "3.2.3", forRemoval = true)
|
||||
public RootUriTemplateHandler(String rootUri) {
|
||||
this(rootUri, new DefaultUriBuilderFactory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link RootUriTemplateHandler} instance.
|
||||
* @param rootUri the root URI to be used to prefix relative URLs
|
||||
* @param handler the handler handler
|
||||
* @deprecated since 3.2.3 for removal in 3.4.0, with no replacement
|
||||
*/
|
||||
@Deprecated(since = "3.2.3", forRemoval = true)
|
||||
public RootUriTemplateHandler(String rootUri, UriTemplateHandler handler) {
|
||||
RootUriTemplateHandler(String rootUri, UriTemplateHandler handler) {
|
||||
Assert.notNull(rootUri, "RootUri must not be null");
|
||||
Assert.notNull(handler, "Handler must not be null");
|
||||
this.rootUri = rootUri;
|
||||
@@ -90,32 +70,4 @@ public class RootUriTemplateHandler implements UriTemplateHandler {
|
||||
return this.rootUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Derives a new {@code RootUriTemplateHandler} from this one, wrapping its delegate
|
||||
* {@link UriTemplateHandler} by applying the given {@code wrapper}.
|
||||
* @param wrapper the wrapper to apply to the delegate URI template handler
|
||||
* @return the new handler
|
||||
* @since 2.3.10
|
||||
* @deprecated since 3.2.3 for removal in 3.4.0, with no replacement
|
||||
*/
|
||||
@Deprecated(since = "3.2.3", forRemoval = true)
|
||||
public RootUriTemplateHandler withHandlerWrapper(Function<UriTemplateHandler, UriTemplateHandler> wrapper) {
|
||||
return new RootUriTemplateHandler(getRootUri(), wrapper.apply(this.handler));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a {@link RootUriTemplateHandler} instance to the given {@link RestTemplate}.
|
||||
* @param restTemplate the {@link RestTemplate} to add the handler to
|
||||
* @param rootUri the root URI
|
||||
* @return the added {@link RootUriTemplateHandler}.
|
||||
* @deprecated since 3.2.3 for removal in 3.4.0, with no replacement
|
||||
*/
|
||||
@Deprecated(since = "3.2.3", forRemoval = true)
|
||||
public static RootUriTemplateHandler addTo(RestTemplate restTemplate, String rootUri) {
|
||||
Assert.notNull(restTemplate, "RestTemplate must not be null");
|
||||
RootUriTemplateHandler handler = new RootUriTemplateHandler(rootUri, restTemplate.getUriTemplateHandler());
|
||||
restTemplate.setUriTemplateHandler(handler);
|
||||
return handler;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -82,21 +82,6 @@ public class NettyWebServer implements WebServer {
|
||||
|
||||
private volatile DisposableServer disposableServer;
|
||||
|
||||
/**
|
||||
* Creates a new {@code NettyWebServer} instance.
|
||||
* @param httpServer the HTTP server
|
||||
* @param handlerAdapter the handler adapter
|
||||
* @param lifecycleTimeout the lifecycle timeout, may be {@code null}
|
||||
* @param shutdown the shutdown, may be {@code null}
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of
|
||||
* {@link #NettyWebServer(HttpServer, ReactorHttpHandlerAdapter, Duration, Shutdown, ReactorResourceFactory)}
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
public NettyWebServer(HttpServer httpServer, ReactorHttpHandlerAdapter handlerAdapter, Duration lifecycleTimeout,
|
||||
Shutdown shutdown) {
|
||||
this(httpServer, handlerAdapter, lifecycleTimeout, shutdown, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code NettyWebServer} instance.
|
||||
* @param httpServer the HTTP server
|
||||
|
||||
@@ -106,17 +106,6 @@ public class SslServerCustomizer implements NettyServerCustomizer {
|
||||
return SslProvider.builder().sslContext((GenericSslContextSpec<?>) createSslContextSpec(sslBundle)).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method used to create an {@link AbstractProtocolSslContextSpec}.
|
||||
* @return the {@link AbstractProtocolSslContextSpec} to use
|
||||
* @deprecated since 3.2.0 for removal in 3.4.0 in favor of
|
||||
* {@link #createSslContextSpec(SslBundle)}
|
||||
*/
|
||||
@Deprecated(since = "3.2", forRemoval = true)
|
||||
protected AbstractProtocolSslContextSpec<?> createSslContextSpec() {
|
||||
return createSslContextSpec(this.sslBundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an {@link AbstractProtocolSslContextSpec} for a given {@link SslBundle}.
|
||||
* @param sslBundle the {@link SslBundle} to use
|
||||
|
||||
@@ -36,7 +36,6 @@ org.springframework.boot.diagnostics.FailureAnalyzers
|
||||
org.springframework.context.ApplicationContextInitializer=\
|
||||
org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\
|
||||
org.springframework.boot.context.ContextIdApplicationContextInitializer,\
|
||||
org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\
|
||||
org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer,\
|
||||
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
|
||||
|
||||
@@ -46,7 +45,6 @@ org.springframework.boot.ClearCachesApplicationListener,\
|
||||
org.springframework.boot.builder.ParentContextCloserApplicationListener,\
|
||||
org.springframework.boot.context.FileEncodingApplicationListener,\
|
||||
org.springframework.boot.context.config.AnsiOutputApplicationListener,\
|
||||
org.springframework.boot.context.config.DelegatingApplicationListener,\
|
||||
org.springframework.boot.context.logging.LoggingApplicationListener,\
|
||||
org.springframework.boot.env.EnvironmentPostProcessorApplicationListener
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -265,7 +265,7 @@ class SpringApplicationBuilderTests {
|
||||
SpringApplicationBuilder application = new SpringApplicationBuilder(ExampleConfig.class)
|
||||
.web(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(application.application().getInitializers()).hasSize(5);
|
||||
assertThat(application.application().getInitializers()).hasSize(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,7 +274,7 @@ class SpringApplicationBuilderTests {
|
||||
.child(ChildConfig.class)
|
||||
.web(WebApplicationType.NONE);
|
||||
this.context = application.run();
|
||||
assertThat(application.application().getInitializers()).hasSize(6);
|
||||
assertThat(application.application().getInitializers()).hasSize(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -284,7 +284,7 @@ class SpringApplicationBuilderTests {
|
||||
.initializers((ConfigurableApplicationContext applicationContext) -> {
|
||||
});
|
||||
this.context = application.run();
|
||||
assertThat(application.application().getInitializers()).hasSize(6);
|
||||
assertThat(application.application().getInitializers()).hasSize(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.context.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.test.context.support.TestPropertySourceUtils;
|
||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link DelegatingApplicationContextInitializer}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
class DelegatingApplicationContextInitializerTests {
|
||||
|
||||
private final DelegatingApplicationContextInitializer initializer = new DelegatingApplicationContextInitializer();
|
||||
|
||||
@Test
|
||||
void orderedInitialize() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context,
|
||||
"context.initializer.classes=" + MockInitB.class.getName() + "," + MockInitA.class.getName());
|
||||
this.initializer.initialize(context);
|
||||
assertThat(context.getBeanFactory().getSingleton("a")).isEqualTo("a");
|
||||
assertThat(context.getBeanFactory().getSingleton("b")).isEqualTo("b");
|
||||
}
|
||||
|
||||
@Test
|
||||
void noInitializers() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
this.initializer.initialize(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyInitializers() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context, "context.initializer.classes:");
|
||||
this.initializer.initialize(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
void noSuchInitializerClass() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context,
|
||||
"context.initializer.classes=missing.madeup.class");
|
||||
assertThatExceptionOfType(ApplicationContextException.class)
|
||||
.isThrownBy(() -> this.initializer.initialize(context));
|
||||
}
|
||||
|
||||
@Test
|
||||
void notAnInitializerClass() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context,
|
||||
"context.initializer.classes=" + Object.class.getName());
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.initializer.initialize(context));
|
||||
}
|
||||
|
||||
@Test
|
||||
void genericNotSuitable() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(context,
|
||||
"context.initializer.classes=" + NotSuitableInit.class.getName());
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.initializer.initialize(context))
|
||||
.withMessageContaining("generic parameter");
|
||||
}
|
||||
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
static class MockInitA implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
applicationContext.getBeanFactory().registerSingleton("a", "a");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||
static class MockInitB implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
assertThat(applicationContext.getBeanFactory().getSingleton("a")).isEqualTo("a");
|
||||
applicationContext.getBeanFactory().registerSingleton("b", "b");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class NotSuitableInit implements ApplicationContextInitializer<ConfigurableWebApplicationContext> {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableWebApplicationContext applicationContext) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.context.config;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.DefaultBootstrapContext;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.test.context.support.TestPropertySourceUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DelegatingApplicationListener}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@Deprecated(since = "3.2.0", forRemoval = true)
|
||||
@SuppressWarnings("removal")
|
||||
class DelegatingApplicationListenerTests {
|
||||
|
||||
private final DelegatingApplicationListener listener = new DelegatingApplicationListener();
|
||||
|
||||
private final StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
||||
@AfterEach
|
||||
void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void orderedInitialize() {
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
|
||||
"context.listener.classes=" + MockInitB.class.getName() + "," + MockInitA.class.getName());
|
||||
this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(new DefaultBootstrapContext(),
|
||||
new SpringApplication(), new String[0], this.context.getEnvironment()));
|
||||
this.context.getBeanFactory().registerSingleton("testListener", this.listener);
|
||||
this.context.refresh();
|
||||
assertThat(this.context.getBeanFactory().getSingleton("a")).isEqualTo("a");
|
||||
assertThat(this.context.getBeanFactory().getSingleton("b")).isEqualTo("b");
|
||||
}
|
||||
|
||||
@Test
|
||||
void noInitializers() {
|
||||
this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(new DefaultBootstrapContext(),
|
||||
new SpringApplication(), new String[0], this.context.getEnvironment()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyInitializers() {
|
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "context.listener.classes:");
|
||||
this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(new DefaultBootstrapContext(),
|
||||
new SpringApplication(), new String[0], this.context.getEnvironment()));
|
||||
}
|
||||
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
static class MockInitA implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) event
|
||||
.getApplicationContext();
|
||||
applicationContext.getBeanFactory().registerSingleton("a", "a");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||
static class MockInitB implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
ConfigurableApplicationContext applicationContext = (ConfigurableApplicationContext) event
|
||||
.getApplicationContext();
|
||||
assertThat(applicationContext.getBeanFactory().getSingleton("a")).isEqualTo("a");
|
||||
applicationContext.getBeanFactory().registerSingleton("b", "b");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,8 +17,6 @@
|
||||
package org.springframework.boot.logging.logback;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
@@ -30,6 +28,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogManager;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
@@ -69,7 +68,6 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -550,20 +548,20 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
||||
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
Map<String, String> properties = loggerContext.getCopyOfPropertyMap();
|
||||
Set<String> expectedProperties = new HashSet<>();
|
||||
ReflectionUtils.doWithFields(LogbackLoggingSystemProperties.class,
|
||||
(field) -> expectedProperties.add((String) field.get(null)), this::isPublicStaticFinal);
|
||||
expectedProperties.removeAll(Arrays.asList("LOG_FILE", "LOG_PATH"));
|
||||
Stream.of(RollingPolicySystemProperty.values())
|
||||
.map(RollingPolicySystemProperty::getEnvironmentVariableName)
|
||||
.forEach(expectedProperties::add);
|
||||
Stream.of(LoggingSystemProperty.values())
|
||||
.map(LoggingSystemProperty::getEnvironmentVariableName)
|
||||
.forEach(expectedProperties::add);
|
||||
expectedProperties
|
||||
.removeAll(Arrays.asList("LOG_FILE", "LOG_PATH", "LOGGED_APPLICATION_NAME", "LOGGED_APPLICATION_GROUP"));
|
||||
expectedProperties.add("org.jboss.logging.provider");
|
||||
expectedProperties.add("LOG_CORRELATION_PATTERN");
|
||||
assertThat(properties).containsOnlyKeys(expectedProperties);
|
||||
assertThat(properties).containsEntry("CONSOLE_LOG_CHARSET", Charset.defaultCharset().name());
|
||||
}
|
||||
|
||||
private boolean isPublicStaticFinal(Field field) {
|
||||
int modifiers = field.getModifiers();
|
||||
return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers);
|
||||
}
|
||||
|
||||
@Test
|
||||
void initializationIsOnlyPerformedOnceUntilCleanedUp() {
|
||||
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -167,18 +167,6 @@ class PemSslStoreBundleTests {
|
||||
assertThat(bundle.getTrustStore()).satisfies(storeContainingCertAndKey("ssl"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("removal")
|
||||
void createWithDetailsWhenHasKeyStoreDetailsAndTrustStoreDetailsAndAlias() {
|
||||
PemSslStoreDetails keyStoreDetails = PemSslStoreDetails.forCertificate("classpath:test-cert.pem")
|
||||
.withPrivateKey("classpath:test-key.pem");
|
||||
PemSslStoreDetails trustStoreDetails = PemSslStoreDetails.forCertificate("classpath:test-cert.pem")
|
||||
.withPrivateKey("classpath:test-key.pem");
|
||||
PemSslStoreBundle bundle = new PemSslStoreBundle(keyStoreDetails, trustStoreDetails, "test-alias");
|
||||
assertThat(bundle.getKeyStore()).satisfies(storeContainingCertAndKey("test-alias"));
|
||||
assertThat(bundle.getTrustStore()).satisfies(storeContainingCertAndKey("test-alias"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWithDetailsWhenHasStoreType() {
|
||||
PemSslStoreDetails keyStoreDetails = new PemSslStoreDetails("PKCS12", "classpath:test-cert.pem",
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.task;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.task.TaskDecorator;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
/**
|
||||
* Tests for {@link TaskExecutorBuilder}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
class TaskExecutorBuilderTests {
|
||||
|
||||
private final TaskExecutorBuilder builder = new TaskExecutorBuilder();
|
||||
|
||||
@Test
|
||||
void poolSettingsShouldApply() {
|
||||
ThreadPoolTaskExecutor executor = this.builder.queueCapacity(10)
|
||||
.corePoolSize(4)
|
||||
.maxPoolSize(8)
|
||||
.allowCoreThreadTimeOut(true)
|
||||
.keepAlive(Duration.ofMinutes(1))
|
||||
.build();
|
||||
assertThat(executor).hasFieldOrPropertyWithValue("queueCapacity", 10);
|
||||
assertThat(executor.getCorePoolSize()).isEqualTo(4);
|
||||
assertThat(executor.getMaxPoolSize()).isEqualTo(8);
|
||||
assertThat(executor).hasFieldOrPropertyWithValue("allowCoreThreadTimeOut", true);
|
||||
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
|
||||
}
|
||||
|
||||
@Test
|
||||
void awaitTerminationShouldApply() {
|
||||
ThreadPoolTaskExecutor executor = this.builder.awaitTermination(true).build();
|
||||
assertThat(executor).hasFieldOrPropertyWithValue("waitForTasksToCompleteOnShutdown", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void awaitTerminationPeriodShouldApplyWithMillisecondPrecision() {
|
||||
Duration period = Duration.ofMillis(50);
|
||||
ThreadPoolTaskExecutor executor = this.builder.awaitTerminationPeriod(period).build();
|
||||
assertThat(executor).hasFieldOrPropertyWithValue("awaitTerminationMillis", period.toMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
void threadNamePrefixShouldApply() {
|
||||
ThreadPoolTaskExecutor executor = this.builder.threadNamePrefix("test-").build();
|
||||
assertThat(executor.getThreadNamePrefix()).isEqualTo("test-");
|
||||
}
|
||||
|
||||
@Test
|
||||
void taskDecoratorShouldApply() {
|
||||
TaskDecorator taskDecorator = mock(TaskDecorator.class);
|
||||
ThreadPoolTaskExecutor executor = this.builder.taskDecorator(taskDecorator).build();
|
||||
assertThat(executor).extracting("taskDecorator").isSameAs(taskDecorator);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizersWhenCustomizersAreNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> this.builder.customizers((TaskExecutorCustomizer[]) null))
|
||||
.withMessageContaining("Customizers must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizersCollectionWhenCustomizersAreNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.builder.customizers((Set<TaskExecutorCustomizer>) null))
|
||||
.withMessageContaining("Customizers must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizersShouldApply() {
|
||||
TaskExecutorCustomizer customizer = mock(TaskExecutorCustomizer.class);
|
||||
ThreadPoolTaskExecutor executor = this.builder.customizers(customizer).build();
|
||||
then(customizer).should().customize(executor);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizersShouldBeAppliedLast() {
|
||||
TaskDecorator taskDecorator = mock(TaskDecorator.class);
|
||||
ThreadPoolTaskExecutor executor = spy(new ThreadPoolTaskExecutor());
|
||||
this.builder.queueCapacity(10)
|
||||
.corePoolSize(4)
|
||||
.maxPoolSize(8)
|
||||
.allowCoreThreadTimeOut(true)
|
||||
.keepAlive(Duration.ofMinutes(1))
|
||||
.awaitTermination(true)
|
||||
.awaitTerminationPeriod(Duration.ofSeconds(30))
|
||||
.threadNamePrefix("test-")
|
||||
.taskDecorator(taskDecorator)
|
||||
.additionalCustomizers((taskExecutor) -> {
|
||||
then(taskExecutor).should().setQueueCapacity(10);
|
||||
then(taskExecutor).should().setCorePoolSize(4);
|
||||
then(taskExecutor).should().setMaxPoolSize(8);
|
||||
then(taskExecutor).should().setAllowCoreThreadTimeOut(true);
|
||||
then(taskExecutor).should().setKeepAliveSeconds(60);
|
||||
then(taskExecutor).should().setWaitForTasksToCompleteOnShutdown(true);
|
||||
then(taskExecutor).should().setAwaitTerminationSeconds(30);
|
||||
then(taskExecutor).should().setThreadNamePrefix("test-");
|
||||
then(taskExecutor).should().setTaskDecorator(taskDecorator);
|
||||
});
|
||||
this.builder.configure(executor);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizersShouldReplaceExisting() {
|
||||
TaskExecutorCustomizer customizer1 = mock(TaskExecutorCustomizer.class);
|
||||
TaskExecutorCustomizer customizer2 = mock(TaskExecutorCustomizer.class);
|
||||
ThreadPoolTaskExecutor executor = this.builder.customizers(customizer1)
|
||||
.customizers(Collections.singleton(customizer2))
|
||||
.build();
|
||||
then(customizer1).shouldHaveNoInteractions();
|
||||
then(customizer2).should().customize(executor);
|
||||
}
|
||||
|
||||
@Test
|
||||
void additionalCustomizersWhenCustomizersAreNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.builder.additionalCustomizers((TaskExecutorCustomizer[]) null))
|
||||
.withMessageContaining("Customizers must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void additionalCustomizersCollectionWhenCustomizersAreNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.builder.additionalCustomizers((Set<TaskExecutorCustomizer>) null))
|
||||
.withMessageContaining("Customizers must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void additionalCustomizersShouldAddToExisting() {
|
||||
TaskExecutorCustomizer customizer1 = mock(TaskExecutorCustomizer.class);
|
||||
TaskExecutorCustomizer customizer2 = mock(TaskExecutorCustomizer.class);
|
||||
ThreadPoolTaskExecutor executor = this.builder.customizers(customizer1)
|
||||
.additionalCustomizers(customizer2)
|
||||
.build();
|
||||
then(customizer1).should().customize(executor);
|
||||
then(customizer2).should().customize(executor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.task;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
/**
|
||||
* Tests for {@link TaskSchedulerBuilder}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@SuppressWarnings("removal")
|
||||
class TaskSchedulerBuilderTests {
|
||||
|
||||
private final TaskSchedulerBuilder builder = new TaskSchedulerBuilder();
|
||||
|
||||
@Test
|
||||
void poolSettingsShouldApply() {
|
||||
ThreadPoolTaskScheduler scheduler = this.builder.poolSize(4).build();
|
||||
assertThat(scheduler.getPoolSize()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
void awaitTerminationShouldApply() {
|
||||
ThreadPoolTaskScheduler executor = this.builder.awaitTermination(true).build();
|
||||
assertThat(executor).hasFieldOrPropertyWithValue("waitForTasksToCompleteOnShutdown", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void awaitTerminationPeriodShouldApply() {
|
||||
Duration period = Duration.ofMinutes(1);
|
||||
ThreadPoolTaskScheduler executor = this.builder.awaitTerminationPeriod(period).build();
|
||||
assertThat(executor).hasFieldOrPropertyWithValue("awaitTerminationMillis", period.toMillis());
|
||||
}
|
||||
|
||||
@Test
|
||||
void threadNamePrefixShouldApply() {
|
||||
ThreadPoolTaskScheduler scheduler = this.builder.threadNamePrefix("test-").build();
|
||||
assertThat(scheduler.getThreadNamePrefix()).isEqualTo("test-");
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizersWhenCustomizersAreNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.builder.customizers((TaskSchedulerCustomizer[]) null))
|
||||
.withMessageContaining("Customizers must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizersCollectionWhenCustomizersAreNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.builder.customizers((Set<TaskSchedulerCustomizer>) null))
|
||||
.withMessageContaining("Customizers must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizersShouldApply() {
|
||||
TaskSchedulerCustomizer customizer = mock(TaskSchedulerCustomizer.class);
|
||||
ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer).build();
|
||||
then(customizer).should().customize(scheduler);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizersShouldBeAppliedLast() {
|
||||
ThreadPoolTaskScheduler scheduler = spy(new ThreadPoolTaskScheduler());
|
||||
this.builder.poolSize(4).threadNamePrefix("test-").additionalCustomizers((taskScheduler) -> {
|
||||
then(taskScheduler).should().setPoolSize(4);
|
||||
then(taskScheduler).should().setThreadNamePrefix("test-");
|
||||
});
|
||||
this.builder.configure(scheduler);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customizersShouldReplaceExisting() {
|
||||
TaskSchedulerCustomizer customizer1 = mock(TaskSchedulerCustomizer.class);
|
||||
TaskSchedulerCustomizer customizer2 = mock(TaskSchedulerCustomizer.class);
|
||||
ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer1)
|
||||
.customizers(Collections.singleton(customizer2))
|
||||
.build();
|
||||
then(customizer1).shouldHaveNoInteractions();
|
||||
then(customizer2).should().customize(scheduler);
|
||||
}
|
||||
|
||||
@Test
|
||||
void additionalCustomizersWhenCustomizersAreNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.builder.additionalCustomizers((TaskSchedulerCustomizer[]) null))
|
||||
.withMessageContaining("Customizers must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void additionalCustomizersCollectionWhenCustomizersAreNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> this.builder.additionalCustomizers((Set<TaskSchedulerCustomizer>) null))
|
||||
.withMessageContaining("Customizers must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void additionalCustomizersShouldAddToExisting() {
|
||||
TaskSchedulerCustomizer customizer1 = mock(TaskSchedulerCustomizer.class);
|
||||
TaskSchedulerCustomizer customizer2 = mock(TaskSchedulerCustomizer.class);
|
||||
ThreadPoolTaskScheduler scheduler = this.builder.customizers(customizer1)
|
||||
.additionalCustomizers(customizer2)
|
||||
.build();
|
||||
then(customizer1).should().customize(scheduler);
|
||||
then(customizer2).should().customize(scheduler);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,8 +23,10 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.web.util.UriBuilder;
|
||||
import org.springframework.web.util.UriBuilderFactory;
|
||||
import org.springframework.web.util.UriTemplateHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link RootUriBuilderFactory}.
|
||||
@@ -35,7 +37,8 @@ class RootUriBuilderFactoryTests {
|
||||
|
||||
@Test
|
||||
void uriStringPrefixesRoot() throws URISyntaxException {
|
||||
UriBuilderFactory builderFactory = new RootUriBuilderFactory("https://example.com");
|
||||
UriBuilderFactory builderFactory = new RootUriBuilderFactory("https://example.com",
|
||||
mock(UriTemplateHandler.class));
|
||||
UriBuilder builder = builderFactory.uriString("/hello");
|
||||
assertThat(builder.build()).isEqualTo(new URI("https://example.com/hello"));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.util.UriTemplateHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -36,6 +35,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link RootUriTemplateHandler}.
|
||||
@@ -43,7 +43,6 @@ import static org.mockito.BDDMockito.then;
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@SuppressWarnings("removal")
|
||||
class RootUriTemplateHandlerTests {
|
||||
|
||||
private URI uri;
|
||||
@@ -61,7 +60,8 @@ class RootUriTemplateHandlerTests {
|
||||
|
||||
@Test
|
||||
void createWithNullRootUriShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new RootUriTemplateHandler((String) null))
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new RootUriTemplateHandler((String) null, mock(UriTemplateHandler.class)))
|
||||
.withMessageContaining("RootUri must not be null");
|
||||
}
|
||||
|
||||
@@ -109,16 +109,4 @@ class RootUriTemplateHandlerTests {
|
||||
assertThat(expanded).isEqualTo(this.uri);
|
||||
}
|
||||
|
||||
@Test
|
||||
void applyShouldWrapExistingTemplate() {
|
||||
given(this.delegate.expand(anyString(), any(Object[].class))).willReturn(this.uri);
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.setUriTemplateHandler(this.delegate);
|
||||
this.handler = RootUriTemplateHandler.addTo(restTemplate, "https://example.com");
|
||||
Object[] uriVariables = new Object[0];
|
||||
URI expanded = this.handler.expand("/hello", uriVariables);
|
||||
then(this.delegate).should().expand("https://example.com/hello", uriVariables);
|
||||
assertThat(expanded).isEqualTo(this.uri);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user