Remove code deprecated for removal in 2.x
Closes gh-29482
This commit is contained in:
parent
1fa541d4de
commit
de3b9a4910
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -78,18 +78,6 @@ public abstract class OnEndpointElementCondition extends SpringBootCondition {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
protected ConditionOutcome getDefaultOutcome(ConditionContext context, AnnotationAttributes annotationAttributes) {
|
protected ConditionOutcome getDefaultOutcome(ConditionContext context, AnnotationAttributes annotationAttributes) {
|
||||||
return getDefaultEndpointsOutcome(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the default outcome that should be used.
|
|
||||||
* @param context the condition context
|
|
||||||
* @return the default outcome
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #getDefaultOutcome(ConditionContext, AnnotationAttributes)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected ConditionOutcome getDefaultEndpointsOutcome(ConditionContext context) {
|
|
||||||
boolean match = Boolean
|
boolean match = Boolean
|
||||||
.parseBoolean(context.getEnvironment().getProperty(this.prefix + "defaults.enabled", "true"));
|
.parseBoolean(context.getEnvironment().getProperty(this.prefix + "defaults.enabled", "true"));
|
||||||
return new ConditionOutcome(match, ConditionMessage.forCondition(this.annotationType)
|
return new ConditionOutcome(match, ConditionMessage.forCondition(this.annotationType)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -50,23 +50,6 @@ public class IncludeExcludeEndpointFilter<E extends ExposableEndpoint<?>> implem
|
||||||
|
|
||||||
private final EndpointPatterns exclude;
|
private final EndpointPatterns exclude;
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link IncludeExcludeEndpointFilter} with include/exclude rules bound
|
|
||||||
* from the {@link Environment}.
|
|
||||||
* @param endpointType the endpoint type that should be considered (other types always
|
|
||||||
* match)
|
|
||||||
* @param environment the environment containing the properties
|
|
||||||
* @param prefix the property prefix to bind
|
|
||||||
* @param defaultIncludes the default {@code includes} to use when none are specified.
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #IncludeExcludeEndpointFilter(Class, Environment, String, String[])}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public IncludeExcludeEndpointFilter(Class<E> endpointType, Environment environment, String prefix,
|
|
||||||
DefaultIncludes defaultIncludes) {
|
|
||||||
this(endpointType, environment, prefix, DefaultIncludes.patterns(defaultIncludes));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link IncludeExcludeEndpointFilter} with include/exclude rules bound
|
* Create a new {@link IncludeExcludeEndpointFilter} with include/exclude rules bound
|
||||||
* from the {@link Environment}.
|
* from the {@link Environment}.
|
||||||
|
|
@ -95,23 +78,6 @@ public class IncludeExcludeEndpointFilter<E extends ExposableEndpoint<?>> implem
|
||||||
this(endpointType, include, exclude, new EndpointPatterns(defaultIncludes));
|
this(endpointType, include, exclude, new EndpointPatterns(defaultIncludes));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link IncludeExcludeEndpointFilter} with specific include/exclude
|
|
||||||
* rules.
|
|
||||||
* @param endpointType the endpoint type that should be considered (other types always
|
|
||||||
* match)
|
|
||||||
* @param include the include patterns
|
|
||||||
* @param exclude the exclude patterns
|
|
||||||
* @param defaultIncludes the default {@code includes} to use when none are specified.
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #IncludeExcludeEndpointFilter(Class, Environment, String, String[])}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public IncludeExcludeEndpointFilter(Class<E> endpointType, Collection<String> include, Collection<String> exclude,
|
|
||||||
DefaultIncludes defaultIncludes) {
|
|
||||||
this(endpointType, include, exclude, DefaultIncludes.patterns(defaultIncludes));
|
|
||||||
}
|
|
||||||
|
|
||||||
private IncludeExcludeEndpointFilter(Class<E> endpointType, Environment environment, String prefix,
|
private IncludeExcludeEndpointFilter(Class<E> endpointType, Environment environment, String prefix,
|
||||||
EndpointPatterns defaultIncludes) {
|
EndpointPatterns defaultIncludes) {
|
||||||
Assert.notNull(endpointType, "EndpointType must not be null");
|
Assert.notNull(endpointType, "EndpointType must not be null");
|
||||||
|
|
@ -172,35 +138,6 @@ public class IncludeExcludeEndpointFilter<E extends ExposableEndpoint<?>> implem
|
||||||
return this.exclude.matches(endpointId);
|
return this.exclude.matches(endpointId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Default include patterns that can be used.
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of {@link EndpointExposure}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public enum DefaultIncludes {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default set of include patterns used for JMX.
|
|
||||||
*/
|
|
||||||
JMX("*"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default set of include patterns used for web.
|
|
||||||
*/
|
|
||||||
WEB("health");
|
|
||||||
|
|
||||||
private final EndpointPatterns patterns;
|
|
||||||
|
|
||||||
DefaultIncludes(String... patterns) {
|
|
||||||
this.patterns = new EndpointPatterns(patterns);
|
|
||||||
}
|
|
||||||
|
|
||||||
static EndpointPatterns patterns(DefaultIncludes defaultIncludes) {
|
|
||||||
return (defaultIncludes != null) ? defaultIncludes.patterns : (EndpointPatterns) null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of endpoint patterns used to match IDs.
|
* A set of endpoint patterns used to match IDs.
|
||||||
*/
|
*/
|
||||||
|
|
@ -241,10 +178,6 @@ public class IncludeExcludeEndpointFilter<E extends ExposableEndpoint<?>> implem
|
||||||
return this.matchesAll || this.endpointIds.contains(endpointId);
|
return this.matchesAll || this.endpointIds.contains(endpointId);
|
||||||
}
|
}
|
||||||
|
|
||||||
static EndpointPatterns forExposure(EndpointExposure exposure) {
|
|
||||||
return (exposure != null) ? new EndpointPatterns(exposure.getDefaultIncludes()) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -159,24 +159,10 @@ public class ConfigurationPropertiesReportEndpoint implements ApplicationContext
|
||||||
JsonMapper.Builder builder = JsonMapper.builder();
|
JsonMapper.Builder builder = JsonMapper.builder();
|
||||||
configureJsonMapper(builder);
|
configureJsonMapper(builder);
|
||||||
this.objectMapper = builder.build();
|
this.objectMapper = builder.build();
|
||||||
configureObjectMapper(this.objectMapper);
|
|
||||||
}
|
}
|
||||||
return this.objectMapper;
|
return this.objectMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure Jackson's {@link ObjectMapper} to be used to serialize the
|
|
||||||
* {@link ConfigurationProperties @ConfigurationProperties} objects into a {@link Map}
|
|
||||||
* structure.
|
|
||||||
* @param mapper the object mapper
|
|
||||||
* @deprecated since 2.6 for removal in 2.8 in favor of
|
|
||||||
* {@link #configureJsonMapper(com.fasterxml.jackson.databind.json.JsonMapper.Builder)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected void configureObjectMapper(ObjectMapper mapper) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configure Jackson's {@link JsonMapper} to be used to serialize the
|
* Configure Jackson's {@link JsonMapper} to be used to serialize the
|
||||||
* {@link ConfigurationProperties @ConfigurationProperties} objects into a {@link Map}
|
* {@link ConfigurationProperties @ConfigurationProperties} objects into a {@link Map}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -193,19 +193,6 @@ public class EnvironmentEndpoint {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply sanitization to the given name and value.
|
|
||||||
* @param key the name to sanitize
|
|
||||||
* @param value the value to sanitize
|
|
||||||
* @return the sanitized value
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 as sanitization should be internal to
|
|
||||||
* the class
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public Object sanitize(String key, Object value) {
|
|
||||||
return this.sanitizer.sanitize(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object sanitize(PropertySource<?> source, String name, Object value) {
|
private Object sanitize(PropertySource<?> source, String name, Object value) {
|
||||||
return this.sanitizer.sanitize(new SanitizableData(source, name, value));
|
return this.sanitizer.sanitize(new SanitizableData(source, name, value));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -47,16 +47,6 @@ public abstract class AbstractRabbitListenerContainerFactoryConfigurer<T extends
|
||||||
|
|
||||||
private RabbitProperties rabbitProperties;
|
private RabbitProperties rabbitProperties;
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new configurer.
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #AbstractRabbitListenerContainerFactoryConfigurer(RabbitProperties)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected AbstractRabbitListenerContainerFactoryConfigurer() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new configurer that will use the given {@code rabbitProperties}.
|
* Creates a new configurer that will use the given {@code rabbitProperties}.
|
||||||
* @param rabbitProperties properties to use
|
* @param rabbitProperties properties to use
|
||||||
|
|
@ -91,17 +81,6 @@ public abstract class AbstractRabbitListenerContainerFactoryConfigurer<T extends
|
||||||
this.retryTemplateCustomizers = retryTemplateCustomizers;
|
this.retryTemplateCustomizers = retryTemplateCustomizers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the {@link RabbitProperties} to use.
|
|
||||||
* @param rabbitProperties the {@link RabbitProperties}
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #AbstractRabbitListenerContainerFactoryConfigurer(RabbitProperties)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected void setRabbitProperties(RabbitProperties rabbitProperties) {
|
|
||||||
this.rabbitProperties = rabbitProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final RabbitProperties getRabbitProperties() {
|
protected final RabbitProperties getRabbitProperties() {
|
||||||
return this.rabbitProperties;
|
return this.rabbitProperties;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -31,16 +31,6 @@ import org.springframework.boot.context.properties.PropertyMapper;
|
||||||
public final class DirectRabbitListenerContainerFactoryConfigurer
|
public final class DirectRabbitListenerContainerFactoryConfigurer
|
||||||
extends AbstractRabbitListenerContainerFactoryConfigurer<DirectRabbitListenerContainerFactory> {
|
extends AbstractRabbitListenerContainerFactoryConfigurer<DirectRabbitListenerContainerFactory> {
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new configurer.
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #DirectRabbitListenerContainerFactoryConfigurer(RabbitProperties)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public DirectRabbitListenerContainerFactoryConfigurer() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new configurer that will use the given {@code rabbitProperties}.
|
* Creates a new configurer that will use the given {@code rabbitProperties}.
|
||||||
* @param rabbitProperties properties to use
|
* @param rabbitProperties properties to use
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -39,16 +39,6 @@ public class RabbitTemplateConfigurer {
|
||||||
|
|
||||||
private RabbitProperties rabbitProperties;
|
private RabbitProperties rabbitProperties;
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new configurer.
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #RabbitTemplateConfigurer(RabbitProperties)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public RabbitTemplateConfigurer() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new configurer that will use the given {@code rabbitProperties}.
|
* Creates a new configurer that will use the given {@code rabbitProperties}.
|
||||||
* @param rabbitProperties properties to use
|
* @param rabbitProperties properties to use
|
||||||
|
|
@ -78,17 +68,6 @@ public class RabbitTemplateConfigurer {
|
||||||
this.retryTemplateCustomizers = retryTemplateCustomizers;
|
this.retryTemplateCustomizers = retryTemplateCustomizers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the {@link RabbitProperties} to use.
|
|
||||||
* @param rabbitProperties the {@link RabbitProperties}
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #RabbitTemplateConfigurer(RabbitProperties)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected void setRabbitProperties(RabbitProperties rabbitProperties) {
|
|
||||||
this.rabbitProperties = rabbitProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final RabbitProperties getRabbitProperties() {
|
protected final RabbitProperties getRabbitProperties() {
|
||||||
return this.rabbitProperties;
|
return this.rabbitProperties;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -31,16 +31,6 @@ import org.springframework.boot.context.properties.PropertyMapper;
|
||||||
public final class SimpleRabbitListenerContainerFactoryConfigurer
|
public final class SimpleRabbitListenerContainerFactoryConfigurer
|
||||||
extends AbstractRabbitListenerContainerFactoryConfigurer<SimpleRabbitListenerContainerFactory> {
|
extends AbstractRabbitListenerContainerFactoryConfigurer<SimpleRabbitListenerContainerFactory> {
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new configurer.
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #SimpleRabbitListenerContainerFactoryConfigurer(RabbitProperties)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public SimpleRabbitListenerContainerFactoryConfigurer() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new configurer that will use the given {@code rabbitProperties}.
|
* Creates a new configurer that will use the given {@code rabbitProperties}.
|
||||||
* @param rabbitProperties properties to use
|
* @param rabbitProperties properties to use
|
||||||
|
|
|
||||||
|
|
@ -108,8 +108,7 @@ public class BatchAutoConfiguration {
|
||||||
static class DataSourceInitializerConfiguration {
|
static class DataSourceInitializerConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@SuppressWarnings("deprecation")
|
@ConditionalOnMissingBean(BatchDataSourceScriptDatabaseInitializer.class)
|
||||||
@ConditionalOnMissingBean({ BatchDataSourceScriptDatabaseInitializer.class, BatchDataSourceInitializer.class })
|
|
||||||
BatchDataSourceScriptDatabaseInitializer batchDataSourceInitializer(DataSource dataSource,
|
BatchDataSourceScriptDatabaseInitializer batchDataSourceInitializer(DataSource dataSource,
|
||||||
@BatchDataSource ObjectProvider<DataSource> batchDataSource, BatchProperties properties) {
|
@BatchDataSource ObjectProvider<DataSource> batchDataSource, BatchProperties properties) {
|
||||||
return new BatchDataSourceScriptDatabaseInitializer(batchDataSource.getIfAvailable(() -> dataSource),
|
return new BatchDataSourceScriptDatabaseInitializer(batchDataSource.getIfAvailable(() -> dataSource),
|
||||||
|
|
|
||||||
|
|
@ -1,83 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.batch;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.batch.BatchProperties.Jdbc;
|
|
||||||
import org.springframework.boot.sql.init.DatabaseInitializationMode;
|
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the Spring Batch schema (ignoring errors, so it should be idempotent).
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @since 1.0.0
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link BatchDataSourceScriptDatabaseInitializer}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class BatchDataSourceInitializer extends org.springframework.boot.jdbc.AbstractDataSourceInitializer {
|
|
||||||
|
|
||||||
private final Jdbc jdbcProperties;
|
|
||||||
|
|
||||||
public BatchDataSourceInitializer(DataSource dataSource, ResourceLoader resourceLoader,
|
|
||||||
BatchProperties properties) {
|
|
||||||
super(dataSource, resourceLoader);
|
|
||||||
Assert.notNull(properties, "BatchProperties must not be null");
|
|
||||||
this.jdbcProperties = properties.getJdbc();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected org.springframework.boot.jdbc.DataSourceInitializationMode getMode() {
|
|
||||||
DatabaseInitializationMode mode = this.jdbcProperties.getInitializeSchema();
|
|
||||||
switch (mode) {
|
|
||||||
case ALWAYS:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.ALWAYS;
|
|
||||||
case EMBEDDED:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.EMBEDDED;
|
|
||||||
case NEVER:
|
|
||||||
default:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.NEVER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getSchemaLocation() {
|
|
||||||
return this.jdbcProperties.getSchema();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getDatabaseName() {
|
|
||||||
String platform = this.jdbcProperties.getPlatform();
|
|
||||||
if (StringUtils.hasText(platform)) {
|
|
||||||
return platform;
|
|
||||||
}
|
|
||||||
String databaseName = super.getDatabaseName();
|
|
||||||
if ("oracle".equals(databaseName)) {
|
|
||||||
return "oracle10g";
|
|
||||||
}
|
|
||||||
if ("mariadb".equals(databaseName)) {
|
|
||||||
return "mysql";
|
|
||||||
}
|
|
||||||
return databaseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,150 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.data.elasticsearch;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
|
|
||||||
import org.springframework.util.unit.DataSize;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deprecated configuration properties for Elasticsearch Reactive REST clients.
|
|
||||||
*
|
|
||||||
* @author Brian Clozel
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@ConfigurationProperties(prefix = "spring.data.elasticsearch.client.reactive")
|
|
||||||
class DeprecatedReactiveElasticsearchRestClientProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Comma-separated list of the Elasticsearch endpoints to connect to.
|
|
||||||
*/
|
|
||||||
private List<String> endpoints = new ArrayList<>(Collections.singletonList("localhost:9200"));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether the client should use SSL to connect to the endpoints.
|
|
||||||
*/
|
|
||||||
private boolean useSsl = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Credentials username.
|
|
||||||
*/
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Credentials password.
|
|
||||||
*/
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connection timeout.
|
|
||||||
*/
|
|
||||||
private Duration connectionTimeout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read and Write Socket timeout.
|
|
||||||
*/
|
|
||||||
private Duration socketTimeout;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Limit on the number of bytes that can be buffered whenever the input stream needs
|
|
||||||
* to be aggregated.
|
|
||||||
*/
|
|
||||||
private DataSize maxInMemorySize;
|
|
||||||
|
|
||||||
private boolean customized = false;
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.uris")
|
|
||||||
public List<String> getEndpoints() {
|
|
||||||
return this.endpoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndpoints(List<String> endpoints) {
|
|
||||||
this.customized = true;
|
|
||||||
this.endpoints = endpoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(reason = "Use of SSL should be indicated through an https URI scheme")
|
|
||||||
public boolean isUseSsl() {
|
|
||||||
return this.useSsl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUseSsl(boolean useSsl) {
|
|
||||||
this.customized = true;
|
|
||||||
this.useSsl = useSsl;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.username")
|
|
||||||
public String getUsername() {
|
|
||||||
return this.username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.customized = true;
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.password")
|
|
||||||
public String getPassword() {
|
|
||||||
return this.password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.customized = true;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.connection-timeout")
|
|
||||||
public Duration getConnectionTimeout() {
|
|
||||||
return this.connectionTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectionTimeout(Duration connectionTimeout) {
|
|
||||||
this.customized = true;
|
|
||||||
this.connectionTimeout = connectionTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.socket-timeout")
|
|
||||||
public Duration getSocketTimeout() {
|
|
||||||
return this.socketTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSocketTimeout(Duration socketTimeout) {
|
|
||||||
this.customized = true;
|
|
||||||
this.socketTimeout = socketTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.webclient.max-in-memory-size")
|
|
||||||
public DataSize getMaxInMemorySize() {
|
|
||||||
return this.maxInMemorySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMaxInMemorySize(DataSize maxInMemorySize) {
|
|
||||||
this.customized = true;
|
|
||||||
this.maxInMemorySize = maxInMemorySize;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isCustomized() {
|
|
||||||
return this.customized;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -49,19 +49,16 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @since 2.2.0
|
* @since 2.2.0
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass({ ReactiveRestClients.class, WebClient.class, HttpClient.class })
|
@ConditionalOnClass({ ReactiveRestClients.class, WebClient.class, HttpClient.class })
|
||||||
@EnableConfigurationProperties({ ElasticsearchProperties.class, ReactiveElasticsearchRestClientProperties.class,
|
@EnableConfigurationProperties({ ElasticsearchProperties.class, ReactiveElasticsearchRestClientProperties.class })
|
||||||
DeprecatedReactiveElasticsearchRestClientProperties.class })
|
|
||||||
public class ReactiveElasticsearchRestClientAutoConfiguration {
|
public class ReactiveElasticsearchRestClientAutoConfiguration {
|
||||||
|
|
||||||
private final ConsolidatedProperties properties;
|
private final ConsolidatedProperties properties;
|
||||||
|
|
||||||
ReactiveElasticsearchRestClientAutoConfiguration(ElasticsearchProperties properties,
|
ReactiveElasticsearchRestClientAutoConfiguration(ElasticsearchProperties properties,
|
||||||
ReactiveElasticsearchRestClientProperties restClientProperties,
|
ReactiveElasticsearchRestClientProperties restClientProperties) {
|
||||||
DeprecatedReactiveElasticsearchRestClientProperties reactiveProperties) {
|
this.properties = new ConsolidatedProperties(properties, restClientProperties);
|
||||||
this.properties = new ConsolidatedProperties(properties, restClientProperties, reactiveProperties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -103,24 +100,17 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
|
||||||
|
|
||||||
private final ReactiveElasticsearchRestClientProperties restClientProperties;
|
private final ReactiveElasticsearchRestClientProperties restClientProperties;
|
||||||
|
|
||||||
private final DeprecatedReactiveElasticsearchRestClientProperties deprecatedProperties;
|
|
||||||
|
|
||||||
private final List<URI> uris;
|
private final List<URI> uris;
|
||||||
|
|
||||||
private ConsolidatedProperties(ElasticsearchProperties properties,
|
private ConsolidatedProperties(ElasticsearchProperties properties,
|
||||||
ReactiveElasticsearchRestClientProperties restClientProperties,
|
ReactiveElasticsearchRestClientProperties restClientProperties) {
|
||||||
DeprecatedReactiveElasticsearchRestClientProperties deprecatedreactiveProperties) {
|
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
this.restClientProperties = restClientProperties;
|
this.restClientProperties = restClientProperties;
|
||||||
this.deprecatedProperties = deprecatedreactiveProperties;
|
|
||||||
this.uris = properties.getUris().stream().map((s) -> s.startsWith("http") ? s : "http://" + s)
|
this.uris = properties.getUris().stream().map((s) -> s.startsWith("http") ? s : "http://" + s)
|
||||||
.map(URI::create).collect(Collectors.toList());
|
.map(URI::create).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getEndpoints() {
|
private List<String> getEndpoints() {
|
||||||
if (this.deprecatedProperties.isCustomized()) {
|
|
||||||
return this.deprecatedProperties.getEndpoints();
|
|
||||||
}
|
|
||||||
return this.uris.stream().map(this::getEndpoint).collect(Collectors.toList());
|
return this.uris.stream().map(this::getEndpoint).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,9 +119,6 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Credentials getCredentials() {
|
private Credentials getCredentials() {
|
||||||
if (this.deprecatedProperties.isCustomized()) {
|
|
||||||
return Credentials.from(this.deprecatedProperties);
|
|
||||||
}
|
|
||||||
Credentials propertyCredentials = Credentials.from(this.properties);
|
Credentials propertyCredentials = Credentials.from(this.properties);
|
||||||
Credentials uriCredentials = Credentials.from(this.uris);
|
Credentials uriCredentials = Credentials.from(this.uris);
|
||||||
if (uriCredentials == null) {
|
if (uriCredentials == null) {
|
||||||
|
|
@ -144,31 +131,25 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Duration getConnectionTimeout() {
|
private Duration getConnectionTimeout() {
|
||||||
return this.deprecatedProperties.isCustomized() ? this.deprecatedProperties.getConnectionTimeout()
|
return this.properties.getConnectionTimeout();
|
||||||
: this.properties.getConnectionTimeout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Duration getSocketTimeout() {
|
private Duration getSocketTimeout() {
|
||||||
return this.deprecatedProperties.isCustomized() ? this.deprecatedProperties.getSocketTimeout()
|
return this.properties.getSocketTimeout();
|
||||||
: this.properties.getSocketTimeout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isUseSsl() {
|
private boolean isUseSsl() {
|
||||||
if (this.deprecatedProperties.isCustomized()) {
|
|
||||||
return this.deprecatedProperties.isUseSsl();
|
|
||||||
}
|
|
||||||
Set<String> schemes = this.uris.stream().map(URI::getScheme).collect(Collectors.toSet());
|
Set<String> schemes = this.uris.stream().map(URI::getScheme).collect(Collectors.toSet());
|
||||||
Assert.isTrue(schemes.size() == 1, "Configured Elasticsearch URIs have varying schemes");
|
Assert.isTrue(schemes.size() == 1, "Configured Elasticsearch URIs have varying schemes");
|
||||||
return schemes.iterator().next().equals("https");
|
return schemes.iterator().next().equals("https");
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataSize getMaxInMemorySize() {
|
private DataSize getMaxInMemorySize() {
|
||||||
return this.deprecatedProperties.isCustomized() ? this.deprecatedProperties.getMaxInMemorySize()
|
return this.restClientProperties.getMaxInMemorySize();
|
||||||
: this.restClientProperties.getMaxInMemorySize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPathPrefix() {
|
private String getPathPrefix() {
|
||||||
return this.deprecatedProperties.isCustomized() ? null : this.properties.getPathPrefix();
|
return this.properties.getPathPrefix();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class Credentials {
|
private static final class Credentials {
|
||||||
|
|
@ -207,10 +188,6 @@ public class ReactiveElasticsearchRestClientAutoConfiguration {
|
||||||
return getCredentials(properties.getUsername(), properties.getPassword());
|
return getCredentials(properties.getUsername(), properties.getPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Credentials from(DeprecatedReactiveElasticsearchRestClientProperties properties) {
|
|
||||||
return getCredentials(properties.getUsername(), properties.getPassword());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Credentials getCredentials(String username, String password) {
|
private static Credentials getCredentials(String username, String password) {
|
||||||
if (username == null && password == null) {
|
if (username == null && password == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -1,159 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.elasticsearch;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deprecated configuration properties for Elasticsearch REST clients.
|
|
||||||
*
|
|
||||||
* @author Brian Clozel
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0.
|
|
||||||
*/
|
|
||||||
@ConfigurationProperties(prefix = "spring.elasticsearch.rest")
|
|
||||||
@Deprecated
|
|
||||||
class DeprecatedElasticsearchRestClientProperties {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Comma-separated list of the Elasticsearch instances to use.
|
|
||||||
*/
|
|
||||||
private List<String> uris = new ArrayList<>(Collections.singletonList("http://localhost:9200"));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Credentials username.
|
|
||||||
*/
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Credentials password.
|
|
||||||
*/
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connection timeout.
|
|
||||||
*/
|
|
||||||
private Duration connectionTimeout = Duration.ofSeconds(1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read timeout.
|
|
||||||
*/
|
|
||||||
private Duration readTimeout = Duration.ofSeconds(30);
|
|
||||||
|
|
||||||
private final Sniffer sniffer = new Sniffer();
|
|
||||||
|
|
||||||
private boolean customized = false;
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.uris")
|
|
||||||
public List<String> getUris() {
|
|
||||||
return this.uris;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUris(List<String> uris) {
|
|
||||||
this.customized = true;
|
|
||||||
this.uris = uris;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.username")
|
|
||||||
public String getUsername() {
|
|
||||||
return this.username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUsername(String username) {
|
|
||||||
this.customized = true;
|
|
||||||
this.username = username;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.password")
|
|
||||||
public String getPassword() {
|
|
||||||
return this.password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.customized = true;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.connection-timeout")
|
|
||||||
public Duration getConnectionTimeout() {
|
|
||||||
return this.connectionTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConnectionTimeout(Duration connectionTimeout) {
|
|
||||||
this.customized = true;
|
|
||||||
this.connectionTimeout = connectionTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.socket-timeout")
|
|
||||||
public Duration getReadTimeout() {
|
|
||||||
return this.readTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReadTimeout(Duration readTimeout) {
|
|
||||||
this.customized = true;
|
|
||||||
this.readTimeout = readTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isCustomized() {
|
|
||||||
return this.customized;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sniffer getSniffer() {
|
|
||||||
return this.sniffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
class Sniffer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Interval between consecutive ordinary sniff executions.
|
|
||||||
*/
|
|
||||||
private Duration interval = Duration.ofMinutes(5);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delay of a sniff execution scheduled after a failure.
|
|
||||||
*/
|
|
||||||
private Duration delayAfterFailure = Duration.ofMinutes(1);
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.restclient.sniffer.interval")
|
|
||||||
public Duration getInterval() {
|
|
||||||
return this.interval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInterval(Duration interval) {
|
|
||||||
DeprecatedElasticsearchRestClientProperties.this.customized = true;
|
|
||||||
this.interval = interval;
|
|
||||||
}
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.elasticsearch.restclient.sniffer.delay-after-failure")
|
|
||||||
public Duration getDelayAfterFailure() {
|
|
||||||
return this.delayAfterFailure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDelayAfterFailure(Duration delayAfterFailure) {
|
|
||||||
DeprecatedElasticsearchRestClientProperties.this.customized = true;
|
|
||||||
this.delayAfterFailure = delayAfterFailure;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -34,11 +34,9 @@ import org.springframework.context.annotation.Import;
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass(RestClientBuilder.class)
|
@ConditionalOnClass(RestClientBuilder.class)
|
||||||
@EnableConfigurationProperties({ ElasticsearchProperties.class, ElasticsearchRestClientProperties.class,
|
@EnableConfigurationProperties({ ElasticsearchProperties.class, ElasticsearchRestClientProperties.class })
|
||||||
DeprecatedElasticsearchRestClientProperties.class })
|
|
||||||
@Import({ RestClientBuilderConfiguration.class, RestHighLevelClientConfiguration.class,
|
@Import({ RestClientBuilderConfiguration.class, RestHighLevelClientConfiguration.class,
|
||||||
RestClientSnifferConfiguration.class })
|
RestClientSnifferConfiguration.class })
|
||||||
public class ElasticsearchRestClientAutoConfiguration {
|
public class ElasticsearchRestClientAutoConfiguration {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.elasticsearch;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.http.auth.AuthScope;
|
import org.apache.http.auth.AuthScope;
|
||||||
|
|
@ -53,12 +52,10 @@ class ElasticsearchRestClientConfigurations {
|
||||||
@ConditionalOnMissingBean(RestClientBuilder.class)
|
@ConditionalOnMissingBean(RestClientBuilder.class)
|
||||||
static class RestClientBuilderConfiguration {
|
static class RestClientBuilderConfiguration {
|
||||||
|
|
||||||
private final ConsolidatedProperties properties;
|
private final ElasticsearchProperties properties;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
RestClientBuilderConfiguration(ElasticsearchProperties properties) {
|
||||||
RestClientBuilderConfiguration(ElasticsearchProperties properties,
|
this.properties = properties;
|
||||||
DeprecatedElasticsearchRestClientProperties deprecatedProperties) {
|
|
||||||
this.properties = new ConsolidatedProperties(properties, deprecatedProperties);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -80,7 +77,7 @@ class ElasticsearchRestClientConfigurations {
|
||||||
return requestConfigBuilder;
|
return requestConfigBuilder;
|
||||||
});
|
});
|
||||||
if (this.properties.getPathPrefix() != null) {
|
if (this.properties.getPathPrefix() != null) {
|
||||||
builder.setPathPrefix(this.properties.properties.getPathPrefix());
|
builder.setPathPrefix(this.properties.getPathPrefix());
|
||||||
}
|
}
|
||||||
builderCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
|
builderCustomizers.orderedStream().forEach((customizer) -> customizer.customize(builder));
|
||||||
return builder;
|
return builder;
|
||||||
|
|
@ -133,16 +130,12 @@ class ElasticsearchRestClientConfigurations {
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
Sniffer elasticsearchSniffer(org.elasticsearch.client.RestHighLevelClient client,
|
Sniffer elasticsearchSniffer(org.elasticsearch.client.RestHighLevelClient client,
|
||||||
ElasticsearchRestClientProperties properties,
|
ElasticsearchRestClientProperties properties) {
|
||||||
DeprecatedElasticsearchRestClientProperties deprecatedProperties) {
|
|
||||||
SnifferBuilder builder = Sniffer.builder(client.getLowLevelClient());
|
SnifferBuilder builder = Sniffer.builder(client.getLowLevelClient());
|
||||||
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
|
||||||
Duration interval = deprecatedProperties.isCustomized() ? deprecatedProperties.getSniffer().getInterval()
|
Duration interval = properties.getSniffer().getInterval();
|
||||||
: properties.getSniffer().getInterval();
|
|
||||||
map.from(interval).asInt(Duration::toMillis).to(builder::setSniffIntervalMillis);
|
map.from(interval).asInt(Duration::toMillis).to(builder::setSniffIntervalMillis);
|
||||||
Duration delayAfterFailure = deprecatedProperties.isCustomized()
|
Duration delayAfterFailure = properties.getSniffer().getDelayAfterFailure();
|
||||||
? deprecatedProperties.getSniffer().getDelayAfterFailure()
|
|
||||||
: properties.getSniffer().getDelayAfterFailure();
|
|
||||||
map.from(delayAfterFailure).asInt(Duration::toMillis).to(builder::setSniffAfterFailureDelayMillis);
|
map.from(delayAfterFailure).asInt(Duration::toMillis).to(builder::setSniffAfterFailureDelayMillis);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
@ -153,9 +146,9 @@ class ElasticsearchRestClientConfigurations {
|
||||||
|
|
||||||
private static final PropertyMapper map = PropertyMapper.get();
|
private static final PropertyMapper map = PropertyMapper.get();
|
||||||
|
|
||||||
private final ConsolidatedProperties properties;
|
private final ElasticsearchProperties properties;
|
||||||
|
|
||||||
DefaultRestClientBuilderCustomizer(ConsolidatedProperties properties) {
|
DefaultRestClientBuilderCustomizer(ElasticsearchProperties properties) {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,7 +173,7 @@ class ElasticsearchRestClientConfigurations {
|
||||||
|
|
||||||
private static class PropertiesCredentialsProvider extends BasicCredentialsProvider {
|
private static class PropertiesCredentialsProvider extends BasicCredentialsProvider {
|
||||||
|
|
||||||
PropertiesCredentialsProvider(ConsolidatedProperties properties) {
|
PropertiesCredentialsProvider(ElasticsearchProperties properties) {
|
||||||
if (StringUtils.hasText(properties.getUsername())) {
|
if (StringUtils.hasText(properties.getUsername())) {
|
||||||
Credentials credentials = new UsernamePasswordCredentials(properties.getUsername(),
|
Credentials credentials = new UsernamePasswordCredentials(properties.getUsername(),
|
||||||
properties.getPassword());
|
properties.getPassword());
|
||||||
|
|
@ -221,48 +214,4 @@ class ElasticsearchRestClientConfigurations {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private static final class ConsolidatedProperties {
|
|
||||||
|
|
||||||
private final ElasticsearchProperties properties;
|
|
||||||
|
|
||||||
private final DeprecatedElasticsearchRestClientProperties deprecatedProperties;
|
|
||||||
|
|
||||||
private ConsolidatedProperties(ElasticsearchProperties properties,
|
|
||||||
DeprecatedElasticsearchRestClientProperties deprecatedProperties) {
|
|
||||||
this.properties = properties;
|
|
||||||
this.deprecatedProperties = deprecatedProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getUris() {
|
|
||||||
return this.deprecatedProperties.isCustomized() ? this.deprecatedProperties.getUris()
|
|
||||||
: this.properties.getUris();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getUsername() {
|
|
||||||
return this.deprecatedProperties.isCustomized() ? this.deprecatedProperties.getUsername()
|
|
||||||
: this.properties.getUsername();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPassword() {
|
|
||||||
return this.deprecatedProperties.isCustomized() ? this.deprecatedProperties.getPassword()
|
|
||||||
: this.properties.getPassword();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Duration getConnectionTimeout() {
|
|
||||||
return this.deprecatedProperties.isCustomized() ? this.deprecatedProperties.getConnectionTimeout()
|
|
||||||
: this.properties.getConnectionTimeout();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Duration getSocketTimeout() {
|
|
||||||
return this.deprecatedProperties.isCustomized() ? this.deprecatedProperties.getReadTimeout()
|
|
||||||
: this.properties.getSocketTimeout();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPathPrefix() {
|
|
||||||
return this.deprecatedProperties.isCustomized() ? null : this.properties.getPathPrefix();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -238,9 +238,7 @@ public class IntegrationAutoConfiguration {
|
||||||
protected static class IntegrationJdbcConfiguration {
|
protected static class IntegrationJdbcConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@SuppressWarnings("deprecation")
|
@ConditionalOnMissingBean(IntegrationDataSourceScriptDatabaseInitializer.class)
|
||||||
@ConditionalOnMissingBean({ IntegrationDataSourceScriptDatabaseInitializer.class,
|
|
||||||
IntegrationDataSourceInitializer.class })
|
|
||||||
public IntegrationDataSourceScriptDatabaseInitializer integrationDataSourceInitializer(DataSource dataSource,
|
public IntegrationDataSourceScriptDatabaseInitializer integrationDataSourceInitializer(DataSource dataSource,
|
||||||
IntegrationProperties properties) {
|
IntegrationProperties properties) {
|
||||||
return new IntegrationDataSourceScriptDatabaseInitializer(dataSource, properties.getJdbc());
|
return new IntegrationDataSourceScriptDatabaseInitializer(dataSource, properties.getJdbc());
|
||||||
|
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.integration;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.springframework.boot.sql.init.DatabaseInitializationMode;
|
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializer for Spring Integration schema.
|
|
||||||
*
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @since 2.0.0
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link IntegrationDataSourceScriptDatabaseInitializer}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class IntegrationDataSourceInitializer extends org.springframework.boot.jdbc.AbstractDataSourceInitializer {
|
|
||||||
|
|
||||||
private final IntegrationProperties.Jdbc properties;
|
|
||||||
|
|
||||||
public IntegrationDataSourceInitializer(DataSource dataSource, ResourceLoader resourceLoader,
|
|
||||||
IntegrationProperties properties) {
|
|
||||||
super(dataSource, resourceLoader);
|
|
||||||
Assert.notNull(properties, "IntegrationProperties must not be null");
|
|
||||||
this.properties = properties.getJdbc();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected org.springframework.boot.jdbc.DataSourceInitializationMode getMode() {
|
|
||||||
DatabaseInitializationMode mode = this.properties.getInitializeSchema();
|
|
||||||
switch (mode) {
|
|
||||||
case ALWAYS:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.ALWAYS;
|
|
||||||
case EMBEDDED:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.EMBEDDED;
|
|
||||||
case NEVER:
|
|
||||||
default:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.NEVER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getSchemaLocation() {
|
|
||||||
return this.properties.getSchema();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getDatabaseName() {
|
|
||||||
String platform = this.properties.getPlatform();
|
|
||||||
if (StringUtils.hasText(platform)) {
|
|
||||||
return platform;
|
|
||||||
}
|
|
||||||
return super.getDatabaseName();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -52,15 +52,12 @@ import org.springframework.util.StringUtils;
|
||||||
* @author Kazuki Shimizu
|
* @author Kazuki Shimizu
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@ConditionalOnClass({ DataSource.class, EmbeddedDatabaseType.class })
|
@ConditionalOnClass({ DataSource.class, EmbeddedDatabaseType.class })
|
||||||
@ConditionalOnMissingBean(type = "io.r2dbc.spi.ConnectionFactory")
|
@ConditionalOnMissingBean(type = "io.r2dbc.spi.ConnectionFactory")
|
||||||
@AutoConfigureBefore(SqlInitializationAutoConfiguration.class)
|
@AutoConfigureBefore(SqlInitializationAutoConfiguration.class)
|
||||||
@EnableConfigurationProperties(DataSourceProperties.class)
|
@EnableConfigurationProperties(DataSourceProperties.class)
|
||||||
@Import({ DataSourcePoolMetadataProvidersConfiguration.class,
|
@Import(DataSourcePoolMetadataProvidersConfiguration.class)
|
||||||
DataSourceInitializationConfiguration.InitializationSpecificCredentialsDataSourceInitializationConfiguration.class,
|
|
||||||
DataSourceInitializationConfiguration.SharedCredentialsDataSourceInitializationConfiguration.class })
|
|
||||||
public class DataSourceAutoConfiguration {
|
public class DataSourceAutoConfiguration {
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
|
|
||||||
|
|
@ -1,200 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.jdbc;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.ObjectProvider;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration.InitializationSpecificCredentialsDataSourceInitializationConfiguration.DifferentCredentialsCondition;
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceInitializationConfiguration.SharedCredentialsDataSourceInitializationConfiguration.DataSourceInitializationCondition;
|
|
||||||
import org.springframework.boot.autoconfigure.sql.init.SqlDataSourceScriptDatabaseInitializer;
|
|
||||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
|
||||||
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
|
|
||||||
import org.springframework.boot.sql.init.DatabaseInitializationMode;
|
|
||||||
import org.springframework.boot.sql.init.DatabaseInitializationSettings;
|
|
||||||
import org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.ConditionContext;
|
|
||||||
import org.springframework.context.annotation.DependsOn;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata;
|
|
||||||
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Configuration for {@link DataSource} initialization using a
|
|
||||||
* {@link DataSourceScriptDatabaseInitializer} with DDL and DML scripts.
|
|
||||||
*
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class DataSourceInitializationConfiguration {
|
|
||||||
|
|
||||||
private static DataSource determineDataSource(Supplier<DataSource> dataSource, String username, String password) {
|
|
||||||
if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
|
|
||||||
return DataSourceBuilder.derivedFrom(dataSource.get()).type(SimpleDriverDataSource.class).username(username)
|
|
||||||
.password(password).build();
|
|
||||||
}
|
|
||||||
return dataSource.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<String> scriptLocations(List<String> locations, String fallback, String platform) {
|
|
||||||
if (locations != null) {
|
|
||||||
return locations;
|
|
||||||
}
|
|
||||||
List<String> fallbackLocations = new ArrayList<>();
|
|
||||||
fallbackLocations.add("optional:classpath*:" + fallback + "-" + platform + ".sql");
|
|
||||||
fallbackLocations.add("optional:classpath*:" + fallback + ".sql");
|
|
||||||
return fallbackLocations;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DatabaseInitializationMode mapMode(org.springframework.boot.jdbc.DataSourceInitializationMode mode) {
|
|
||||||
switch (mode) {
|
|
||||||
case ALWAYS:
|
|
||||||
return DatabaseInitializationMode.ALWAYS;
|
|
||||||
case EMBEDDED:
|
|
||||||
return DatabaseInitializationMode.EMBEDDED;
|
|
||||||
case NEVER:
|
|
||||||
return DatabaseInitializationMode.NEVER;
|
|
||||||
default:
|
|
||||||
throw new IllegalStateException("Unexpected initialization mode '" + mode + "'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fully-qualified to work around javac bug in JDK 1.8
|
|
||||||
@org.springframework.context.annotation.Configuration(proxyBeanMethods = false)
|
|
||||||
@org.springframework.context.annotation.Conditional(DifferentCredentialsCondition.class)
|
|
||||||
@org.springframework.context.annotation.Import(DatabaseInitializationDependencyConfigurer.class)
|
|
||||||
@ConditionalOnSingleCandidate(DataSource.class)
|
|
||||||
@ConditionalOnMissingBean(DataSourceScriptDatabaseInitializer.class)
|
|
||||||
static class InitializationSpecificCredentialsDataSourceInitializationConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
SqlDataSourceScriptDatabaseInitializer ddlOnlyScriptDataSourceInitializer(ObjectProvider<DataSource> dataSource,
|
|
||||||
DataSourceProperties properties) {
|
|
||||||
DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
|
|
||||||
settings.setSchemaLocations(scriptLocations(properties.getSchema(), "schema", properties.getPlatform()));
|
|
||||||
settings.setContinueOnError(properties.isContinueOnError());
|
|
||||||
settings.setSeparator(properties.getSeparator());
|
|
||||||
settings.setEncoding(properties.getSqlScriptEncoding());
|
|
||||||
settings.setMode(mapMode(properties.getInitializationMode()));
|
|
||||||
DataSource initializationDataSource = determineDataSource(dataSource::getObject,
|
|
||||||
properties.getSchemaUsername(), properties.getSchemaPassword());
|
|
||||||
return new SqlDataSourceScriptDatabaseInitializer(initializationDataSource, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@DependsOn("ddlOnlyScriptDataSourceInitializer")
|
|
||||||
SqlDataSourceScriptDatabaseInitializer dmlOnlyScriptDataSourceInitializer(ObjectProvider<DataSource> dataSource,
|
|
||||||
DataSourceProperties properties) {
|
|
||||||
DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
|
|
||||||
settings.setDataLocations(scriptLocations(properties.getData(), "data", properties.getPlatform()));
|
|
||||||
settings.setContinueOnError(properties.isContinueOnError());
|
|
||||||
settings.setSeparator(properties.getSeparator());
|
|
||||||
settings.setEncoding(properties.getSqlScriptEncoding());
|
|
||||||
settings.setMode(mapMode(properties.getInitializationMode()));
|
|
||||||
DataSource initializationDataSource = determineDataSource(dataSource::getObject,
|
|
||||||
properties.getDataUsername(), properties.getDataPassword());
|
|
||||||
return new SqlDataSourceScriptDatabaseInitializer(initializationDataSource, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
static class DifferentCredentialsCondition extends AnyNestedCondition {
|
|
||||||
|
|
||||||
DifferentCredentialsCondition() {
|
|
||||||
super(ConfigurationPhase.PARSE_CONFIGURATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ConditionalOnProperty(prefix = "spring.datasource", name = "schema-username")
|
|
||||||
static class SchemaCredentials {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ConditionalOnProperty(prefix = "spring.datasource", name = "data-username")
|
|
||||||
static class DataCredentials {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fully-qualified to work around javac bug in JDK 1.8
|
|
||||||
@org.springframework.context.annotation.Configuration(proxyBeanMethods = false)
|
|
||||||
@org.springframework.context.annotation.Import(DatabaseInitializationDependencyConfigurer.class)
|
|
||||||
@org.springframework.context.annotation.Conditional(DataSourceInitializationCondition.class)
|
|
||||||
@ConditionalOnSingleCandidate(DataSource.class)
|
|
||||||
@ConditionalOnMissingBean(DataSourceScriptDatabaseInitializer.class)
|
|
||||||
static class SharedCredentialsDataSourceInitializationConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
SqlDataSourceScriptDatabaseInitializer scriptDataSourceInitializer(DataSource dataSource,
|
|
||||||
DataSourceProperties properties) {
|
|
||||||
DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
|
|
||||||
settings.setSchemaLocations(scriptLocations(properties.getSchema(), "schema", properties.getPlatform()));
|
|
||||||
settings.setDataLocations(scriptLocations(properties.getData(), "data", properties.getPlatform()));
|
|
||||||
settings.setContinueOnError(properties.isContinueOnError());
|
|
||||||
settings.setSeparator(properties.getSeparator());
|
|
||||||
settings.setEncoding(properties.getSqlScriptEncoding());
|
|
||||||
settings.setMode(mapMode(properties.getInitializationMode()));
|
|
||||||
return new SqlDataSourceScriptDatabaseInitializer(dataSource, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
static class DataSourceInitializationCondition extends SpringBootCondition {
|
|
||||||
|
|
||||||
private static final Set<String> INITIALIZATION_PROPERTIES = Collections
|
|
||||||
.unmodifiableSet(new HashSet<>(Arrays.asList("spring.datasource.initialization-mode",
|
|
||||||
"spring.datasource.platform", "spring.datasource.schema", "spring.datasource.schema[0]",
|
|
||||||
"spring.datasource.schema-username", "spring.datasource.schema-password",
|
|
||||||
"spring.datasource.data", "spring.datasource.data[0]", "spring.datasource.data-username",
|
|
||||||
"spring.datasource.data-password", "spring.datasource.continue-on-error",
|
|
||||||
"spring.datasource.separator", "spring.datasource.sql-script-encoding")));
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
|
||||||
ConditionMessage.Builder message = ConditionMessage.forCondition("DataSource Initialization");
|
|
||||||
Environment environment = context.getEnvironment();
|
|
||||||
Set<String> configuredProperties = INITIALIZATION_PROPERTIES.stream()
|
|
||||||
.filter(environment::containsProperty).collect(Collectors.toSet());
|
|
||||||
if (configuredProperties.isEmpty()) {
|
|
||||||
return ConditionOutcome
|
|
||||||
.noMatch(message.didNotFind("configured properties").items(INITIALIZATION_PROPERTIES));
|
|
||||||
}
|
|
||||||
return ConditionOutcome.match(
|
|
||||||
message.found("configured property", "configured properties").items(configuredProperties));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,9 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.jdbc;
|
package org.springframework.boot.autoconfigure.jdbc;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -28,7 +26,6 @@ import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
|
|
||||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||||
import org.springframework.boot.jdbc.DatabaseDriver;
|
import org.springframework.boot.jdbc.DatabaseDriver;
|
||||||
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
||||||
|
|
@ -95,73 +92,6 @@ public class DataSourceProperties implements BeanClassLoaderAware, InitializingB
|
||||||
*/
|
*/
|
||||||
private String jndiName;
|
private String jndiName;
|
||||||
|
|
||||||
/**
|
|
||||||
* Mode to apply when determining if DataSource initialization should be performed
|
|
||||||
* using the available DDL and DML scripts.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private org.springframework.boot.jdbc.DataSourceInitializationMode initializationMode = org.springframework.boot.jdbc.DataSourceInitializationMode.EMBEDDED;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Platform to use in the DDL or DML scripts (such as schema-${platform}.sql or
|
|
||||||
* data-${platform}.sql).
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private String platform = "all";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Schema (DDL) script resource references.
|
|
||||||
*/
|
|
||||||
private List<String> schema;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Username of the database to execute DDL scripts (if different).
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private String schemaUsername;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Password of the database to execute DDL scripts (if different).
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private String schemaPassword;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data (DML) script resource references.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private List<String> data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Username of the database to execute DML scripts (if different).
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private String dataUsername;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Password of the database to execute DML scripts (if different).
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private String dataPassword;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether to stop if an error occurs while initializing the database.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private boolean continueOnError = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Statement separator in SQL initialization scripts.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private String separator = ";";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SQL scripts encoding.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private Charset sqlScriptEncoding;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connection details for an embedded database. Defaults to the most suitable embedded
|
* Connection details for an embedded database. Defaults to the most suitable embedded
|
||||||
* database that is available on the classpath.
|
* database that is available on the classpath.
|
||||||
|
|
@ -391,127 +321,6 @@ public class DataSourceProperties implements BeanClassLoaderAware, InitializingB
|
||||||
this.jndiName = jndiName;
|
this.jndiName = jndiName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.sql.init.mode")
|
|
||||||
public org.springframework.boot.jdbc.DataSourceInitializationMode getInitializationMode() {
|
|
||||||
return this.initializationMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setInitializationMode(org.springframework.boot.jdbc.DataSourceInitializationMode initializationMode) {
|
|
||||||
this.initializationMode = initializationMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.sql.init.platform")
|
|
||||||
public String getPlatform() {
|
|
||||||
return this.platform;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setPlatform(String platform) {
|
|
||||||
this.platform = platform;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.sql.init.schema-locations")
|
|
||||||
public List<String> getSchema() {
|
|
||||||
return this.schema;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setSchema(List<String> schema) {
|
|
||||||
this.schema = schema;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.sql.init.username")
|
|
||||||
public String getSchemaUsername() {
|
|
||||||
return this.schemaUsername;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setSchemaUsername(String schemaUsername) {
|
|
||||||
this.schemaUsername = schemaUsername;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.sql.init.password")
|
|
||||||
public String getSchemaPassword() {
|
|
||||||
return this.schemaPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setSchemaPassword(String schemaPassword) {
|
|
||||||
this.schemaPassword = schemaPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.sql.init.data-locations")
|
|
||||||
public List<String> getData() {
|
|
||||||
return this.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setData(List<String> data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.sql.init.username")
|
|
||||||
public String getDataUsername() {
|
|
||||||
return this.dataUsername;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setDataUsername(String dataUsername) {
|
|
||||||
this.dataUsername = dataUsername;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.sql.init.password")
|
|
||||||
public String getDataPassword() {
|
|
||||||
return this.dataPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setDataPassword(String dataPassword) {
|
|
||||||
this.dataPassword = dataPassword;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.sql.init.continue-on-error")
|
|
||||||
public boolean isContinueOnError() {
|
|
||||||
return this.continueOnError;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setContinueOnError(boolean continueOnError) {
|
|
||||||
this.continueOnError = continueOnError;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.sql.init.separator")
|
|
||||||
public String getSeparator() {
|
|
||||||
return this.separator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setSeparator(String separator) {
|
|
||||||
this.separator = separator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.sql.init.encoding")
|
|
||||||
public Charset getSqlScriptEncoding() {
|
|
||||||
return this.sqlScriptEncoding;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setSqlScriptEncoding(Charset sqlScriptEncoding) {
|
|
||||||
this.sqlScriptEncoding = sqlScriptEncoding;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EmbeddedDatabaseConnection getEmbeddedDatabaseConnection() {
|
public EmbeddedDatabaseConnection getEmbeddedDatabaseConnection() {
|
||||||
return this.embeddedDatabaseConnection;
|
return this.embeddedDatabaseConnection;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2020 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,15 +17,11 @@
|
||||||
package org.springframework.boot.autoconfigure.jms.artemis;
|
package org.springframework.boot.autoconfigure.jms.artemis;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
import org.apache.activemq.artemis.api.core.TransportConfiguration;
|
||||||
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
|
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
|
||||||
import org.apache.activemq.artemis.api.core.client.ServerLocator;
|
import org.apache.activemq.artemis.api.core.client.ServerLocator;
|
||||||
import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory;
|
import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory;
|
||||||
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
|
|
||||||
import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
|
|
||||||
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||||
|
|
||||||
import org.springframework.beans.factory.ListableBeanFactory;
|
import org.springframework.beans.factory.ListableBeanFactory;
|
||||||
|
|
@ -139,18 +135,7 @@ class ArtemisConnectionFactoryFactory {
|
||||||
return connectionFactory;
|
return connectionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private <T extends ActiveMQConnectionFactory> T newNativeConnectionFactory(Class<T> factoryClass) throws Exception {
|
private <T extends ActiveMQConnectionFactory> T newNativeConnectionFactory(Class<T> factoryClass) throws Exception {
|
||||||
// Fallback if the broker url is not set
|
|
||||||
if (!StringUtils.hasText(this.properties.getBrokerUrl()) && StringUtils.hasText(this.properties.getHost())) {
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
|
||||||
params.put(TransportConstants.HOST_PROP_NAME, this.properties.getHost());
|
|
||||||
params.put(TransportConstants.PORT_PROP_NAME, this.properties.getPort());
|
|
||||||
TransportConfiguration transportConfiguration = new TransportConfiguration(
|
|
||||||
NettyConnectorFactory.class.getName(), params);
|
|
||||||
Constructor<T> constructor = factoryClass.getConstructor(boolean.class, TransportConfiguration[].class);
|
|
||||||
return constructor.newInstance(false, new TransportConfiguration[] { transportConfiguration });
|
|
||||||
}
|
|
||||||
String brokerUrl = StringUtils.hasText(this.properties.getBrokerUrl()) ? this.properties.getBrokerUrl()
|
String brokerUrl = StringUtils.hasText(this.properties.getBrokerUrl()) ? this.properties.getBrokerUrl()
|
||||||
: DEFAULT_BROKER_URL;
|
: DEFAULT_BROKER_URL;
|
||||||
Constructor<T> constructor = factoryClass.getConstructor(String.class);
|
Constructor<T> constructor = factoryClass.getConstructor(String.class);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants;
|
import org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration properties for Artemis.
|
* Configuration properties for Artemis.
|
||||||
|
|
@ -47,16 +46,6 @@ public class ArtemisProperties {
|
||||||
*/
|
*/
|
||||||
private String brokerUrl;
|
private String brokerUrl;
|
||||||
|
|
||||||
/**
|
|
||||||
* Artemis broker host.
|
|
||||||
*/
|
|
||||||
private String host;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Artemis broker port.
|
|
||||||
*/
|
|
||||||
private int port = 61616;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Login user of the broker.
|
* Login user of the broker.
|
||||||
*/
|
*/
|
||||||
|
|
@ -85,38 +74,6 @@ public class ArtemisProperties {
|
||||||
this.brokerUrl = brokerUrl;
|
this.brokerUrl = brokerUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the host of the broker.
|
|
||||||
* @return the host
|
|
||||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of broker url
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.artemis.broker-url")
|
|
||||||
public String getHost() {
|
|
||||||
return this.host;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setHost(String host) {
|
|
||||||
this.host = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the port of the broker.
|
|
||||||
* @return the port
|
|
||||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of broker url
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "spring.artemis.broker-url")
|
|
||||||
public int getPort() {
|
|
||||||
return this.port;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void setPort(int port) {
|
|
||||||
this.port = port;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUser() {
|
public String getUser() {
|
||||||
return this.user;
|
return this.user;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -133,9 +133,7 @@ public class QuartzAutoConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@SuppressWarnings("deprecation")
|
@ConditionalOnMissingBean(QuartzDataSourceScriptDatabaseInitializer.class)
|
||||||
@ConditionalOnMissingBean({ QuartzDataSourceScriptDatabaseInitializer.class,
|
|
||||||
QuartzDataSourceInitializer.class })
|
|
||||||
@Conditional(OnQuartzDatasourceInitializationCondition.class)
|
@Conditional(OnQuartzDatasourceInitializationCondition.class)
|
||||||
public QuartzDataSourceScriptDatabaseInitializer quartzDataSourceScriptDatabaseInitializer(
|
public QuartzDataSourceScriptDatabaseInitializer quartzDataSourceScriptDatabaseInitializer(
|
||||||
DataSource dataSource, @QuartzDataSource ObjectProvider<DataSource> quartzDataSource,
|
DataSource dataSource, @QuartzDataSource ObjectProvider<DataSource> quartzDataSource,
|
||||||
|
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.quartz;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.springframework.boot.sql.init.DatabaseInitializationMode;
|
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the Quartz Scheduler schema.
|
|
||||||
*
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @since 2.0.0
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link QuartzDataSourceScriptDatabaseInitializer}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class QuartzDataSourceInitializer extends org.springframework.boot.jdbc.AbstractDataSourceInitializer {
|
|
||||||
|
|
||||||
private final QuartzProperties properties;
|
|
||||||
|
|
||||||
public QuartzDataSourceInitializer(DataSource dataSource, ResourceLoader resourceLoader,
|
|
||||||
QuartzProperties properties) {
|
|
||||||
super(dataSource, resourceLoader);
|
|
||||||
Assert.notNull(properties, "QuartzProperties must not be null");
|
|
||||||
this.properties = properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void customize(ResourceDatabasePopulator populator) {
|
|
||||||
populator.setCommentPrefixes(this.properties.getJdbc().getCommentPrefix().toArray(new String[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected org.springframework.boot.jdbc.DataSourceInitializationMode getMode() {
|
|
||||||
DatabaseInitializationMode mode = this.properties.getJdbc().getInitializeSchema();
|
|
||||||
switch (mode) {
|
|
||||||
case ALWAYS:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.ALWAYS;
|
|
||||||
case EMBEDDED:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.EMBEDDED;
|
|
||||||
case NEVER:
|
|
||||||
default:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.NEVER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getSchemaLocation() {
|
|
||||||
return this.properties.getJdbc().getSchema();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getDatabaseName() {
|
|
||||||
String platform = this.properties.getJdbc().getPlatform();
|
|
||||||
if (StringUtils.hasText(platform)) {
|
|
||||||
return platform;
|
|
||||||
}
|
|
||||||
String databaseName = super.getDatabaseName();
|
|
||||||
if ("db2".equals(databaseName)) {
|
|
||||||
return "db2_v95";
|
|
||||||
}
|
|
||||||
if ("mysql".equals(databaseName) || "mariadb".equals(databaseName)) {
|
|
||||||
return "mysql_innodb";
|
|
||||||
}
|
|
||||||
if ("postgresql".equals(databaseName)) {
|
|
||||||
return "postgres";
|
|
||||||
}
|
|
||||||
if ("sqlserver".equals(databaseName)) {
|
|
||||||
return "sqlServer";
|
|
||||||
}
|
|
||||||
return databaseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -56,9 +56,7 @@ import org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessi
|
||||||
class JdbcSessionConfiguration {
|
class JdbcSessionConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@SuppressWarnings("deprecation")
|
@ConditionalOnMissingBean(JdbcSessionDataSourceScriptDatabaseInitializer.class)
|
||||||
@ConditionalOnMissingBean({ JdbcSessionDataSourceScriptDatabaseInitializer.class,
|
|
||||||
JdbcSessionDataSourceInitializer.class })
|
|
||||||
@Conditional(OnJdbcSessionDatasourceInitializationCondition.class)
|
@Conditional(OnJdbcSessionDatasourceInitializationCondition.class)
|
||||||
JdbcSessionDataSourceScriptDatabaseInitializer jdbcSessionDataSourceScriptDatabaseInitializer(
|
JdbcSessionDataSourceScriptDatabaseInitializer jdbcSessionDataSourceScriptDatabaseInitializer(
|
||||||
@SpringSessionDataSource ObjectProvider<DataSource> sessionDataSource,
|
@SpringSessionDataSource ObjectProvider<DataSource> sessionDataSource,
|
||||||
|
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.session;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.springframework.boot.sql.init.DatabaseInitializationMode;
|
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializer for Spring Session schema.
|
|
||||||
*
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @since 1.4.0
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link JdbcSessionDataSourceScriptDatabaseInitializer}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class JdbcSessionDataSourceInitializer extends org.springframework.boot.jdbc.AbstractDataSourceInitializer {
|
|
||||||
|
|
||||||
private final JdbcSessionProperties properties;
|
|
||||||
|
|
||||||
public JdbcSessionDataSourceInitializer(DataSource dataSource, ResourceLoader resourceLoader,
|
|
||||||
JdbcSessionProperties properties) {
|
|
||||||
super(dataSource, resourceLoader);
|
|
||||||
Assert.notNull(properties, "JdbcSessionProperties must not be null");
|
|
||||||
this.properties = properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected org.springframework.boot.jdbc.DataSourceInitializationMode getMode() {
|
|
||||||
DatabaseInitializationMode mode = this.properties.getInitializeSchema();
|
|
||||||
switch (mode) {
|
|
||||||
case ALWAYS:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.ALWAYS;
|
|
||||||
case EMBEDDED:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.EMBEDDED;
|
|
||||||
case NEVER:
|
|
||||||
default:
|
|
||||||
return org.springframework.boot.jdbc.DataSourceInitializationMode.NEVER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getSchemaLocation() {
|
|
||||||
return this.properties.getSchema();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getDatabaseName() {
|
|
||||||
String platform = this.properties.getPlatform();
|
|
||||||
if (StringUtils.hasText(platform)) {
|
|
||||||
return platform;
|
|
||||||
}
|
|
||||||
return super.getDatabaseName();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.boot.autoconfigure.web.reactive;
|
package org.springframework.boot.autoconfigure.web.reactive;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -36,8 +35,6 @@ public class WebFluxProperties {
|
||||||
|
|
||||||
private final Format format = new Format();
|
private final Format format = new Format();
|
||||||
|
|
||||||
private final Session session = new Session();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path pattern used for static resources.
|
* Path pattern used for static resources.
|
||||||
*/
|
*/
|
||||||
|
|
@ -71,11 +68,6 @@ public class WebFluxProperties {
|
||||||
return this.format;
|
return this.format;
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "server.reactive.session")
|
|
||||||
public Session getSession() {
|
|
||||||
return this.session;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStaticPathPattern() {
|
public String getStaticPathPattern() {
|
||||||
return this.staticPathPattern;
|
return this.staticPathPattern;
|
||||||
}
|
}
|
||||||
|
|
@ -127,84 +119,4 @@ public class WebFluxProperties {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Session properties.
|
|
||||||
*
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@code server.reactive.session}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static class Session {
|
|
||||||
|
|
||||||
private final Cookie cookie = new Cookie();
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "server.reactive.session.cookie")
|
|
||||||
public Cookie getCookie() {
|
|
||||||
return this.cookie;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Session cookie properties.
|
|
||||||
*
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link org.springframework.boot.web.server.Cookie}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static class Cookie {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SameSite attribute value for session Cookies.
|
|
||||||
*/
|
|
||||||
private SameSite sameSite;
|
|
||||||
|
|
||||||
@DeprecatedConfigurationProperty(replacement = "server.reactive.session.cookie.same-site")
|
|
||||||
public SameSite getSameSite() {
|
|
||||||
return this.sameSite;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSameSite(SameSite sameSite) {
|
|
||||||
this.sameSite = sameSite;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SameSite values.
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link org.springframework.boot.web.server.Cookie.SameSite}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public enum SameSite {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cookies are sent in both first-party and cross-origin requests.
|
|
||||||
*/
|
|
||||||
NONE("None"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cookies are sent in a first-party context, also when following a link to the
|
|
||||||
* origin site.
|
|
||||||
*/
|
|
||||||
LAX("Lax"),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cookies are only sent in a first-party context (i.e. not when following a link
|
|
||||||
* to the origin site).
|
|
||||||
*/
|
|
||||||
STRICT("Strict");
|
|
||||||
|
|
||||||
private final String attribute;
|
|
||||||
|
|
||||||
SameSite(String attribute) {
|
|
||||||
this.attribute = attribute;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String attribute() {
|
|
||||||
return this.attribute;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -23,8 +23,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.PropertyMapper;
|
import org.springframework.boot.context.properties.PropertyMapper;
|
||||||
import org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException;
|
|
||||||
import org.springframework.boot.web.server.Cookie;
|
import org.springframework.boot.web.server.Cookie;
|
||||||
|
import org.springframework.boot.web.server.Cookie.SameSite;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.ResponseCookie.ResponseCookieBuilder;
|
import org.springframework.http.ResponseCookie.ResponseCookieBuilder;
|
||||||
|
|
@ -48,24 +48,9 @@ public class WebSessionIdResolverAutoConfiguration {
|
||||||
|
|
||||||
private final ServerProperties serverProperties;
|
private final ServerProperties serverProperties;
|
||||||
|
|
||||||
private final WebFluxProperties webFluxProperties;
|
|
||||||
|
|
||||||
public WebSessionIdResolverAutoConfiguration(ServerProperties serverProperties,
|
public WebSessionIdResolverAutoConfiguration(ServerProperties serverProperties,
|
||||||
WebFluxProperties webFluxProperties) {
|
WebFluxProperties webFluxProperties) {
|
||||||
this.serverProperties = serverProperties;
|
this.serverProperties = serverProperties;
|
||||||
this.webFluxProperties = webFluxProperties;
|
|
||||||
assertNoMutuallyExclusiveProperties(serverProperties, webFluxProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private void assertNoMutuallyExclusiveProperties(ServerProperties serverProperties,
|
|
||||||
WebFluxProperties webFluxProperties) {
|
|
||||||
MutuallyExclusiveConfigurationPropertiesException.throwIfMultipleNonNullValuesIn((entries) -> {
|
|
||||||
entries.put("spring.webflux.session.cookie.same-site",
|
|
||||||
webFluxProperties.getSession().getCookie().getSameSite());
|
|
||||||
entries.put("server.reactive.session.cookie.same-site",
|
|
||||||
serverProperties.getReactive().getSession().getCookie().getSameSite());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
@ -91,16 +76,9 @@ public class WebSessionIdResolverAutoConfiguration {
|
||||||
map.from(getSameSite(cookie)).to(builder::sameSite);
|
map.from(getSameSite(cookie)).to(builder::sameSite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
private String getSameSite(Cookie properties) {
|
private String getSameSite(Cookie properties) {
|
||||||
if (properties.getSameSite() != null) {
|
SameSite sameSite = properties.getSameSite();
|
||||||
return properties.getSameSite().attributeValue();
|
return (sameSite != null) ? sameSite.attributeValue() : null;
|
||||||
}
|
|
||||||
WebFluxProperties.Cookie deprecatedProperties = this.webFluxProperties.getSession().getCookie();
|
|
||||||
if (deprecatedProperties.getSameSite() != null) {
|
|
||||||
return deprecatedProperties.getSameSite().attribute();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -30,7 +30,6 @@ import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders;
|
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders;
|
||||||
import org.springframework.boot.autoconfigure.web.WebProperties.Resources;
|
import org.springframework.boot.autoconfigure.web.WebProperties.Resources;
|
||||||
import org.springframework.boot.web.error.ErrorAttributeOptions;
|
import org.springframework.boot.web.error.ErrorAttributeOptions;
|
||||||
import org.springframework.boot.web.error.ErrorAttributeOptions.Include;
|
|
||||||
import org.springframework.boot.web.reactive.error.ErrorAttributes;
|
import org.springframework.boot.web.reactive.error.ErrorAttributes;
|
||||||
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
|
import org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
@ -136,21 +135,6 @@ public abstract class AbstractErrorWebExceptionHandler implements ErrorWebExcept
|
||||||
this.viewResolvers = viewResolvers;
|
this.viewResolvers = viewResolvers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract the error attributes from the current request, to be used to populate error
|
|
||||||
* views or JSON payloads.
|
|
||||||
* @param request the source request
|
|
||||||
* @param includeStackTrace whether to include the error stacktrace information
|
|
||||||
* @return the error attributes as a Map
|
|
||||||
* @deprecated since 2.3.0 for removal in 2.5.0 in favor of
|
|
||||||
* {@link #getErrorAttributes(ServerRequest, ErrorAttributeOptions)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected Map<String, Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace) {
|
|
||||||
return getErrorAttributes(request,
|
|
||||||
(includeStackTrace) ? ErrorAttributeOptions.of(Include.STACK_TRACE) : ErrorAttributeOptions.defaults());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract the error attributes from the current request, to be used to populate error
|
* Extract the error attributes from the current request, to be used to populate error
|
||||||
* views or JSON payloads.
|
* views or JSON payloads.
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.batch;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import org.springframework.core.io.DefaultResourceLoader;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verifyNoInteractions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link BatchDataSourceInitializer}.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class BatchDataSourceInitializerTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getDatabaseNameWithPlatformDoesNotTouchDataSource() {
|
|
||||||
DataSource dataSource = mock(DataSource.class);
|
|
||||||
BatchProperties properties = new BatchProperties();
|
|
||||||
properties.getJdbc().setPlatform("test");
|
|
||||||
BatchDataSourceInitializer initializer = new BatchDataSourceInitializer(dataSource, new DefaultResourceLoader(),
|
|
||||||
properties);
|
|
||||||
assertThat(initializer.getDatabaseName()).isEqualTo("test");
|
|
||||||
verifyNoInteractions(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -16,10 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.data.elasticsearch;
|
package org.springframework.boot.autoconfigure.data.elasticsearch;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
@ -28,8 +24,6 @@ import java.util.List;
|
||||||
|
|
||||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
|
|
@ -81,33 +75,6 @@ class ReactiveElasticsearchRestClientAutoConfigurationTests {
|
||||||
.hasSingleBean(ClientConfiguration.class).hasBean("customClientConfiguration"));
|
.hasSingleBean(ClientConfiguration.class).hasBean("customClientConfiguration"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void whenEndpointIsCustomizedThenClientConfigurationHasCustomEndpoint() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.data.elasticsearch.client.reactive.endpoints=localhost:9876")
|
|
||||||
.run((context) -> {
|
|
||||||
List<InetSocketAddress> endpoints = context.getBean(ClientConfiguration.class).getEndpoints();
|
|
||||||
assertThat(endpoints).hasSize(1);
|
|
||||||
assertThat(endpoints.get(0).getHostString()).isEqualTo("localhost");
|
|
||||||
assertThat(endpoints.get(0).getPort()).isEqualTo(9876);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void whenMultipleEndpointsAreConfiguredThenClientConfigurationHasMultipleEndpoints() {
|
|
||||||
this.contextRunner
|
|
||||||
.withPropertyValues("spring.data.elasticsearch.client.reactive.endpoints=localhost:9876,localhost:8765")
|
|
||||||
.run((context) -> {
|
|
||||||
List<InetSocketAddress> endpoints = context.getBean(ClientConfiguration.class).getEndpoints();
|
|
||||||
assertThat(endpoints).hasSize(2);
|
|
||||||
assertThat(endpoints.get(0).getHostString()).isEqualTo("localhost");
|
|
||||||
assertThat(endpoints.get(0).getPort()).isEqualTo(9876);
|
|
||||||
assertThat(endpoints.get(1).getHostString()).isEqualTo("localhost");
|
|
||||||
assertThat(endpoints.get(1).getPort()).isEqualTo(8765);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenUriIsCustomizedThenClientConfigurationHasCustomEndpoint() {
|
void whenUriIsCustomizedThenClientConfigurationHasCustomEndpoint() {
|
||||||
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=http://localhost:9876").run((context) -> {
|
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=http://localhost:9876").run((context) -> {
|
||||||
|
|
@ -223,13 +190,6 @@ class ReactiveElasticsearchRestClientAutoConfigurationTests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void whenConfiguredToUseSslThenClientConfigurationUsesSsl() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.data.elasticsearch.client.reactive.use-ssl=true")
|
|
||||||
.run((context) -> assertThat(context.getBean(ClientConfiguration.class).useSsl()).isTrue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenSocketTimeoutIsNotConfiguredThenClientConfigurationUsesDefault() {
|
void whenSocketTimeoutIsNotConfiguredThenClientConfigurationUsesDefault() {
|
||||||
this.contextRunner.run((context) -> assertThat(context.getBean(ClientConfiguration.class).getSocketTimeout())
|
this.contextRunner.run((context) -> assertThat(context.getBean(ClientConfiguration.class).getSocketTimeout())
|
||||||
|
|
@ -242,16 +202,16 @@ class ReactiveElasticsearchRestClientAutoConfigurationTests {
|
||||||
.isEqualTo(Duration.ofSeconds(1)));
|
.isEqualTo(Duration.ofSeconds(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedPropertyPrefixTest
|
@Test
|
||||||
void whenSocketTimeoutIsConfiguredThenClientConfigurationHasCustomSocketTimeout(String prefix) {
|
void whenSocketTimeoutIsConfiguredThenClientConfigurationHasCustomSocketTimeout() {
|
||||||
this.contextRunner.withPropertyValues(prefix + "socket-timeout=2s")
|
this.contextRunner.withPropertyValues("spring.elasticsearch.socket-timeout=2s")
|
||||||
.run((context) -> assertThat(context.getBean(ClientConfiguration.class).getSocketTimeout())
|
.run((context) -> assertThat(context.getBean(ClientConfiguration.class).getSocketTimeout())
|
||||||
.isEqualTo(Duration.ofSeconds(2)));
|
.isEqualTo(Duration.ofSeconds(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedPropertyPrefixTest
|
@Test
|
||||||
void whenConnectionTimeoutIsConfiguredThenClientConfigurationHasCustomConnectTimeout(String prefix) {
|
void whenConnectionTimeoutIsConfiguredThenClientConfigurationHasCustomConnectTimeout() {
|
||||||
this.contextRunner.withPropertyValues(prefix + "connection-timeout=2s")
|
this.contextRunner.withPropertyValues("spring.elasticsearch.connection-timeout=2s")
|
||||||
.run((context) -> assertThat(context.getBean(ClientConfiguration.class).getConnectTimeout())
|
.run((context) -> assertThat(context.getBean(ClientConfiguration.class).getConnectTimeout())
|
||||||
.isEqualTo(Duration.ofSeconds(2)));
|
.isEqualTo(Duration.ofSeconds(2)));
|
||||||
}
|
}
|
||||||
|
|
@ -263,19 +223,21 @@ class ReactiveElasticsearchRestClientAutoConfigurationTests {
|
||||||
.isEqualTo("/some/prefix"));
|
.isEqualTo("/some/prefix"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedPropertyPrefixTest
|
@Test
|
||||||
void whenCredentialsAreConfiguredThenClientConfigurationHasDefaultAuthorizationHeader(String prefix) {
|
void whenCredentialsAreConfiguredThenClientConfigurationHasDefaultAuthorizationHeader() {
|
||||||
this.contextRunner.withPropertyValues(prefix + "username=alice", prefix + "password=secret")
|
this.contextRunner
|
||||||
|
.withPropertyValues("spring.elasticsearch.username=alice", "spring.elasticsearch.password=secret")
|
||||||
.run((context) -> assertThat(
|
.run((context) -> assertThat(
|
||||||
context.getBean(ClientConfiguration.class).getDefaultHeaders().get(HttpHeaders.AUTHORIZATION))
|
context.getBean(ClientConfiguration.class).getDefaultHeaders().get(HttpHeaders.AUTHORIZATION))
|
||||||
.containsExactly("Basic YWxpY2U6c2VjcmV0"));
|
.containsExactly("Basic YWxpY2U6c2VjcmV0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@Test
|
||||||
@ValueSource(strings = { "spring.elasticsearch.webclient.", "spring.data.elasticsearch.client.reactive." })
|
void whenMaxInMemorySizeIsConfiguredThenUnderlyingWebClientHasCustomMaxInMemorySize() {
|
||||||
void whenMaxInMemorySizeIsConfiguredThenUnderlyingWebClientHasCustomMaxInMemorySize(String prefix) {
|
this.contextRunner.withPropertyValues("spring.elasticsearch.webclient.max-in-memory-size=1MB")
|
||||||
this.contextRunner.withPropertyValues(prefix + "max-in-memory-size=1MB").run((context) -> {
|
.run((context) -> {
|
||||||
WebClient client = configureWebClient(context.getBean(ClientConfiguration.class).getClientConfigurers());
|
WebClient client = configureWebClient(
|
||||||
|
context.getBean(ClientConfiguration.class).getClientConfigurers());
|
||||||
assertThat(client).extracting("exchangeFunction.strategies.codecConfigurer.defaultCodecs")
|
assertThat(client).extracting("exchangeFunction.strategies.codecConfigurer.defaultCodecs")
|
||||||
.asInstanceOf(InstanceOfAssertFactories.type(DefaultCodecConfig.class))
|
.asInstanceOf(InstanceOfAssertFactories.type(DefaultCodecConfig.class))
|
||||||
.extracting(DefaultCodecConfig::maxInMemorySize).isEqualTo(1024 * 1024);
|
.extracting(DefaultCodecConfig::maxInMemorySize).isEqualTo(1024 * 1024);
|
||||||
|
|
@ -310,12 +272,4 @@ class ReactiveElasticsearchRestClientAutoConfigurationTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@ValueSource(strings = { "spring.data.elasticsearch.client.reactive.", "spring.elasticsearch." })
|
|
||||||
static @interface ParameterizedPropertyPrefixTest {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,10 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.elasticsearch;
|
package org.springframework.boot.autoconfigure.elasticsearch;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -35,8 +31,6 @@ import org.elasticsearch.client.RestClient;
|
||||||
import org.elasticsearch.client.RestClientBuilder;
|
import org.elasticsearch.client.RestClientBuilder;
|
||||||
import org.elasticsearch.client.sniff.Sniffer;
|
import org.elasticsearch.client.sniff.Sniffer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||||
|
|
@ -126,17 +120,6 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void configureWithLegacyCustomTimeouts() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.elasticsearch.rest.connection-timeout=15s",
|
|
||||||
"spring.elasticsearch.rest.read-timeout=1m").run((context) -> {
|
|
||||||
assertThat(context).hasSingleBean(org.elasticsearch.client.RestHighLevelClient.class);
|
|
||||||
org.elasticsearch.client.RestHighLevelClient restClient = context
|
|
||||||
.getBean(org.elasticsearch.client.RestHighLevelClient.class);
|
|
||||||
assertTimeouts(restClient, Duration.ofSeconds(15), Duration.ofMinutes(1));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void configureWithCustomTimeouts() {
|
void configureWithCustomTimeouts() {
|
||||||
this.contextRunner.withPropertyValues("spring.elasticsearch.connection-timeout=15s",
|
this.contextRunner.withPropertyValues("spring.elasticsearch.connection-timeout=15s",
|
||||||
|
|
@ -156,18 +139,18 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||||
.isEqualTo(Math.toIntExact(connectTimeout.toMillis()));
|
.isEqualTo(Math.toIntExact(connectTimeout.toMillis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedPropertyPrefixTest
|
@Test
|
||||||
void configureUriWithNoScheme(String prefix) {
|
void configureUriWithNoScheme() {
|
||||||
this.contextRunner.withPropertyValues(prefix + "uris=localhost:9876").run((context) -> {
|
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=localhost:9876").run((context) -> {
|
||||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
||||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||||
.containsExactly("http://localhost:9876");
|
.containsExactly("http://localhost:9876");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedPropertyPrefixTest
|
@Test
|
||||||
void configureUriWithUsernameOnly(String prefix) {
|
void configureUriWithUsernameOnly() {
|
||||||
this.contextRunner.withPropertyValues(prefix + "uris=http://user@localhost:9200").run((context) -> {
|
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=http://user@localhost:9200").run((context) -> {
|
||||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
||||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||||
.containsExactly("http://localhost:9200");
|
.containsExactly("http://localhost:9200");
|
||||||
|
|
@ -181,26 +164,32 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedPropertyPrefixTest
|
@Test
|
||||||
void configureUriWithUsernameAndEmptyPassword(String prefix) {
|
void configureUriWithUsernameAndEmptyPassword() {
|
||||||
this.contextRunner.withPropertyValues(prefix + "uris=http://user:@localhost:9200").run((context) -> {
|
this.contextRunner.withPropertyValues("spring.elasticsearch.uris=http://user:@localhost:9200")
|
||||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class).getLowLevelClient();
|
.run((context) -> {
|
||||||
|
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||||
|
.getLowLevelClient();
|
||||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||||
.containsExactly("http://localhost:9200");
|
.containsExactly("http://localhost:9200");
|
||||||
assertThat(client)
|
assertThat(client)
|
||||||
.extracting("client.credentialsProvider", InstanceOfAssertFactories.type(CredentialsProvider.class))
|
.extracting("client.credentialsProvider",
|
||||||
|
InstanceOfAssertFactories.type(CredentialsProvider.class))
|
||||||
.satisfies((credentialsProvider) -> {
|
.satisfies((credentialsProvider) -> {
|
||||||
Credentials credentials = credentialsProvider.getCredentials(new AuthScope("localhost", 9200));
|
Credentials credentials = credentialsProvider
|
||||||
|
.getCredentials(new AuthScope("localhost", 9200));
|
||||||
assertThat(credentials.getUserPrincipal().getName()).isEqualTo("user");
|
assertThat(credentials.getUserPrincipal().getName()).isEqualTo("user");
|
||||||
assertThat(credentials.getPassword()).isEmpty();
|
assertThat(credentials.getPassword()).isEmpty();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedPropertyPrefixTest
|
@Test
|
||||||
void configureUriWithUsernameAndPasswordWhenUsernameAndPasswordPropertiesSet(String prefix) {
|
void configureUriWithUsernameAndPasswordWhenUsernameAndPasswordPropertiesSet() {
|
||||||
this.contextRunner.withPropertyValues(prefix + "uris=http://user:password@localhost:9200,localhost:9201",
|
this.contextRunner
|
||||||
prefix + "username=admin", prefix + "password=admin").run((context) -> {
|
.withPropertyValues("spring.elasticsearch.uris=http://user:password@localhost:9200,localhost:9201",
|
||||||
|
"spring.elasticsearch.username=admin", "spring.elasticsearch.password=admin")
|
||||||
|
.run((context) -> {
|
||||||
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class)
|
RestClient client = context.getBean(org.elasticsearch.client.RestHighLevelClient.class)
|
||||||
.getLowLevelClient();
|
.getLowLevelClient();
|
||||||
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
assertThat(client.getNodes().stream().map(Node::getHost).map(HttpHost::toString))
|
||||||
|
|
@ -248,10 +237,10 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedSnifferPropertyPrefixTest
|
@Test
|
||||||
void configureWithCustomSnifferSettings(String prefix) {
|
void configureWithCustomSnifferSettings() {
|
||||||
this.contextRunner.withPropertyValues(prefix + "interval=180s", prefix + "delay-after-failure=30s")
|
this.contextRunner.withPropertyValues("spring.elasticsearch.restclient.sniffer.interval=180s",
|
||||||
.run((context) -> {
|
"spring.elasticsearch.restclient.sniffer.delay-after-failure=30s").run((context) -> {
|
||||||
assertThat(context).hasSingleBean(Sniffer.class);
|
assertThat(context).hasSingleBean(Sniffer.class);
|
||||||
Sniffer sniffer = context.getBean(Sniffer.class);
|
Sniffer sniffer = context.getBean(Sniffer.class);
|
||||||
assertThat(sniffer).hasFieldOrPropertyWithValue("sniffIntervalMillis",
|
assertThat(sniffer).hasFieldOrPropertyWithValue("sniffIntervalMillis",
|
||||||
|
|
@ -334,20 +323,4 @@ class ElasticsearchRestClientAutoConfigurationTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@ValueSource(strings = { "spring.elasticsearch.rest.", "spring.elasticsearch." })
|
|
||||||
static @interface ParameterizedPropertyPrefixTest {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@ValueSource(strings = { "spring.elasticsearch.rest.sniffer.", "spring.elasticsearch.restclient.sniffer." })
|
|
||||||
static @interface ParameterizedSnifferPropertyPrefixTest {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -51,7 +51,6 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.integration.annotation.IntegrationComponentScan;
|
import org.springframework.integration.annotation.IntegrationComponentScan;
|
||||||
import org.springframework.integration.annotation.MessagingGateway;
|
import org.springframework.integration.annotation.MessagingGateway;
|
||||||
import org.springframework.integration.annotation.ServiceActivator;
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
|
|
@ -386,18 +385,6 @@ class IntegrationAutoConfigurationTests {
|
||||||
.hasBean("customInitializer"));
|
.hasBean("customInitializer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
void whenTheUserDefinesTheirOwnIntegrationDataSourceInitializerThenTheAutoConfiguredInitializerBacksOff() {
|
|
||||||
this.contextRunner.withUserConfiguration(CustomIntegrationDataSourceInitializerConfiguration.class)
|
|
||||||
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class,
|
|
||||||
DataSourceTransactionManagerAutoConfiguration.class))
|
|
||||||
.run((context) -> assertThat(context)
|
|
||||||
.doesNotHaveBean(IntegrationDataSourceScriptDatabaseInitializer.class)
|
|
||||||
.hasSingleBean(IntegrationDataSourceInitializer.class).hasBean("customInitializer"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenTheUserDefinesTheirOwnDatabaseInitializerThenTheAutoConfiguredIntegrationInitializerRemains() {
|
void whenTheUserDefinesTheirOwnDatabaseInitializerThenTheAutoConfiguredIntegrationInitializerRemains() {
|
||||||
this.contextRunner.withUserConfiguration(CustomDatabaseInitializerConfiguration.class)
|
this.contextRunner.withUserConfiguration(CustomDatabaseInitializerConfiguration.class)
|
||||||
|
|
@ -578,18 +565,6 @@ class IntegrationAutoConfigurationTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
static class CustomIntegrationDataSourceInitializerConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
IntegrationDataSourceInitializer customInitializer(DataSource dataSource, ResourceLoader resourceLoader,
|
|
||||||
IntegrationProperties properties) {
|
|
||||||
return new IntegrationDataSourceInitializer(dataSource, resourceLoader, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
static class PollingConsumerConfiguration {
|
static class PollingConsumerConfiguration {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.integration;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import org.springframework.core.io.DefaultResourceLoader;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verifyNoInteractions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link IntegrationDataSourceInitializer}.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class IntegrationDataSourceInitializerTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getDatabaseNameWithPlatformDoesNotTouchDataSource() {
|
|
||||||
DataSource dataSource = mock(DataSource.class);
|
|
||||||
IntegrationProperties properties = new IntegrationProperties();
|
|
||||||
properties.getJdbc().setPlatform("test");
|
|
||||||
IntegrationDataSourceInitializer initializer = new IntegrationDataSourceInitializer(dataSource,
|
|
||||||
new DefaultResourceLoader(), properties);
|
|
||||||
assertThat(initializer.getDatabaseName()).isEqualTo("test");
|
|
||||||
verifyNoInteractions(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -39,18 +39,15 @@ import org.apache.commons.dbcp2.BasicDataSource;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.jdbc.DatabaseDriver;
|
import org.springframework.boot.jdbc.DatabaseDriver;
|
||||||
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
||||||
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
|
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
|
||||||
import org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitialization;
|
|
||||||
import org.springframework.boot.test.context.FilteredClassLoader;
|
import org.springframework.boot.test.context.FilteredClassLoader;
|
||||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
|
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
|
||||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
@ -235,16 +232,6 @@ class DataSourceAutoConfigurationTests {
|
||||||
.run((context) -> assertThat(context).getBean(DataSource.class).isInstanceOf(EmbeddedDatabase.class));
|
.run((context) -> assertThat(context).getBean(DataSource.class).isInstanceOf(EmbeddedDatabase.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void testDataSourceIsInitializedEarly() {
|
|
||||||
this.contextRunner.withUserConfiguration(TestInitializedDataSourceConfiguration.class)
|
|
||||||
.withPropertyValues("spring.datasource.initialization-mode=always").run((context) -> {
|
|
||||||
assertThat(context).hasSingleBean(DataSourceScriptDatabaseInitializer.class);
|
|
||||||
assertThat(context.getBean(TestInitializedDataSourceConfiguration.class).called).isTrue();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenNoInitializationRelatedSpringDataSourcePropertiesAreConfiguredThenInitializationBacksOff() {
|
void whenNoInitializationRelatedSpringDataSourcePropertiesAreConfiguredThenInitializationBacksOff() {
|
||||||
this.contextRunner
|
this.contextRunner
|
||||||
|
|
@ -282,22 +269,6 @@ class DataSourceAutoConfigurationTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
@DependsOnDatabaseInitialization
|
|
||||||
static class TestInitializedDataSourceConfiguration {
|
|
||||||
|
|
||||||
private boolean called;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
void validateDataSourceIsInitialized(DataSource dataSource) {
|
|
||||||
// Inject the datasource to validate it is initialized at the injection point
|
|
||||||
JdbcTemplate template = new JdbcTemplate(dataSource);
|
|
||||||
assertThat(template.queryForObject("SELECT COUNT(*) from BAR", Integer.class)).isEqualTo(1);
|
|
||||||
this.called = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// see testExplicitDriverClassClearsUsername
|
// see testExplicitDriverClassClearsUsername
|
||||||
public static class DatabaseTestDriver implements Driver {
|
public static class DatabaseTestDriver implements Driver {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,440 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.jdbc;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.SQLFeatureNotSupportedException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
|
||||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
||||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
|
||||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
|
||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
||||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Scope;
|
|
||||||
import org.springframework.context.support.SimpleThreadScope;
|
|
||||||
import org.springframework.core.io.DefaultResourceLoader;
|
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
|
||||||
import org.springframework.core.io.support.ResourcePatternUtils;
|
|
||||||
import org.springframework.jdbc.BadSqlGrammarException;
|
|
||||||
import org.springframework.jdbc.core.JdbcOperations;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.util.ClassUtils;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Integration tests for DataSource initialization.
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class DataSourceInitializationIntegrationTests {
|
|
||||||
|
|
||||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
||||||
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class))
|
|
||||||
.withPropertyValues("spring.datasource.initialization-mode=never",
|
|
||||||
"spring.datasource.url:jdbc:hsqldb:mem:init-" + UUID.randomUUID());
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void dataSourceInitialized() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.datasource.initialization-mode:always").run((context) -> {
|
|
||||||
assertThat(context).hasSingleBean(DataSource.class);
|
|
||||||
DataSource dataSource = context.getBean(DataSource.class);
|
|
||||||
assertThat(dataSource).isInstanceOf(HikariDataSource.class);
|
|
||||||
assertDataSourceIsInitialized(dataSource);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void initializationAppliesToCustomDataSource() {
|
|
||||||
this.contextRunner.withUserConfiguration(OneDataSource.class)
|
|
||||||
.withPropertyValues("spring.datasource.initialization-mode:always").run((context) -> {
|
|
||||||
assertThat(context).hasSingleBean(DataSource.class);
|
|
||||||
assertDataSourceIsInitialized(context.getBean(DataSource.class));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void initializationWithUsernameAndPasswordAppliesToCustomDataSource() {
|
|
||||||
this.contextRunner.withUserConfiguration(OneDataSource.class)
|
|
||||||
.withPropertyValues("spring.datasource.initialization-mode:always",
|
|
||||||
"spring.datasource.schema-username=test", "spring.datasource.schema-password=secret")
|
|
||||||
.run((context) -> {
|
|
||||||
assertThat(context).hasSingleBean(DataSource.class);
|
|
||||||
assertDataSourceIsInitialized(context.getBean(DataSource.class));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertDataSourceIsInitialized(DataSource dataSource) {
|
|
||||||
JdbcOperations template = new JdbcTemplate(dataSource);
|
|
||||||
assertThat(template.queryForObject("SELECT COUNT(*) from BAR", Integer.class)).isEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void dataSourceInitializedWithExplicitScript() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.datasource.initialization-mode:always",
|
|
||||||
"spring.datasource.schema:" + getRelativeLocationFor("schema.sql"),
|
|
||||||
"spring.datasource.data:" + getRelativeLocationFor("data.sql")).run((context) -> {
|
|
||||||
DataSource dataSource = context.getBean(DataSource.class);
|
|
||||||
assertThat(dataSource).isInstanceOf(HikariDataSource.class);
|
|
||||||
assertThat(dataSource).isNotNull();
|
|
||||||
JdbcOperations template = new JdbcTemplate(dataSource);
|
|
||||||
assertThat(template.queryForObject("SELECT COUNT(*) from FOO", Integer.class)).isEqualTo(1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void dataSourceInitializedWithMultipleScripts() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.datasource.initialization-mode:always",
|
|
||||||
"spring.datasource.schema:" + getRelativeLocationFor("schema.sql") + ","
|
|
||||||
+ getRelativeLocationFor("another.sql"),
|
|
||||||
"spring.datasource.data:" + getRelativeLocationFor("data.sql")).run((context) -> {
|
|
||||||
DataSource dataSource = context.getBean(DataSource.class);
|
|
||||||
assertThat(dataSource).isInstanceOf(HikariDataSource.class);
|
|
||||||
assertThat(dataSource).isNotNull();
|
|
||||||
JdbcOperations template = new JdbcTemplate(dataSource);
|
|
||||||
assertThat(template.queryForObject("SELECT COUNT(*) from FOO", Integer.class)).isEqualTo(1);
|
|
||||||
assertThat(template.queryForObject("SELECT COUNT(*) from SPAM", Integer.class)).isEqualTo(0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void dataSourceInitializedWithExplicitSqlScriptEncoding() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.datasource.initialization-mode:always",
|
|
||||||
"spring.datasource.sqlScriptEncoding:UTF-8",
|
|
||||||
"spring.datasource.schema:" + getRelativeLocationFor("encoding-schema.sql"),
|
|
||||||
"spring.datasource.data:" + getRelativeLocationFor("encoding-data.sql")).run((context) -> {
|
|
||||||
DataSource dataSource = context.getBean(DataSource.class);
|
|
||||||
assertThat(dataSource).isInstanceOf(HikariDataSource.class);
|
|
||||||
assertThat(dataSource).isNotNull();
|
|
||||||
JdbcOperations template = new JdbcTemplate(dataSource);
|
|
||||||
assertThat(template.queryForObject("SELECT COUNT(*) from BAR", Integer.class)).isEqualTo(2);
|
|
||||||
assertThat(template.queryForObject("SELECT name from BAR WHERE id=1", String.class))
|
|
||||||
.isEqualTo("bar");
|
|
||||||
assertThat(template.queryForObject("SELECT name from BAR WHERE id=2", String.class))
|
|
||||||
.isEqualTo("ばー");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void initializationDisabled() {
|
|
||||||
this.contextRunner.run(assertInitializationIsDisabled());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void initializationDoesNotApplyWithSeveralDataSources() {
|
|
||||||
this.contextRunner.withUserConfiguration(TwoDataSources.class)
|
|
||||||
.withPropertyValues("spring.datasource.initialization-mode:always").run((context) -> {
|
|
||||||
assertThat(context.getBeanNamesForType(DataSource.class)).hasSize(2);
|
|
||||||
assertDataSourceNotInitialized(context.getBean("oneDataSource", DataSource.class));
|
|
||||||
assertDataSourceNotInitialized(context.getBean("twoDataSource", DataSource.class));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private ContextConsumer<AssertableApplicationContext> assertInitializationIsDisabled() {
|
|
||||||
return (context) -> {
|
|
||||||
assertThat(context).hasSingleBean(DataSource.class);
|
|
||||||
DataSource dataSource = context.getBean(DataSource.class);
|
|
||||||
assertDataSourceNotInitialized(dataSource);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertDataSourceNotInitialized(DataSource dataSource) {
|
|
||||||
JdbcOperations template = new JdbcTemplate(dataSource);
|
|
||||||
assertThatExceptionOfType(BadSqlGrammarException.class)
|
|
||||||
.isThrownBy(() -> template.queryForObject("SELECT COUNT(*) from BAR", Integer.class))
|
|
||||||
.satisfies((ex) -> {
|
|
||||||
SQLException sqlException = ex.getSQLException();
|
|
||||||
int expectedCode = -5501; // user lacks privilege or object not found
|
|
||||||
assertThat(sqlException.getErrorCode()).isEqualTo(expectedCode);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void dataSourceInitializedWithSchemaCredentials() {
|
|
||||||
this.contextRunner
|
|
||||||
.withPropertyValues("spring.datasource.initialization-mode:always",
|
|
||||||
"spring.datasource.sqlScriptEncoding:UTF-8",
|
|
||||||
"spring.datasource.schema:" + getRelativeLocationFor("encoding-schema.sql"),
|
|
||||||
"spring.datasource.data:" + getRelativeLocationFor("encoding-data.sql"),
|
|
||||||
"spring.datasource.schema-username:admin", "spring.datasource.schema-password:admin")
|
|
||||||
.run((context) -> {
|
|
||||||
assertThat(context).hasFailed();
|
|
||||||
assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class)
|
|
||||||
.hasMessageContaining("invalid authorization specification");
|
|
||||||
context.getStartupFailure().printStackTrace();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void dataSourceInitializedWithDataCredentials() {
|
|
||||||
this.contextRunner
|
|
||||||
.withPropertyValues("spring.datasource.initialization-mode:always",
|
|
||||||
"spring.datasource.sqlScriptEncoding:UTF-8",
|
|
||||||
"spring.datasource.schema:" + getRelativeLocationFor("encoding-schema.sql"),
|
|
||||||
"spring.datasource.data:" + getRelativeLocationFor("encoding-data.sql"),
|
|
||||||
"spring.datasource.data-username:admin", "spring.datasource.data-password:admin")
|
|
||||||
.run((context) -> {
|
|
||||||
assertThat(context).hasFailed();
|
|
||||||
assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class)
|
|
||||||
.hasMessageContaining("invalid authorization specification");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void multipleScriptsAppliedInLexicalOrder() {
|
|
||||||
new ApplicationContextRunner(() -> {
|
|
||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
|
||||||
context.setResourceLoader(new ReverseOrderResourceLoader(new DefaultResourceLoader()));
|
|
||||||
return context;
|
|
||||||
}).withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class))
|
|
||||||
.withPropertyValues("spring.datasource.initialization-mode=always",
|
|
||||||
"spring.datasource.url:jdbc:hsqldb:mem:testdb-" + new Random().nextInt(),
|
|
||||||
"spring.datasource.schema:classpath*:" + getRelativeLocationFor("lexical-schema-*.sql"),
|
|
||||||
"spring.datasource.data:classpath*:" + getRelativeLocationFor("data.sql"))
|
|
||||||
.run((context) -> {
|
|
||||||
DataSource dataSource = context.getBean(DataSource.class);
|
|
||||||
assertThat(dataSource).isInstanceOf(HikariDataSource.class);
|
|
||||||
assertThat(dataSource).isNotNull();
|
|
||||||
JdbcOperations template = new JdbcTemplate(dataSource);
|
|
||||||
assertThat(template.queryForObject("SELECT COUNT(*) from FOO", Integer.class)).isEqualTo(1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testDataSourceInitializedWithInvalidSchemaResource() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.datasource.initialization-mode:always",
|
|
||||||
"spring.datasource.schema:classpath:does/not/exist.sql").run((context) -> {
|
|
||||||
assertThat(context).hasFailed();
|
|
||||||
assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class);
|
|
||||||
assertThat(context.getStartupFailure())
|
|
||||||
.hasMessageContaining("No schema scripts found at location 'classpath:does/not/exist.sql'");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void dataSourceInitializedWithInvalidDataResource() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.datasource.initialization-mode:always",
|
|
||||||
"spring.datasource.schema:" + getRelativeLocationFor("schema.sql"),
|
|
||||||
"spring.datasource.data:classpath:does/not/exist.sql").run((context) -> {
|
|
||||||
assertThat(context).hasFailed();
|
|
||||||
assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class);
|
|
||||||
assertThat(context.getStartupFailure())
|
|
||||||
.hasMessageContaining("No data scripts found at location 'classpath:does/not/exist.sql'");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void whenDataSourceIsProxiedByABeanPostProcessorThenDataSourceInitializationUsesTheProxy() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.datasource.initialization-mode:always")
|
|
||||||
.withUserConfiguration(DataSourceProxyConfiguration.class).run((context) -> {
|
|
||||||
assertThat(context).hasSingleBean(DataSource.class);
|
|
||||||
DataSource dataSource = context.getBean(DataSource.class);
|
|
||||||
assertThat(dataSource).isInstanceOf(DataSourceProxy.class);
|
|
||||||
assertThat(((DataSourceProxy) dataSource).connectionsRetrieved).hasPositiveValue();
|
|
||||||
assertDataSourceIsInitialized(dataSource);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
// gh-13042
|
|
||||||
void whenDataSourceIsScopedAndJpaIsInvolvedThenInitializationCompletesSuccessfully() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.datasource.initialization-mode:always")
|
|
||||||
.withConfiguration(AutoConfigurations.of(HibernateJpaAutoConfiguration.class))
|
|
||||||
.withUserConfiguration(ScopedDataSourceConfiguration.class).run((context) -> {
|
|
||||||
assertThat(context).hasSingleBean(DataSource.class);
|
|
||||||
DataSource dataSource = context.getBean(DataSource.class);
|
|
||||||
assertThat(dataSource).isInstanceOf(HikariDataSource.class);
|
|
||||||
assertDataSourceIsInitialized(dataSource);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getRelativeLocationFor(String resource) {
|
|
||||||
return ClassUtils.addResourcePathToPackagePath(getClass(), resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
static class OneDataSource {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
DataSource oneDataSource() {
|
|
||||||
return new TestDataSource(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
static class TwoDataSources extends OneDataSource {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
DataSource twoDataSource() {
|
|
||||||
return new TestDataSource(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link ResourcePatternResolver} used to ensure consistently wrong resource
|
|
||||||
* ordering.
|
|
||||||
*/
|
|
||||||
static class ReverseOrderResourceLoader implements ResourcePatternResolver {
|
|
||||||
|
|
||||||
private final ResourcePatternResolver resolver;
|
|
||||||
|
|
||||||
ReverseOrderResourceLoader(ResourceLoader loader) {
|
|
||||||
this.resolver = ResourcePatternUtils.getResourcePatternResolver(loader);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Resource getResource(String location) {
|
|
||||||
return this.resolver.getResource(location);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ClassLoader getClassLoader() {
|
|
||||||
return this.resolver.getClassLoader();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Resource[] getResources(String locationPattern) throws IOException {
|
|
||||||
Resource[] resources = this.resolver.getResources(locationPattern);
|
|
||||||
Arrays.sort(resources, Comparator.comparing(Resource::getFilename).reversed());
|
|
||||||
return resources;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = true)
|
|
||||||
static class DataSourceProxyConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
static BeanPostProcessor dataSourceProxy() {
|
|
||||||
return new BeanPostProcessor() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object postProcessAfterInitialization(Object bean, String beanName) {
|
|
||||||
if (bean instanceof DataSource) {
|
|
||||||
return new DataSourceProxy((DataSource) bean);
|
|
||||||
}
|
|
||||||
return bean;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static class DataSourceProxy implements DataSource {
|
|
||||||
|
|
||||||
private final AtomicInteger connectionsRetrieved = new AtomicInteger();
|
|
||||||
|
|
||||||
private final DataSource delegate;
|
|
||||||
|
|
||||||
DataSourceProxy(DataSource delegate) {
|
|
||||||
this.delegate = delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PrintWriter getLogWriter() throws SQLException {
|
|
||||||
return this.delegate.getLogWriter();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLogWriter(PrintWriter out) throws SQLException {
|
|
||||||
this.delegate.setLogWriter(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
|
||||||
return this.delegate.isWrapperFor(iface);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
|
||||||
return this.delegate.unwrap(iface);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Connection getConnection() throws SQLException {
|
|
||||||
this.connectionsRetrieved.incrementAndGet();
|
|
||||||
return this.delegate.getConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Connection getConnection(String username, String password) throws SQLException {
|
|
||||||
this.connectionsRetrieved.incrementAndGet();
|
|
||||||
return this.delegate.getConnection(username, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLoginTimeout() throws SQLException {
|
|
||||||
return this.delegate.getLoginTimeout();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLoginTimeout(int seconds) throws SQLException {
|
|
||||||
this.delegate.setLoginTimeout(seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
|
||||||
return this.delegate.getParentLogger();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
static class ScopedDataSourceConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
static BeanFactoryPostProcessor fooScope() {
|
|
||||||
return (beanFactory) -> beanFactory.registerScope("test", new SimpleThreadScope());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@Scope("test")
|
|
||||||
HikariDataSource dataSource(DataSourceProperties properties) {
|
|
||||||
return properties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -178,24 +178,4 @@ class DataSourcePropertiesTests {
|
||||||
assertThat(properties.determinePassword()).isNull();
|
assertThat(properties.determinePassword()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void determineCredentialsForSchemaScripts() {
|
|
||||||
DataSourceProperties properties = new DataSourceProperties();
|
|
||||||
properties.setSchemaUsername("foo");
|
|
||||||
properties.setSchemaPassword("bar");
|
|
||||||
assertThat(properties.getSchemaUsername()).isEqualTo("foo");
|
|
||||||
assertThat(properties.getSchemaPassword()).isEqualTo("bar");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void determineCredentialsForDataScripts() {
|
|
||||||
DataSourceProperties properties = new DataSourceProperties();
|
|
||||||
properties.setDataUsername("foo");
|
|
||||||
properties.setDataPassword("bar");
|
|
||||||
assertThat(properties.getDataUsername()).isEqualTo("foo");
|
|
||||||
assertThat(properties.getDataPassword()).isEqualTo("bar");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -145,16 +145,6 @@ class JdbcTemplateAutoConfigurationTests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void testDependencyToDeprecatedDataSourceInitialization() {
|
|
||||||
this.contextRunner.withUserConfiguration(DataSourceInitializationValidator.class)
|
|
||||||
.withPropertyValues("spring.datasource.initialization-mode=always").run((context) -> {
|
|
||||||
assertThat(context).hasNotFailed();
|
|
||||||
assertThat(context.getBean(DataSourceInitializationValidator.class).count).isEqualTo(1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDependencyToScriptBasedDataSourceInitialization() {
|
void testDependencyToScriptBasedDataSourceInitialization() {
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(SqlInitializationAutoConfiguration.class))
|
this.contextRunner.withConfiguration(AutoConfigurations.of(SqlInitializationAutoConfiguration.class))
|
||||||
|
|
|
||||||
|
|
@ -130,26 +130,6 @@ class ArtemisAutoConfigurationTests {
|
||||||
getActiveMQConnectionFactory(getConnectionFactory(context)), "192.168.1.144", 9876));
|
getActiveMQConnectionFactory(getConnectionFactory(context)), "192.168.1.144", 9876));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void nativeConnectionFactoryCustomHost() {
|
|
||||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
|
||||||
.withPropertyValues("spring.artemis.mode:native", "spring.artemis.host:192.168.1.144",
|
|
||||||
"spring.artemis.port:9876")
|
|
||||||
.run((context) -> assertNettyConnectionFactory(
|
|
||||||
getActiveMQConnectionFactory(getConnectionFactory(context)), "192.168.1.144", 9876));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void nativeConnectionFactoryCustomBrokerUrlAndHost() {
|
|
||||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
|
||||||
.withPropertyValues("spring.artemis.mode:native", "spring.artemis.host:192.168.1.144",
|
|
||||||
"spring.artemis.port:9876", "spring.artemis.broker-url=tcp://192.168.1.221:6543")
|
|
||||||
.run((context) -> assertNettyConnectionFactory(
|
|
||||||
getActiveMQConnectionFactory(getConnectionFactory(context)), "192.168.1.221", 6543));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nativeConnectionFactoryCredentials() {
|
void nativeConnectionFactoryCredentials() {
|
||||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -99,17 +99,6 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes
|
||||||
super(HibernateJpaAutoConfiguration.class);
|
super(HibernateJpaAutoConfiguration.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void testDataScriptWithDeprecatedMissingDdl() {
|
|
||||||
contextRunner().withPropertyValues("spring.datasource.data:classpath:/city.sql",
|
|
||||||
// Missing:
|
|
||||||
"spring.datasource.schema:classpath:/ddl.sql").run((context) -> {
|
|
||||||
assertThat(context).hasFailed();
|
|
||||||
assertThat(context.getStartupFailure()).hasMessageContaining("ddl.sql");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDmlScriptWithMissingDdl() {
|
void testDmlScriptWithMissingDdl() {
|
||||||
contextRunner().withPropertyValues("spring.sql.init.data-locations:classpath:/city.sql",
|
contextRunner().withPropertyValues("spring.sql.init.data-locations:classpath:/city.sql",
|
||||||
|
|
@ -120,16 +109,6 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testDataScript() {
|
|
||||||
// This can't succeed because the data SQL is executed immediately after the
|
|
||||||
// schema and Hibernate hasn't initialized yet at that point
|
|
||||||
contextRunner().withPropertyValues("spring.datasource.data:classpath:/city.sql").run((context) -> {
|
|
||||||
assertThat(context).hasFailed();
|
|
||||||
assertThat(context.getStartupFailure()).isInstanceOf(BeanCreationException.class);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDmlScript() {
|
void testDmlScript() {
|
||||||
// This can't succeed because the data SQL is executed immediately after the
|
// This can't succeed because the data SQL is executed immediately after the
|
||||||
|
|
@ -140,16 +119,6 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void testDataScriptRunsEarly() {
|
|
||||||
contextRunner().withUserConfiguration(TestInitializedJpaConfiguration.class)
|
|
||||||
.withClassLoader(new HideDataScriptClassLoader())
|
|
||||||
.withPropertyValues("spring.jpa.show-sql=true", "spring.jpa.hibernate.ddl-auto:create-drop",
|
|
||||||
"spring.datasource.data:classpath:/city.sql", "spring.jpa.defer-datasource-initialization=true")
|
|
||||||
.run((context) -> assertThat(context.getBean(TestInitializedJpaConfiguration.class).called).isTrue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testDmlScriptRunsEarly() {
|
void testDmlScriptRunsEarly() {
|
||||||
contextRunner().withUserConfiguration(TestInitializedJpaConfiguration.class)
|
contextRunner().withUserConfiguration(TestInitializedJpaConfiguration.class)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -63,7 +63,6 @@ import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||||
import org.springframework.scheduling.quartz.LocalDataSourceJobStore;
|
import org.springframework.scheduling.quartz.LocalDataSourceJobStore;
|
||||||
|
|
@ -318,18 +317,6 @@ class QuartzAutoConfigurationTests {
|
||||||
.doesNotHaveBean("quartzDataSourceScriptDatabaseInitializer").hasBean("customInitializer"));
|
.doesNotHaveBean("quartzDataSourceScriptDatabaseInitializer").hasBean("customInitializer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
void whenTheUserDefinesTheirOwnQuartzDataSourceInitializerThenTheAutoConfiguredInitializerBacksOff() {
|
|
||||||
this.contextRunner.withUserConfiguration(CustomQuartzDataSourceInitializerConfiguration.class)
|
|
||||||
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class,
|
|
||||||
DataSourceTransactionManagerAutoConfiguration.class))
|
|
||||||
.withPropertyValues("spring.quartz.job-store-type=jdbc")
|
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(QuartzDataSourceScriptDatabaseInitializer.class)
|
|
||||||
.hasSingleBean(QuartzDataSourceInitializer.class).hasBean("customInitializer"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenTheUserDefinesTheirOwnDatabaseInitializerThenTheAutoConfiguredQuartzInitializerRemains() {
|
void whenTheUserDefinesTheirOwnDatabaseInitializerThenTheAutoConfiguredQuartzInitializerRemains() {
|
||||||
this.contextRunner.withUserConfiguration(CustomDatabaseInitializerConfiguration.class)
|
this.contextRunner.withUserConfiguration(CustomDatabaseInitializerConfiguration.class)
|
||||||
|
|
@ -561,18 +548,6 @@ class QuartzAutoConfigurationTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
static class CustomQuartzDataSourceInitializerConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
QuartzDataSourceInitializer customInitializer(DataSource dataSource, ResourceLoader resourceLoader,
|
|
||||||
QuartzProperties properties) {
|
|
||||||
return new QuartzDataSourceInitializer(dataSource, resourceLoader, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static class ComponentThatUsesScheduler {
|
static class ComponentThatUsesScheduler {
|
||||||
|
|
||||||
ComponentThatUsesScheduler(Scheduler scheduler) {
|
ComponentThatUsesScheduler(Scheduler scheduler) {
|
||||||
|
|
|
||||||
|
|
@ -1,105 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.quartz;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|
||||||
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
|
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
||||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
|
||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.io.DefaultResourceLoader;
|
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verifyNoInteractions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link QuartzDataSourceInitializer}.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class QuartzDataSourceInitializerTests {
|
|
||||||
|
|
||||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
||||||
.withConfiguration(
|
|
||||||
AutoConfigurations.of(DataSourceAutoConfiguration.class, JdbcTemplateAutoConfiguration.class))
|
|
||||||
.withPropertyValues("spring.datasource.url=" + String.format(
|
|
||||||
"jdbc:h2:mem:test-%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE", UUID.randomUUID().toString()));
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getDatabaseNameWithPlatformDoesNotTouchDataSource() {
|
|
||||||
DataSource dataSource = mock(DataSource.class);
|
|
||||||
QuartzProperties properties = new QuartzProperties();
|
|
||||||
properties.getJdbc().setPlatform("test");
|
|
||||||
QuartzDataSourceInitializer initializer = new QuartzDataSourceInitializer(dataSource,
|
|
||||||
new DefaultResourceLoader(), properties);
|
|
||||||
assertThat(initializer.getDatabaseName()).isEqualTo("test");
|
|
||||||
verifyNoInteractions(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void hashIsUsedAsACommentPrefixByDefault() {
|
|
||||||
this.contextRunner.withUserConfiguration(TestConfiguration.class).withPropertyValues(
|
|
||||||
"spring.quartz.jdbc.schema=classpath:org/springframework/boot/autoconfigure/quartz/tables_#_comments.sql")
|
|
||||||
.run(this::assertThatDataSourceHasBeenInitialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void doubleDashIsUsedAsACommentPrefixByDefault() {
|
|
||||||
this.contextRunner.withUserConfiguration(TestConfiguration.class).withPropertyValues(
|
|
||||||
"spring.quartz.jdbc.schema=classpath:org/springframework/boot/autoconfigure/quartz/tables_--_comments.sql")
|
|
||||||
.run(this::assertThatDataSourceHasBeenInitialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void commentPrefixCanBeCustomized() {
|
|
||||||
this.contextRunner.withUserConfiguration(TestConfiguration.class).withPropertyValues(
|
|
||||||
"spring.quartz.jdbc.comment-prefix=**",
|
|
||||||
"spring.quartz.jdbc.schema=classpath:org/springframework/boot/autoconfigure/quartz/tables_custom_comment_prefix.sql")
|
|
||||||
.run(this::assertThatDataSourceHasBeenInitialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertThatDataSourceHasBeenInitialized(AssertableApplicationContext context) {
|
|
||||||
JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);
|
|
||||||
assertThat(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM QRTZ_TEST_TABLE", Integer.class)).isEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
@EnableConfigurationProperties(QuartzProperties.class)
|
|
||||||
static class TestConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
QuartzDataSourceInitializer initializer(DataSource dataSource, ResourceLoader resourceLoader,
|
|
||||||
QuartzProperties properties) {
|
|
||||||
return new QuartzDataSourceInitializer(dataSource, resourceLoader, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -40,7 +40,6 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.jdbc.BadSqlGrammarException;
|
import org.springframework.jdbc.BadSqlGrammarException;
|
||||||
import org.springframework.jdbc.core.JdbcOperations;
|
import org.springframework.jdbc.core.JdbcOperations;
|
||||||
import org.springframework.session.FlushMode;
|
import org.springframework.session.FlushMode;
|
||||||
|
|
@ -256,19 +255,6 @@ class SessionAutoConfigurationJdbcTests extends AbstractSessionAutoConfiguration
|
||||||
.hasBean("customInitializer"));
|
.hasBean("customInitializer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
void whenTheUserDefinesTheirOwnJdbcSessionDataSourceInitializerThenTheAutoConfiguredInitializerBacksOff() {
|
|
||||||
this.contextRunner.withUserConfiguration(CustomJdbcSessionDataSourceInitializerConfiguration.class)
|
|
||||||
.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class,
|
|
||||||
DataSourceTransactionManagerAutoConfiguration.class))
|
|
||||||
.withPropertyValues("spring.session.store-type=jdbc")
|
|
||||||
.run((context) -> assertThat(context)
|
|
||||||
.doesNotHaveBean(JdbcSessionDataSourceScriptDatabaseInitializer.class)
|
|
||||||
.hasSingleBean(JdbcSessionDataSourceInitializer.class).hasBean("customInitializer"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenTheUserDefinesTheirOwnDatabaseInitializerThenTheAutoConfiguredJdbcSessionInitializerRemains() {
|
void whenTheUserDefinesTheirOwnDatabaseInitializerThenTheAutoConfiguredJdbcSessionInitializerRemains() {
|
||||||
this.contextRunner.withUserConfiguration(CustomDatabaseInitializerConfiguration.class)
|
this.contextRunner.withUserConfiguration(CustomDatabaseInitializerConfiguration.class)
|
||||||
|
|
@ -326,16 +312,4 @@ class SessionAutoConfigurationJdbcTests extends AbstractSessionAutoConfiguration
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
static class CustomJdbcSessionDataSourceInitializerConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
JdbcSessionDataSourceInitializer customInitializer(DataSource dataSource, ResourceLoader resourceLoader,
|
|
||||||
JdbcSessionProperties properties) {
|
|
||||||
return new JdbcSessionDataSourceInitializer(dataSource, resourceLoader, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -67,14 +67,6 @@ class SqlInitializationAutoConfigurationTests {
|
||||||
.run((context) -> assertThat(context).hasSingleBean(R2dbcScriptDatabaseInitializer.class));
|
.run((context) -> assertThat(context).hasSingleBean(R2dbcScriptDatabaseInitializer.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void whenConnectionFactoryIsAvailableAndInitializationIsDisabledThenInitializerIsNotAutoConfigured() {
|
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(R2dbcAutoConfiguration.class))
|
|
||||||
.withPropertyValues("spring.sql.init.enabled:false")
|
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(AbstractScriptDatabaseInitializer.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenConnectionFactoryIsAvailableAndModeIsNeverThenInitializerIsNotAutoConfigured() {
|
void whenConnectionFactoryIsAvailableAndModeIsNeverThenInitializerIsNotAutoConfigured() {
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(R2dbcAutoConfiguration.class))
|
this.contextRunner.withConfiguration(AutoConfigurations.of(R2dbcAutoConfiguration.class))
|
||||||
|
|
@ -89,14 +81,6 @@ class SqlInitializationAutoConfigurationTests {
|
||||||
.run((context) -> assertThat(context).hasSingleBean(DataSourceScriptDatabaseInitializer.class));
|
.run((context) -> assertThat(context).hasSingleBean(DataSourceScriptDatabaseInitializer.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void whenDataSourceIsAvailableAndInitializationIsDisabledThenInitializerIsNotAutoConfigured() {
|
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class))
|
|
||||||
.withPropertyValues("spring.sql.init.enabled:false")
|
|
||||||
.run((context) -> assertThat(context).doesNotHaveBean(AbstractScriptDatabaseInitializer.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenDataSourceIsAvailableAndModeIsNeverThenThenInitializerIsNotAutoConfigured() {
|
void whenDataSourceIsAvailableAndModeIsNeverThenThenInitializerIsNotAutoConfigured() {
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class))
|
this.contextRunner.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class))
|
||||||
|
|
@ -170,16 +154,6 @@ class SqlInitializationAutoConfigurationTests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void whenDataSourceAutoConfigurationHasDefinedAnInitializerThenAutoConfigurationBacksOff() {
|
|
||||||
this.contextRunner.withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class))
|
|
||||||
.withPropertyValues("spring.datasource.schema=classpath:schema.sql")
|
|
||||||
.withInitializer(new ConditionEvaluationReportLoggingListener(LogLevel.INFO)).run((context) -> {
|
|
||||||
assertThat(context).hasSingleBean(SqlDataSourceScriptDatabaseInitializer.class);
|
|
||||||
assertThat(context).hasBean("scriptDataSourceInitializer");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
static class SqlDatabaseInitializerConfiguration {
|
static class SqlDatabaseInitializerConfiguration {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -40,7 +40,6 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||||
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
|
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
|
||||||
import org.springframework.boot.autoconfigure.validation.ValidatorAdapter;
|
import org.springframework.boot.autoconfigure.validation.ValidatorAdapter;
|
||||||
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration.WebFluxConfig;
|
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration.WebFluxConfig;
|
||||||
import org.springframework.boot.context.properties.source.MutuallyExclusiveConfigurationPropertiesException;
|
|
||||||
import org.springframework.boot.test.context.runner.ContextConsumer;
|
import org.springframework.boot.test.context.runner.ContextConsumer;
|
||||||
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
|
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
|
||||||
import org.springframework.boot.web.codec.CodecCustomizer;
|
import org.springframework.boot.web.codec.CodecCustomizer;
|
||||||
|
|
@ -580,23 +579,6 @@ class WebFluxAutoConfigurationTests {
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void sameSiteAttributesAreExclusive() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.webflux.session.cookie.same-site:strict",
|
|
||||||
"server.reactive.session.cookie.same-site:strict").run((context) -> {
|
|
||||||
assertThat(context).hasFailed();
|
|
||||||
assertThat(context).getFailure()
|
|
||||||
.hasRootCauseExactlyInstanceOf(MutuallyExclusiveConfigurationPropertiesException.class);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void deprecatedCustomSameSiteConfigurationShouldBeApplied() {
|
|
||||||
this.contextRunner.withPropertyValues("spring.webflux.session.cookie.same-site:strict").run(
|
|
||||||
assertExchangeWithSession((exchange) -> assertThat(exchange.getResponse().getCookies().get("SESSION"))
|
|
||||||
.isNotEmpty().allMatch((cookie) -> cookie.getSameSite().equals("Strict"))));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void customSessionCookieConfigurationShouldBeApplied() {
|
void customSessionCookieConfigurationShouldBeApplied() {
|
||||||
this.contextRunner.withPropertyValues("server.reactive.session.cookie.name:JSESSIONID",
|
this.contextRunner.withPropertyValues("server.reactive.session.cookie.name:JSESSIONID",
|
||||||
|
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.autoconfigure.session;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import org.springframework.core.io.DefaultResourceLoader;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.verifyNoInteractions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link JdbcSessionDataSourceInitializer}.
|
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class JdbcSessionDataSourceInitializerTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getDatabaseNameWithPlatformDoesNotTouchDataSource() {
|
|
||||||
DataSource dataSource = mock(DataSource.class);
|
|
||||||
JdbcSessionProperties properties = new JdbcSessionProperties();
|
|
||||||
properties.setPlatform("test");
|
|
||||||
JdbcSessionDataSourceInitializer initializer = new JdbcSessionDataSourceInitializer(dataSource,
|
|
||||||
new DefaultResourceLoader(), properties);
|
|
||||||
assertThat(initializer.getDatabaseName()).isEqualTo("test");
|
|
||||||
verifyNoInteractions(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -23,9 +23,6 @@ import java.net.URLClassLoader;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind;
|
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind;
|
||||||
import org.springframework.core.SmartClassLoader;
|
import org.springframework.core.SmartClassLoader;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
@ -59,29 +56,10 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
|
||||||
* @param urls the urls managed by the classloader
|
* @param urls the urls managed by the classloader
|
||||||
*/
|
*/
|
||||||
public RestartClassLoader(ClassLoader parent, URL[] urls, ClassLoaderFileRepository updatedFiles) {
|
public RestartClassLoader(ClassLoader parent, URL[] urls, ClassLoaderFileRepository updatedFiles) {
|
||||||
this(parent, urls, updatedFiles, LogFactory.getLog(RestartClassLoader.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link RestartClassLoader} instance.
|
|
||||||
* @param parent the parent classloader
|
|
||||||
* @param updatedFiles any files that have been updated since the JARs referenced in
|
|
||||||
* URLs were created.
|
|
||||||
* @param urls the urls managed by the classloader
|
|
||||||
* @param logger the logger used for messages
|
|
||||||
* @deprecated since 2.4.11 for removal in 2.7.0 in favor of
|
|
||||||
* {@link #RestartClassLoader(ClassLoader, URL[], ClassLoaderFileRepository)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public RestartClassLoader(ClassLoader parent, URL[] urls, ClassLoaderFileRepository updatedFiles, Log logger) {
|
|
||||||
super(urls, parent);
|
super(urls, parent);
|
||||||
Assert.notNull(parent, "Parent must not be null");
|
Assert.notNull(parent, "Parent must not be null");
|
||||||
Assert.notNull(updatedFiles, "UpdatedFiles must not be null");
|
Assert.notNull(updatedFiles, "UpdatedFiles must not be null");
|
||||||
Assert.notNull(logger, "Logger must not be null");
|
|
||||||
this.updatedFiles = updatedFiles;
|
this.updatedFiles = updatedFiles;
|
||||||
if (logger.isDebugEnabled()) {
|
|
||||||
logger.debug("Created RestartClassLoader " + toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -110,19 +110,6 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
|
||||||
|
|
||||||
private final Function<RunnerConfiguration<C>, SELF> instanceFactory;
|
private final Function<RunnerConfiguration<C>, SELF> instanceFactory;
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link AbstractApplicationContextRunner} instance.
|
|
||||||
* @param contextFactory the factory used to create the actual context
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #AbstractApplicationContextRunner(Supplier, Function)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected AbstractApplicationContextRunner(Supplier<C> contextFactory) {
|
|
||||||
Assert.notNull(contextFactory, "ContextFactory must not be null");
|
|
||||||
this.runnerConfiguration = new RunnerConfiguration<>(contextFactory);
|
|
||||||
this.instanceFactory = this::legacyNewInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link AbstractApplicationContextRunner} instance.
|
* Create a new {@link AbstractApplicationContextRunner} instance.
|
||||||
* @param contextFactory the factory used to create the actual context
|
* @param contextFactory the factory used to create the actual context
|
||||||
|
|
@ -151,43 +138,6 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
|
||||||
this.instanceFactory = instanceFactory;
|
this.instanceFactory = instanceFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link AbstractApplicationContextRunner} instance.
|
|
||||||
* @param contextFactory the factory used to create the actual context
|
|
||||||
* @param allowBeanDefinitionOverriding whether bean definition overriding is allowed
|
|
||||||
* @param initializers the initializers
|
|
||||||
* @param environmentProperties the environment properties
|
|
||||||
* @param systemProperties the system properties
|
|
||||||
* @param classLoader the class loader
|
|
||||||
* @param parent the parent
|
|
||||||
* @param beanRegistrations the bean registrations
|
|
||||||
* @param configurations the configuration
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #AbstractApplicationContextRunner(Supplier, Function)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected AbstractApplicationContextRunner(Supplier<C> contextFactory, boolean allowBeanDefinitionOverriding,
|
|
||||||
List<ApplicationContextInitializer<? super C>> initializers, TestPropertyValues environmentProperties,
|
|
||||||
TestPropertyValues systemProperties, ClassLoader classLoader, ApplicationContext parent,
|
|
||||||
List<BeanRegistration<?>> beanRegistrations, List<Configurations> configurations) {
|
|
||||||
Assert.notNull(contextFactory, "ContextFactory must not be null");
|
|
||||||
Assert.notNull(environmentProperties, "EnvironmentProperties must not be null");
|
|
||||||
Assert.notNull(systemProperties, "SystemProperties must not be null");
|
|
||||||
Assert.notNull(configurations, "Configurations must not be null");
|
|
||||||
Assert.notNull(initializers, "Initializers must not be null");
|
|
||||||
RunnerConfiguration<C> configuration = new RunnerConfiguration<>(contextFactory);
|
|
||||||
configuration.allowBeanDefinitionOverriding = allowBeanDefinitionOverriding;
|
|
||||||
configuration.initializers = Collections.unmodifiableList(initializers);
|
|
||||||
configuration.environmentProperties = environmentProperties;
|
|
||||||
configuration.systemProperties = systemProperties;
|
|
||||||
configuration.classLoader = classLoader;
|
|
||||||
configuration.parent = parent;
|
|
||||||
configuration.beanRegistrations = Collections.unmodifiableList(beanRegistrations);
|
|
||||||
configuration.configurations = Collections.unmodifiableList(configurations);
|
|
||||||
this.runnerConfiguration = configuration;
|
|
||||||
this.instanceFactory = this::legacyNewInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify if bean definition overriding, by registering a definition with the same
|
* Specify if bean definition overriding, by registering a definition with the same
|
||||||
* name as an existing definition, should be allowed.
|
* name as an existing definition, should be allowed.
|
||||||
|
|
@ -374,20 +324,6 @@ public abstract class AbstractApplicationContextRunner<SELF extends AbstractAppl
|
||||||
return customizer.apply((SELF) this);
|
return customizer.apply((SELF) this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private SELF legacyNewInstance(RunnerConfiguration<C> configuration) {
|
|
||||||
return newInstance(configuration.contextFactory, configuration.allowBeanDefinitionOverriding,
|
|
||||||
configuration.initializers, configuration.environmentProperties, configuration.systemProperties,
|
|
||||||
configuration.classLoader, configuration.parent, configuration.beanRegistrations,
|
|
||||||
configuration.configurations);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
protected abstract SELF newInstance(Supplier<C> contextFactory, boolean allowBeanDefinitionOverriding,
|
|
||||||
List<ApplicationContextInitializer<? super C>> initializers, TestPropertyValues environmentProperties,
|
|
||||||
TestPropertyValues systemProperties, ClassLoader classLoader, ApplicationContext parent,
|
|
||||||
List<BeanRegistration<?>> beanRegistrations, List<Configurations> configurations);
|
|
||||||
|
|
||||||
private SELF newInstance(RunnerConfiguration<C> runnerConfiguration) {
|
private SELF newInstance(RunnerConfiguration<C> runnerConfiguration) {
|
||||||
return this.instanceFactory.apply(runnerConfiguration);
|
return this.instanceFactory.apply(runnerConfiguration);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,14 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.boot.test.context.runner;
|
package org.springframework.boot.test.context.runner;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.springframework.boot.context.annotation.Configurations;
|
|
||||||
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
|
||||||
import org.springframework.boot.test.util.TestPropertyValues;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.ApplicationContextInitializer;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
|
||||||
|
|
@ -62,27 +57,4 @@ public class ApplicationContextRunner extends
|
||||||
super(runnerConfiguration, ApplicationContextRunner::new);
|
super(runnerConfiguration, ApplicationContextRunner::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private ApplicationContextRunner(Supplier<ConfigurableApplicationContext> contextFactory,
|
|
||||||
boolean allowBeanDefinitionOverriding,
|
|
||||||
List<ApplicationContextInitializer<? super ConfigurableApplicationContext>> initializers,
|
|
||||||
TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoader classLoader,
|
|
||||||
ApplicationContext parent, List<BeanRegistration<?>> beanRegistrations,
|
|
||||||
List<Configurations> configurations) {
|
|
||||||
super(contextFactory, allowBeanDefinitionOverriding, initializers, environmentProperties, systemProperties,
|
|
||||||
classLoader, parent, beanRegistrations, configurations);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
protected ApplicationContextRunner newInstance(Supplier<ConfigurableApplicationContext> contextFactory,
|
|
||||||
boolean allowBeanDefinitionOverriding,
|
|
||||||
List<ApplicationContextInitializer<? super ConfigurableApplicationContext>> initializers,
|
|
||||||
TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoader classLoader,
|
|
||||||
ApplicationContext parent, List<BeanRegistration<?>> beanRegistrations,
|
|
||||||
List<Configurations> configurations) {
|
|
||||||
return new ApplicationContextRunner(contextFactory, allowBeanDefinitionOverriding, initializers,
|
|
||||||
environmentProperties, systemProperties, classLoader, parent, beanRegistrations, configurations);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,16 +16,11 @@
|
||||||
|
|
||||||
package org.springframework.boot.test.context.runner;
|
package org.springframework.boot.test.context.runner;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.springframework.boot.context.annotation.Configurations;
|
|
||||||
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
|
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
|
||||||
import org.springframework.boot.test.util.TestPropertyValues;
|
|
||||||
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext;
|
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext;
|
||||||
import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebApplicationContext;
|
import org.springframework.boot.web.reactive.context.ConfigurableReactiveWebApplicationContext;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.ApplicationContextInitializer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link AbstractApplicationContextRunner ApplicationContext runner} for a
|
* An {@link AbstractApplicationContextRunner ApplicationContext runner} for a
|
||||||
|
|
@ -63,27 +58,4 @@ public final class ReactiveWebApplicationContextRunner extends
|
||||||
super(configuration, ReactiveWebApplicationContextRunner::new);
|
super(configuration, ReactiveWebApplicationContextRunner::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private ReactiveWebApplicationContextRunner(Supplier<ConfigurableReactiveWebApplicationContext> contextFactory,
|
|
||||||
boolean allowBeanDefinitionOverriding,
|
|
||||||
List<ApplicationContextInitializer<? super ConfigurableReactiveWebApplicationContext>> initializers,
|
|
||||||
TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoader classLoader,
|
|
||||||
ApplicationContext parent, List<BeanRegistration<?>> beanRegistrations,
|
|
||||||
List<Configurations> configurations) {
|
|
||||||
super(contextFactory, allowBeanDefinitionOverriding, initializers, environmentProperties, systemProperties,
|
|
||||||
classLoader, parent, beanRegistrations, configurations);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
protected ReactiveWebApplicationContextRunner newInstance(
|
|
||||||
Supplier<ConfigurableReactiveWebApplicationContext> contextFactory, boolean allowBeanDefinitionOverriding,
|
|
||||||
List<ApplicationContextInitializer<? super ConfigurableReactiveWebApplicationContext>> initializers,
|
|
||||||
TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoader classLoader,
|
|
||||||
ApplicationContext parent, List<BeanRegistration<?>> beanRegistrations,
|
|
||||||
List<Configurations> configurations) {
|
|
||||||
return new ReactiveWebApplicationContextRunner(contextFactory, allowBeanDefinitionOverriding, initializers,
|
|
||||||
environmentProperties, systemProperties, classLoader, parent, beanRegistrations, configurations);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,15 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.boot.test.context.runner;
|
package org.springframework.boot.test.context.runner;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.springframework.boot.context.annotation.Configurations;
|
|
||||||
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
|
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
|
||||||
import org.springframework.boot.test.util.TestPropertyValues;
|
|
||||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
|
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
|
||||||
import org.springframework.context.ApplicationContext;
|
|
||||||
import org.springframework.context.ApplicationContextInitializer;
|
|
||||||
import org.springframework.mock.web.MockServletContext;
|
import org.springframework.mock.web.MockServletContext;
|
||||||
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
import org.springframework.web.context.ConfigurableWebApplicationContext;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
@ -66,29 +61,6 @@ public final class WebApplicationContextRunner extends
|
||||||
super(configuration, WebApplicationContextRunner::new);
|
super(configuration, WebApplicationContextRunner::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private WebApplicationContextRunner(Supplier<ConfigurableWebApplicationContext> contextFactory,
|
|
||||||
boolean allowBeanDefinitionOverriding,
|
|
||||||
List<ApplicationContextInitializer<? super ConfigurableWebApplicationContext>> initializers,
|
|
||||||
TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoader classLoader,
|
|
||||||
ApplicationContext parent, List<BeanRegistration<?>> beanRegistrations,
|
|
||||||
List<Configurations> configurations) {
|
|
||||||
super(contextFactory, allowBeanDefinitionOverriding, initializers, environmentProperties, systemProperties,
|
|
||||||
classLoader, parent, beanRegistrations, configurations);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
protected WebApplicationContextRunner newInstance(Supplier<ConfigurableWebApplicationContext> contextFactory,
|
|
||||||
boolean allowBeanDefinitionOverriding,
|
|
||||||
List<ApplicationContextInitializer<? super ConfigurableWebApplicationContext>> initializers,
|
|
||||||
TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoader classLoader,
|
|
||||||
ApplicationContext parent, List<BeanRegistration<?>> beanRegistrations,
|
|
||||||
List<Configurations> configurations) {
|
|
||||||
return new WebApplicationContextRunner(contextFactory, allowBeanDefinitionOverriding, initializers,
|
|
||||||
environmentProperties, systemProperties, classLoader, parent, beanRegistrations, configurations);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decorate the specified {@code contextFactory} to set a {@link MockServletContext}
|
* Decorate the specified {@code contextFactory} to set a {@link MockServletContext}
|
||||||
* on each newly created {@link WebApplicationContext}.
|
* on each newly created {@link WebApplicationContext}.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -96,23 +96,10 @@ public abstract class Packager {
|
||||||
* @param source the source archive file to package
|
* @param source the source archive file to package
|
||||||
*/
|
*/
|
||||||
protected Packager(File source) {
|
protected Packager(File source) {
|
||||||
this(source, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link Packager} instance.
|
|
||||||
* @param source the source archive file to package
|
|
||||||
* @param layoutFactory the layout factory to use or {@code null}
|
|
||||||
* @deprecated since 2.3.10 for removal in 2.5 in favor of {@link #Packager(File)} and
|
|
||||||
* {@link #setLayoutFactory(LayoutFactory)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected Packager(File source, LayoutFactory layoutFactory) {
|
|
||||||
Assert.notNull(source, "Source file must not be null");
|
Assert.notNull(source, "Source file must not be null");
|
||||||
Assert.isTrue(source.exists() && source.isFile(),
|
Assert.isTrue(source.exists() && source.isFile(),
|
||||||
() -> "Source must refer to an existing file, got " + source.getAbsolutePath());
|
() -> "Source must refer to an existing file, got " + source.getAbsolutePath());
|
||||||
this.source = source.getAbsoluteFile();
|
this.source = source.getAbsoluteFile();
|
||||||
this.layoutFactory = layoutFactory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -46,18 +46,6 @@ public class Repackager extends Packager {
|
||||||
super(source);
|
super(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link Repackager} instance.
|
|
||||||
* @param source the source archive file to package
|
|
||||||
* @param layoutFactory the layout factory to use or {@code null}
|
|
||||||
* @deprecated since 2.3.10 for removal in 2.5 in favor of {@link #Repackager(File)}
|
|
||||||
* and {@link #setLayoutFactory(LayoutFactory)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public Repackager(File source, LayoutFactory layoutFactory) {
|
|
||||||
super(source, layoutFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets if source files should be backed up when they would be overwritten.
|
* Sets if source files should be backed up when they would be overwritten.
|
||||||
* @param backupSource if source files should be backed up
|
* @param backupSource if source files should be backed up
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -58,19 +58,6 @@ public abstract class Launcher {
|
||||||
launch(args, launchClass, classLoader);
|
launch(args, launchClass, classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a classloader for the specified archives.
|
|
||||||
* @param archives the archives
|
|
||||||
* @return the classloader
|
|
||||||
* @throws Exception if the classloader cannot be created
|
|
||||||
* @deprecated since 2.3.0 for removal in 2.5.0 in favor of
|
|
||||||
* {@link #createClassLoader(Iterator)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected ClassLoader createClassLoader(List<Archive> archives) throws Exception {
|
|
||||||
return createClassLoader(archives.iterator());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a classloader for the specified archives.
|
* Create a classloader for the specified archives.
|
||||||
* @param archives the archives
|
* @param archives the archives
|
||||||
|
|
@ -132,21 +119,7 @@ public abstract class Launcher {
|
||||||
* @throws Exception if the class path archives cannot be obtained
|
* @throws Exception if the class path archives cannot be obtained
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
*/
|
*/
|
||||||
protected Iterator<Archive> getClassPathArchivesIterator() throws Exception {
|
protected abstract Iterator<Archive> getClassPathArchivesIterator() throws Exception;
|
||||||
return getClassPathArchives().iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the archives that will be used to construct the class path.
|
|
||||||
* @return the class path archives
|
|
||||||
* @throws Exception if the class path archives cannot be obtained
|
|
||||||
* @deprecated since 2.3.0 for removal in 2.5.0 in favor of implementing
|
|
||||||
* {@link #getClassPathArchivesIterator()}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected List<Archive> getClassPathArchives() throws Exception {
|
|
||||||
throw new IllegalStateException("Unexpected call to getClassPathArchives()");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final Archive createArchive() throws Exception {
|
protected final Archive createArchive() throws Exception {
|
||||||
ProtectionDomain protectionDomain = getClass().getProtectionDomain();
|
ProtectionDomain protectionDomain = getClass().getProtectionDomain();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -20,11 +20,6 @@ import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Spliterator;
|
|
||||||
import java.util.Spliterators;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.jar.Manifest;
|
import java.util.jar.Manifest;
|
||||||
|
|
||||||
import org.springframework.boot.loader.Launcher;
|
import org.springframework.boot.loader.Launcher;
|
||||||
|
|
@ -62,67 +57,7 @@ public interface Archive extends Iterable<Archive.Entry>, AutoCloseable {
|
||||||
* @throws IOException on IO error
|
* @throws IOException on IO error
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
*/
|
*/
|
||||||
default Iterator<Archive> getNestedArchives(EntryFilter searchFilter, EntryFilter includeFilter)
|
Iterator<Archive> getNestedArchives(EntryFilter searchFilter, EntryFilter includeFilter) throws IOException;
|
||||||
throws IOException {
|
|
||||||
EntryFilter combinedFilter = (entry) -> (searchFilter == null || searchFilter.matches(entry))
|
|
||||||
&& (includeFilter == null || includeFilter.matches(entry));
|
|
||||||
List<Archive> nestedArchives = getNestedArchives(combinedFilter);
|
|
||||||
return nestedArchives.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns nested {@link Archive}s for entries that match the specified filter.
|
|
||||||
* @param filter the filter used to limit entries
|
|
||||||
* @return nested archives
|
|
||||||
* @throws IOException if nested archives cannot be read
|
|
||||||
* @deprecated since 2.3.0 for removal in 2.5.0 in favor of
|
|
||||||
* {@link #getNestedArchives(EntryFilter, EntryFilter)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default List<Archive> getNestedArchives(EntryFilter filter) throws IOException {
|
|
||||||
throw new IllegalStateException("Unexpected call to getNestedArchives(filter)");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a new iterator for the archive entries.
|
|
||||||
* @deprecated since 2.3.0 for removal in 2.5.0 in favor of using
|
|
||||||
* {@link org.springframework.boot.loader.jar.JarFile} to access entries and
|
|
||||||
* {@link #getNestedArchives(EntryFilter, EntryFilter)} for accessing nested archives.
|
|
||||||
* @see java.lang.Iterable#iterator()
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
Iterator<Entry> iterator();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs the given action for each element of the {@code Iterable} until all
|
|
||||||
* elements have been processed or the action throws an exception.
|
|
||||||
* @deprecated since 2.3.0 for removal in 2.5.0 in favor of using
|
|
||||||
* {@link org.springframework.boot.loader.jar.JarFile} to access entries and
|
|
||||||
* {@link #getNestedArchives(EntryFilter, EntryFilter)} for accessing nested archives.
|
|
||||||
* @see Iterable#forEach
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
default void forEach(Consumer<? super Entry> action) {
|
|
||||||
Objects.requireNonNull(action);
|
|
||||||
for (Entry entry : this) {
|
|
||||||
action.accept(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a {@link Spliterator} over the elements described by this {@code Iterable}.
|
|
||||||
* @deprecated since 2.3.0 for removal in 2.5.0 in favor of using
|
|
||||||
* {@link org.springframework.boot.loader.jar.JarFile} to access entries and
|
|
||||||
* {@link #getNestedArchives(EntryFilter, EntryFilter)} for accessing nested archives.
|
|
||||||
* @see Iterable#spliterator
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@Override
|
|
||||||
default Spliterator<Entry> spliterator() {
|
|
||||||
return Spliterators.spliteratorUnknownSize(iterator(), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return if the archive is exploded (already unpacked).
|
* Return if the archive is exploded (already unpacked).
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -81,20 +81,6 @@ public interface SpringApplicationRunListener {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
default void started(ConfigurableApplicationContext context, Duration timeTaken) {
|
default void started(ConfigurableApplicationContext context, Duration timeTaken) {
|
||||||
started(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The context has been refreshed and the application has started but
|
|
||||||
* {@link CommandLineRunner CommandLineRunners} and {@link ApplicationRunner
|
|
||||||
* ApplicationRunners} have not been called.
|
|
||||||
* @param context the application context.
|
|
||||||
* @since 2.0.0
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #started(ConfigurableApplicationContext, Duration)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default void started(ConfigurableApplicationContext context) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -107,20 +93,6 @@ public interface SpringApplicationRunListener {
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
default void ready(ConfigurableApplicationContext context, Duration timeTaken) {
|
default void ready(ConfigurableApplicationContext context, Duration timeTaken) {
|
||||||
running(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called immediately before the run method finishes, when the application context has
|
|
||||||
* been refreshed and all {@link CommandLineRunner CommandLineRunners} and
|
|
||||||
* {@link ApplicationRunner ApplicationRunners} have been called.
|
|
||||||
* @param context the application context.
|
|
||||||
* @since 2.0.0
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #ready(ConfigurableApplicationContext, Duration)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
default void running(ConfigurableApplicationContext context) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -102,20 +102,6 @@ public class SpringApplicationBuilder {
|
||||||
this.application = createSpringApplication(resourceLoader, sources);
|
this.application = createSpringApplication(resourceLoader, sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new {@link SpringApplication} instance from the given sources. Subclasses
|
|
||||||
* may override in order to provide a custom subclass of {@link SpringApplication}.
|
|
||||||
* @param sources the sources
|
|
||||||
* @return the {@link SpringApplication} instance
|
|
||||||
* @since 1.1.0
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #createSpringApplication(ResourceLoader, Class...)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected SpringApplication createSpringApplication(Class<?>... sources) {
|
|
||||||
return new SpringApplication(sources);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link SpringApplication} instance from the given sources using the
|
* Creates a new {@link SpringApplication} instance from the given sources using the
|
||||||
* given {@link ResourceLoader}. Subclasses may override in order to provide a custom
|
* given {@link ResourceLoader}. Subclasses may override in order to provide a custom
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -88,17 +88,6 @@ public final class ConfigData {
|
||||||
return this.propertySources;
|
return this.propertySources;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a set of {@link Option config data options} for this source.
|
|
||||||
* @return the config data options
|
|
||||||
* @deprecated since 2.4.5 in favor of {@link #getOptions(PropertySource)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public Set<Option> getOptions() {
|
|
||||||
Assert.state(this.propertySourceOptions instanceof AlwaysPropertySourceOptions, "No global options defined");
|
|
||||||
return this.propertySourceOptions.get(null).asSet();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the {@link Options config data options} that apply to the given source.
|
* Return the {@link Options config data options} that apply to the given source.
|
||||||
* @param propertySource the property source to check
|
* @param propertySource the property source to check
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,6 @@ class ConfigDataEnvironment {
|
||||||
ConfigurableEnvironment environment, ResourceLoader resourceLoader, Collection<String> additionalProfiles,
|
ConfigurableEnvironment environment, ResourceLoader resourceLoader, Collection<String> additionalProfiles,
|
||||||
ConfigDataEnvironmentUpdateListener environmentUpdateListener) {
|
ConfigDataEnvironmentUpdateListener environmentUpdateListener) {
|
||||||
Binder binder = Binder.get(environment);
|
Binder binder = Binder.get(environment);
|
||||||
UseLegacyConfigProcessingException.throwIfRequested(binder);
|
|
||||||
this.logFactory = logFactory;
|
this.logFactory = logFactory;
|
||||||
this.logger = logFactory.getLog(getClass());
|
this.logger = logFactory.getLog(getClass());
|
||||||
this.notFoundAction = binder.bind(ON_NOT_FOUND_PROPERTY, ConfigDataNotFoundAction.class)
|
this.notFoundAction = binder.bind(ON_NOT_FOUND_PROPERTY, ConfigDataNotFoundAction.class)
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,6 @@ class ConfigDataEnvironmentContributor implements Iterable<ConfigDataEnvironment
|
||||||
PlaceholdersResolver placeholdersResolver = new ConfigDataEnvironmentContributorPlaceholdersResolver(
|
PlaceholdersResolver placeholdersResolver = new ConfigDataEnvironmentContributorPlaceholdersResolver(
|
||||||
contributors, activationContext, this, true);
|
contributors, activationContext, this, true);
|
||||||
Binder binder = new Binder(sources, placeholdersResolver, null, null, null);
|
Binder binder = new Binder(sources, placeholdersResolver, null, null, null);
|
||||||
UseLegacyConfigProcessingException.throwIfRequested(binder);
|
|
||||||
ConfigDataProperties properties = ConfigDataProperties.get(binder);
|
ConfigDataProperties properties = ConfigDataProperties.get(binder);
|
||||||
if (properties != null && this.configDataOptions.contains(ConfigData.Option.IGNORE_IMPORTS)) {
|
if (properties != null && this.configDataOptions.contains(ConfigData.Option.IGNORE_IMPORTS)) {
|
||||||
properties = properties.withoutImports();
|
properties = properties.withoutImports();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -19,8 +19,6 @@ package org.springframework.boot.context.config;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
@ -35,9 +33,6 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.io.DefaultResourceLoader;
|
import org.springframework.core.io.DefaultResourceLoader;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.core.log.LogMessage;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link EnvironmentPostProcessor} that loads and applies {@link ConfigData} to Spring's
|
* {@link EnvironmentPostProcessor} that loads and applies {@link ConfigData} to Spring's
|
||||||
|
|
@ -96,18 +91,10 @@ public class ConfigDataEnvironmentPostProcessor implements EnvironmentPostProces
|
||||||
|
|
||||||
void postProcessEnvironment(ConfigurableEnvironment environment, ResourceLoader resourceLoader,
|
void postProcessEnvironment(ConfigurableEnvironment environment, ResourceLoader resourceLoader,
|
||||||
Collection<String> additionalProfiles) {
|
Collection<String> additionalProfiles) {
|
||||||
try {
|
|
||||||
this.logger.trace("Post-processing environment to add config data");
|
this.logger.trace("Post-processing environment to add config data");
|
||||||
resourceLoader = (resourceLoader != null) ? resourceLoader : new DefaultResourceLoader();
|
resourceLoader = (resourceLoader != null) ? resourceLoader : new DefaultResourceLoader();
|
||||||
getConfigDataEnvironment(environment, resourceLoader, additionalProfiles).processAndApply();
|
getConfigDataEnvironment(environment, resourceLoader, additionalProfiles).processAndApply();
|
||||||
}
|
}
|
||||||
catch (UseLegacyConfigProcessingException ex) {
|
|
||||||
this.logger.debug(LogMessage.format("Switching to legacy config file processing [%s]",
|
|
||||||
ex.getConfigurationProperty()));
|
|
||||||
configureAdditionalProfiles(environment, additionalProfiles);
|
|
||||||
postProcessUsingLegacyApplicationListener(environment, resourceLoader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigDataEnvironment getConfigDataEnvironment(ConfigurableEnvironment environment, ResourceLoader resourceLoader,
|
ConfigDataEnvironment getConfigDataEnvironment(ConfigurableEnvironment environment, ResourceLoader resourceLoader,
|
||||||
Collection<String> additionalProfiles) {
|
Collection<String> additionalProfiles) {
|
||||||
|
|
@ -115,25 +102,6 @@ public class ConfigDataEnvironmentPostProcessor implements EnvironmentPostProces
|
||||||
additionalProfiles, this.environmentUpdateListener);
|
additionalProfiles, this.environmentUpdateListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureAdditionalProfiles(ConfigurableEnvironment environment,
|
|
||||||
Collection<String> additionalProfiles) {
|
|
||||||
if (!CollectionUtils.isEmpty(additionalProfiles)) {
|
|
||||||
Set<String> profiles = new LinkedHashSet<>(additionalProfiles);
|
|
||||||
profiles.addAll(Arrays.asList(environment.getActiveProfiles()));
|
|
||||||
environment.setActiveProfiles(StringUtils.toStringArray(profiles));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void postProcessUsingLegacyApplicationListener(ConfigurableEnvironment environment,
|
|
||||||
ResourceLoader resourceLoader) {
|
|
||||||
getLegacyListener().addPropertySources(environment, resourceLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
LegacyConfigFileApplicationListener getLegacyListener() {
|
|
||||||
return new LegacyConfigFileApplicationListener(this.logFactory.getLog(ConfigFileApplicationListener.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply {@link ConfigData} post-processing to an existing {@link Environment}. This
|
* Apply {@link ConfigData} post-processing to an existing {@link Environment}. This
|
||||||
* method can be useful when working with an {@link Environment} that has been created
|
* method can be useful when working with an {@link Environment} that has been created
|
||||||
|
|
@ -201,18 +169,4 @@ public class ConfigDataEnvironmentPostProcessor implements EnvironmentPostProces
|
||||||
postProcessor.postProcessEnvironment(environment, resourceLoader, additionalProfiles);
|
postProcessor.postProcessEnvironment(environment, resourceLoader, additionalProfiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
static class LegacyConfigFileApplicationListener extends ConfigFileApplicationListener {
|
|
||||||
|
|
||||||
LegacyConfigFileApplicationListener(Log logger) {
|
|
||||||
super(logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addPropertySources(ConfigurableEnvironment environment, ResourceLoader resourceLoader) {
|
|
||||||
super.addPropertySources(environment, resourceLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,968 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Deque;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
||||||
import org.springframework.boot.DefaultPropertiesPropertySource;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
|
||||||
import org.springframework.boot.context.event.ApplicationPreparedEvent;
|
|
||||||
import org.springframework.boot.context.properties.bind.Bindable;
|
|
||||||
import org.springframework.boot.context.properties.bind.Binder;
|
|
||||||
import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver;
|
|
||||||
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
|
|
||||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
|
||||||
import org.springframework.boot.env.PropertySourceLoader;
|
|
||||||
import org.springframework.boot.env.RandomValuePropertySource;
|
|
||||||
import org.springframework.boot.logging.DeferredLog;
|
|
||||||
import org.springframework.context.ApplicationEvent;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
|
|
||||||
import org.springframework.context.event.SmartApplicationListener;
|
|
||||||
import org.springframework.core.Ordered;
|
|
||||||
import org.springframework.core.env.AbstractEnvironment;
|
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
|
||||||
import org.springframework.core.env.Environment;
|
|
||||||
import org.springframework.core.env.MutablePropertySources;
|
|
||||||
import org.springframework.core.env.Profiles;
|
|
||||||
import org.springframework.core.env.PropertySource;
|
|
||||||
import org.springframework.core.io.DefaultResourceLoader;
|
|
||||||
import org.springframework.core.io.FileSystemResource;
|
|
||||||
import org.springframework.core.io.Resource;
|
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.core.io.support.ResourcePatternResolver;
|
|
||||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
import org.springframework.util.ResourceUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link EnvironmentPostProcessor} that configures the context environment by loading
|
|
||||||
* properties from well known file locations. By default properties will be loaded from
|
|
||||||
* 'application.properties' and/or 'application.yml' files in the following locations:
|
|
||||||
* <ul>
|
|
||||||
* <li>file:./config/</li>
|
|
||||||
* <li>file:./config/{@literal *}/</li>
|
|
||||||
* <li>file:./</li>
|
|
||||||
* <li>classpath:config/</li>
|
|
||||||
* <li>classpath:</li>
|
|
||||||
* </ul>
|
|
||||||
* The list is ordered by precedence (properties defined in locations higher in the list
|
|
||||||
* override those defined in lower locations).
|
|
||||||
* <p>
|
|
||||||
* Alternative search locations and names can be specified using
|
|
||||||
* {@link #setSearchLocations(String)} and {@link #setSearchNames(String)}.
|
|
||||||
* <p>
|
|
||||||
* Additional files will also be loaded based on active profiles. For example if a 'web'
|
|
||||||
* profile is active 'application-web.properties' and 'application-web.yml' will be
|
|
||||||
* considered.
|
|
||||||
* <p>
|
|
||||||
* The 'spring.config.name' property can be used to specify an alternative name to load
|
|
||||||
* and the 'spring.config.location' property can be used to specify alternative search
|
|
||||||
* locations or specific files.
|
|
||||||
* <p>
|
|
||||||
*
|
|
||||||
* @author Dave Syer
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
* @author Eddú Meléndez
|
|
||||||
* @author Madhura Bhave
|
|
||||||
* @author Scott Frederick
|
|
||||||
* @since 1.0.0
|
|
||||||
* @deprecated since 2.4.0 for removal in 3.0.0 in favor of
|
|
||||||
* {@link ConfigDataEnvironmentPostProcessor}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class ConfigFileApplicationListener implements EnvironmentPostProcessor, SmartApplicationListener, Ordered {
|
|
||||||
|
|
||||||
// Note the order is from least to most specific (last one wins)
|
|
||||||
private static final String DEFAULT_SEARCH_LOCATIONS = "classpath:/,classpath:/config/,file:./,file:./config/*/,file:./config/";
|
|
||||||
|
|
||||||
private static final String DEFAULT_NAMES = "application";
|
|
||||||
|
|
||||||
private static final Set<String> NO_SEARCH_NAMES = Collections.singleton(null);
|
|
||||||
|
|
||||||
private static final Bindable<String[]> STRING_ARRAY = Bindable.of(String[].class);
|
|
||||||
|
|
||||||
private static final Bindable<List<String>> STRING_LIST = Bindable.listOf(String.class);
|
|
||||||
|
|
||||||
private static final Set<String> LOAD_FILTERED_PROPERTY;
|
|
||||||
|
|
||||||
static {
|
|
||||||
Set<String> filteredProperties = new HashSet<>();
|
|
||||||
filteredProperties.add("spring.profiles.active");
|
|
||||||
filteredProperties.add("spring.profiles.include");
|
|
||||||
LOAD_FILTERED_PROPERTY = Collections.unmodifiableSet(filteredProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The "active profiles" property name.
|
|
||||||
*/
|
|
||||||
public static final String ACTIVE_PROFILES_PROPERTY = "spring.profiles.active";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The "includes profiles" property name.
|
|
||||||
*/
|
|
||||||
public static final String INCLUDE_PROFILES_PROPERTY = "spring.profiles.include";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The "config name" property name.
|
|
||||||
*/
|
|
||||||
public static final String CONFIG_NAME_PROPERTY = "spring.config.name";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The "config location" property name.
|
|
||||||
*/
|
|
||||||
public static final String CONFIG_LOCATION_PROPERTY = "spring.config.location";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The "config additional location" property name.
|
|
||||||
*/
|
|
||||||
public static final String CONFIG_ADDITIONAL_LOCATION_PROPERTY = "spring.config.additional-location";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default order for the processor.
|
|
||||||
*/
|
|
||||||
public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 10;
|
|
||||||
|
|
||||||
private final Log logger;
|
|
||||||
|
|
||||||
private static final Resource[] EMPTY_RESOURCES = {};
|
|
||||||
|
|
||||||
private static final Comparator<File> FILE_COMPARATOR = Comparator.comparing(File::getAbsolutePath);
|
|
||||||
|
|
||||||
private String searchLocations;
|
|
||||||
|
|
||||||
private String names;
|
|
||||||
|
|
||||||
private int order = DEFAULT_ORDER;
|
|
||||||
|
|
||||||
public ConfigFileApplicationListener() {
|
|
||||||
this(new DeferredLog());
|
|
||||||
}
|
|
||||||
|
|
||||||
ConfigFileApplicationListener(Log logger) {
|
|
||||||
this.logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
|
|
||||||
return ApplicationEnvironmentPreparedEvent.class.isAssignableFrom(eventType)
|
|
||||||
|| ApplicationPreparedEvent.class.isAssignableFrom(eventType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onApplicationEvent(ApplicationEvent event) {
|
|
||||||
throw new IllegalStateException("ConfigFileApplicationListener [" + getClass().getName()
|
|
||||||
+ "] is deprecated and can only be used as an EnvironmentPostProcessor");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
|
||||||
addPropertySources(environment, application.getResourceLoader());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add config file property sources to the specified environment.
|
|
||||||
* @param environment the environment to add source to
|
|
||||||
* @param resourceLoader the resource loader
|
|
||||||
* @see #addPostProcessors(ConfigurableApplicationContext)
|
|
||||||
*/
|
|
||||||
protected void addPropertySources(ConfigurableEnvironment environment, ResourceLoader resourceLoader) {
|
|
||||||
RandomValuePropertySource.addToEnvironment(environment);
|
|
||||||
new Loader(environment, resourceLoader).load();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add appropriate post-processors to post-configure the property-sources.
|
|
||||||
* @param context the context to configure
|
|
||||||
*/
|
|
||||||
protected void addPostProcessors(ConfigurableApplicationContext context) {
|
|
||||||
context.addBeanFactoryPostProcessor(new PropertySourceOrderingPostProcessor(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrder(int order) {
|
|
||||||
this.order = order;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getOrder() {
|
|
||||||
return this.order;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the search locations that will be considered as a comma-separated list. Each
|
|
||||||
* search location should be a directory path (ending in "/") and it will be prefixed
|
|
||||||
* by the file names constructed from {@link #setSearchNames(String) search names} and
|
|
||||||
* profiles (if any) plus file extensions supported by the properties loaders.
|
|
||||||
* Locations are considered in the order specified, with later items taking precedence
|
|
||||||
* (like a map merge).
|
|
||||||
* @param locations the search locations
|
|
||||||
*/
|
|
||||||
public void setSearchLocations(String locations) {
|
|
||||||
Assert.hasLength(locations, "Locations must not be empty");
|
|
||||||
this.searchLocations = locations;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the names of the files that should be loaded (excluding file extension) as a
|
|
||||||
* comma-separated list.
|
|
||||||
* @param names the names to load
|
|
||||||
*/
|
|
||||||
public void setSearchNames(String names) {
|
|
||||||
Assert.hasLength(names, "Names must not be empty");
|
|
||||||
this.names = names;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link BeanFactoryPostProcessor} to re-order our property sources below any
|
|
||||||
* {@code @PropertySource} items added by the {@link ConfigurationClassPostProcessor}.
|
|
||||||
*/
|
|
||||||
private static class PropertySourceOrderingPostProcessor implements BeanFactoryPostProcessor, Ordered {
|
|
||||||
|
|
||||||
private final ConfigurableApplicationContext context;
|
|
||||||
|
|
||||||
PropertySourceOrderingPostProcessor(ConfigurableApplicationContext context) {
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getOrder() {
|
|
||||||
return Ordered.HIGHEST_PRECEDENCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
|
||||||
reorderSources(this.context.getEnvironment());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void reorderSources(ConfigurableEnvironment environment) {
|
|
||||||
DefaultPropertiesPropertySource.moveToEnd(environment);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads candidate property sources and configures the active profiles.
|
|
||||||
*/
|
|
||||||
private class Loader {
|
|
||||||
|
|
||||||
private final Log logger = ConfigFileApplicationListener.this.logger;
|
|
||||||
|
|
||||||
private final ConfigurableEnvironment environment;
|
|
||||||
|
|
||||||
private final PropertySourcesPlaceholdersResolver placeholdersResolver;
|
|
||||||
|
|
||||||
private final ResourceLoader resourceLoader;
|
|
||||||
|
|
||||||
private final List<PropertySourceLoader> propertySourceLoaders;
|
|
||||||
|
|
||||||
private Deque<Profile> profiles;
|
|
||||||
|
|
||||||
private List<Profile> processedProfiles;
|
|
||||||
|
|
||||||
private boolean activatedProfiles;
|
|
||||||
|
|
||||||
private Map<Profile, MutablePropertySources> loaded;
|
|
||||||
|
|
||||||
private Map<DocumentsCacheKey, List<Document>> loadDocumentsCache = new HashMap<>();
|
|
||||||
|
|
||||||
Loader(ConfigurableEnvironment environment, ResourceLoader resourceLoader) {
|
|
||||||
this.environment = environment;
|
|
||||||
this.placeholdersResolver = new PropertySourcesPlaceholdersResolver(this.environment);
|
|
||||||
this.resourceLoader = (resourceLoader != null) ? resourceLoader : new DefaultResourceLoader(null);
|
|
||||||
this.propertySourceLoaders = SpringFactoriesLoader.loadFactories(PropertySourceLoader.class,
|
|
||||||
this.resourceLoader.getClassLoader());
|
|
||||||
}
|
|
||||||
|
|
||||||
void load() {
|
|
||||||
FilteredPropertySource.apply(this.environment, DefaultPropertiesPropertySource.NAME, LOAD_FILTERED_PROPERTY,
|
|
||||||
this::loadWithFilteredProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadWithFilteredProperties(PropertySource<?> defaultProperties) {
|
|
||||||
this.profiles = new LinkedList<>();
|
|
||||||
this.processedProfiles = new LinkedList<>();
|
|
||||||
this.activatedProfiles = false;
|
|
||||||
this.loaded = new LinkedHashMap<>();
|
|
||||||
initializeProfiles();
|
|
||||||
while (!this.profiles.isEmpty()) {
|
|
||||||
Profile profile = this.profiles.poll();
|
|
||||||
if (isDefaultProfile(profile)) {
|
|
||||||
addProfileToEnvironment(profile.getName());
|
|
||||||
}
|
|
||||||
load(profile, this::getPositiveProfileFilter, addToLoaded(MutablePropertySources::addLast, false));
|
|
||||||
this.processedProfiles.add(profile);
|
|
||||||
}
|
|
||||||
load(null, this::getNegativeProfileFilter, addToLoaded(MutablePropertySources::addFirst, true));
|
|
||||||
addLoadedPropertySources();
|
|
||||||
applyActiveProfiles(defaultProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize profile information from both the {@link Environment} active
|
|
||||||
* profiles and any {@code spring.profiles.active}/{@code spring.profiles.include}
|
|
||||||
* properties that are already set.
|
|
||||||
*/
|
|
||||||
private void initializeProfiles() {
|
|
||||||
// The default profile for these purposes is represented as null. We add it
|
|
||||||
// first so that it is processed first and has lowest priority.
|
|
||||||
this.profiles.add(null);
|
|
||||||
Binder binder = Binder.get(this.environment);
|
|
||||||
Set<Profile> activatedViaProperty = getProfiles(binder, ACTIVE_PROFILES_PROPERTY);
|
|
||||||
Set<Profile> includedViaProperty = getProfiles(binder, INCLUDE_PROFILES_PROPERTY);
|
|
||||||
List<Profile> otherActiveProfiles = getOtherActiveProfiles(activatedViaProperty, includedViaProperty);
|
|
||||||
this.profiles.addAll(otherActiveProfiles);
|
|
||||||
// Any pre-existing active profiles set via property sources (e.g.
|
|
||||||
// System properties) take precedence over those added in config files.
|
|
||||||
this.profiles.addAll(includedViaProperty);
|
|
||||||
addActiveProfiles(activatedViaProperty);
|
|
||||||
if (this.profiles.size() == 1) { // only has null profile
|
|
||||||
for (String defaultProfileName : getDefaultProfiles(binder)) {
|
|
||||||
Profile defaultProfile = new Profile(defaultProfileName, true);
|
|
||||||
this.profiles.add(defaultProfile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] getDefaultProfiles(Binder binder) {
|
|
||||||
return binder.bind(AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME, STRING_ARRAY)
|
|
||||||
.orElseGet(this.environment::getDefaultProfiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Profile> getOtherActiveProfiles(Set<Profile> activatedViaProperty,
|
|
||||||
Set<Profile> includedViaProperty) {
|
|
||||||
return Arrays.stream(this.environment.getActiveProfiles()).map(Profile::new).filter(
|
|
||||||
(profile) -> !activatedViaProperty.contains(profile) && !includedViaProperty.contains(profile))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
void addActiveProfiles(Set<Profile> profiles) {
|
|
||||||
if (profiles.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.activatedProfiles) {
|
|
||||||
if (this.logger.isDebugEnabled()) {
|
|
||||||
this.logger.debug("Profiles already activated, '" + profiles + "' will not be applied");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.profiles.addAll(profiles);
|
|
||||||
if (this.logger.isDebugEnabled()) {
|
|
||||||
this.logger.debug("Activated activeProfiles " + StringUtils.collectionToCommaDelimitedString(profiles));
|
|
||||||
}
|
|
||||||
this.activatedProfiles = true;
|
|
||||||
removeUnprocessedDefaultProfiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeUnprocessedDefaultProfiles() {
|
|
||||||
this.profiles.removeIf((profile) -> (profile != null && profile.isDefaultProfile()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private DocumentFilter getPositiveProfileFilter(Profile profile) {
|
|
||||||
return (Document document) -> {
|
|
||||||
if (profile == null) {
|
|
||||||
return ObjectUtils.isEmpty(document.getProfiles());
|
|
||||||
}
|
|
||||||
return ObjectUtils.containsElement(document.getProfiles(), profile.getName())
|
|
||||||
&& this.environment.acceptsProfiles(Profiles.of(document.getProfiles()));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private DocumentFilter getNegativeProfileFilter(Profile profile) {
|
|
||||||
return (Document document) -> (profile == null && !ObjectUtils.isEmpty(document.getProfiles())
|
|
||||||
&& this.environment.acceptsProfiles(Profiles.of(document.getProfiles())));
|
|
||||||
}
|
|
||||||
|
|
||||||
private DocumentConsumer addToLoaded(BiConsumer<MutablePropertySources, PropertySource<?>> addMethod,
|
|
||||||
boolean checkForExisting) {
|
|
||||||
return (profile, document) -> {
|
|
||||||
if (checkForExisting) {
|
|
||||||
for (MutablePropertySources merged : this.loaded.values()) {
|
|
||||||
if (merged.contains(document.getPropertySource().getName())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MutablePropertySources merged = this.loaded.computeIfAbsent(profile,
|
|
||||||
(k) -> new MutablePropertySources());
|
|
||||||
addMethod.accept(merged, document.getPropertySource());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void load(Profile profile, DocumentFilterFactory filterFactory, DocumentConsumer consumer) {
|
|
||||||
getSearchLocations().forEach((location) -> {
|
|
||||||
String nonOptionalLocation = ConfigDataLocation.of(location).getValue();
|
|
||||||
boolean isDirectory = location.endsWith("/");
|
|
||||||
Set<String> names = isDirectory ? getSearchNames() : NO_SEARCH_NAMES;
|
|
||||||
names.forEach((name) -> load(nonOptionalLocation, name, profile, filterFactory, consumer));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void load(String location, String name, Profile profile, DocumentFilterFactory filterFactory,
|
|
||||||
DocumentConsumer consumer) {
|
|
||||||
if (!StringUtils.hasText(name)) {
|
|
||||||
for (PropertySourceLoader loader : this.propertySourceLoaders) {
|
|
||||||
if (canLoadFileExtension(loader, location)) {
|
|
||||||
load(loader, location, profile, filterFactory.getDocumentFilter(profile), consumer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IllegalStateException("File extension of config file location '" + location
|
|
||||||
+ "' is not known to any PropertySourceLoader. If the location is meant to reference "
|
|
||||||
+ "a directory, it must end in '/'");
|
|
||||||
}
|
|
||||||
Set<String> processed = new HashSet<>();
|
|
||||||
for (PropertySourceLoader loader : this.propertySourceLoaders) {
|
|
||||||
for (String fileExtension : loader.getFileExtensions()) {
|
|
||||||
if (processed.add(fileExtension)) {
|
|
||||||
loadForFileExtension(loader, location + name, "." + fileExtension, profile, filterFactory,
|
|
||||||
consumer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean canLoadFileExtension(PropertySourceLoader loader, String name) {
|
|
||||||
return Arrays.stream(loader.getFileExtensions())
|
|
||||||
.anyMatch((fileExtension) -> StringUtils.endsWithIgnoreCase(name, fileExtension));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadForFileExtension(PropertySourceLoader loader, String prefix, String fileExtension,
|
|
||||||
Profile profile, DocumentFilterFactory filterFactory, DocumentConsumer consumer) {
|
|
||||||
DocumentFilter defaultFilter = filterFactory.getDocumentFilter(null);
|
|
||||||
DocumentFilter profileFilter = filterFactory.getDocumentFilter(profile);
|
|
||||||
if (profile != null) {
|
|
||||||
// Try profile-specific file & profile section in profile file (gh-340)
|
|
||||||
String profileSpecificFile = prefix + "-" + profile + fileExtension;
|
|
||||||
load(loader, profileSpecificFile, profile, defaultFilter, consumer);
|
|
||||||
load(loader, profileSpecificFile, profile, profileFilter, consumer);
|
|
||||||
// Try profile specific sections in files we've already processed
|
|
||||||
for (Profile processedProfile : this.processedProfiles) {
|
|
||||||
if (processedProfile != null) {
|
|
||||||
String previouslyLoaded = prefix + "-" + processedProfile + fileExtension;
|
|
||||||
load(loader, previouslyLoaded, profile, profileFilter, consumer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Also try the profile-specific section (if any) of the normal file
|
|
||||||
load(loader, prefix + fileExtension, profile, profileFilter, consumer);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void load(PropertySourceLoader loader, String location, Profile profile, DocumentFilter filter,
|
|
||||||
DocumentConsumer consumer) {
|
|
||||||
Resource[] resources = getResources(location);
|
|
||||||
for (Resource resource : resources) {
|
|
||||||
try {
|
|
||||||
if (resource == null || !resource.exists()) {
|
|
||||||
if (this.logger.isTraceEnabled()) {
|
|
||||||
StringBuilder description = getDescription("Skipped missing config ", location, resource,
|
|
||||||
profile);
|
|
||||||
this.logger.trace(description);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!StringUtils.hasText(StringUtils.getFilenameExtension(resource.getFilename()))) {
|
|
||||||
if (this.logger.isTraceEnabled()) {
|
|
||||||
StringBuilder description = getDescription("Skipped empty config extension ", location,
|
|
||||||
resource, profile);
|
|
||||||
this.logger.trace(description);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (resource.isFile() && isPatternLocation(location) && hasHiddenPathElement(resource)) {
|
|
||||||
if (this.logger.isTraceEnabled()) {
|
|
||||||
StringBuilder description = getDescription("Skipped location with hidden path element ",
|
|
||||||
location, resource, profile);
|
|
||||||
this.logger.trace(description);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String name = "applicationConfig: [" + getLocationName(location, resource) + "]";
|
|
||||||
List<Document> documents = loadDocuments(loader, name, resource);
|
|
||||||
if (CollectionUtils.isEmpty(documents)) {
|
|
||||||
if (this.logger.isTraceEnabled()) {
|
|
||||||
StringBuilder description = getDescription("Skipped unloaded config ", location, resource,
|
|
||||||
profile);
|
|
||||||
this.logger.trace(description);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
List<Document> loaded = new ArrayList<>();
|
|
||||||
for (Document document : documents) {
|
|
||||||
if (filter.match(document)) {
|
|
||||||
addActiveProfiles(document.getActiveProfiles());
|
|
||||||
addIncludedProfiles(document.getIncludeProfiles());
|
|
||||||
loaded.add(document);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.reverse(loaded);
|
|
||||||
if (!loaded.isEmpty()) {
|
|
||||||
loaded.forEach((document) -> consumer.accept(profile, document));
|
|
||||||
if (this.logger.isDebugEnabled()) {
|
|
||||||
StringBuilder description = getDescription("Loaded config file ", location, resource,
|
|
||||||
profile);
|
|
||||||
this.logger.debug(description);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
StringBuilder description = getDescription("Failed to load property source from ", location,
|
|
||||||
resource, profile);
|
|
||||||
throw new IllegalStateException(description.toString(), ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasHiddenPathElement(Resource resource) throws IOException {
|
|
||||||
String cleanPath = StringUtils.cleanPath(resource.getFile().getAbsolutePath());
|
|
||||||
for (Path value : Paths.get(cleanPath)) {
|
|
||||||
if (value.toString().startsWith("..")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getLocationName(String locationReference, Resource resource) {
|
|
||||||
if (!locationReference.contains("*")) {
|
|
||||||
return locationReference;
|
|
||||||
}
|
|
||||||
if (resource instanceof FileSystemResource) {
|
|
||||||
return ((FileSystemResource) resource).getPath();
|
|
||||||
}
|
|
||||||
return resource.getDescription();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Resource[] getResources(String locationReference) {
|
|
||||||
try {
|
|
||||||
if (isPatternLocation(locationReference)) {
|
|
||||||
return getResourcesFromPatternLocationReference(locationReference);
|
|
||||||
}
|
|
||||||
return new Resource[] { this.resourceLoader.getResource(locationReference) };
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
return EMPTY_RESOURCES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isPatternLocation(String location) {
|
|
||||||
return location.contains("*");
|
|
||||||
}
|
|
||||||
|
|
||||||
private Resource[] getResourcesFromPatternLocationReference(String locationReference) throws IOException {
|
|
||||||
String directoryPath = locationReference.substring(0, locationReference.indexOf("*/"));
|
|
||||||
Resource resource = this.resourceLoader.getResource(directoryPath);
|
|
||||||
File[] files = resource.getFile().listFiles(File::isDirectory);
|
|
||||||
if (files != null) {
|
|
||||||
String fileName = locationReference.substring(locationReference.lastIndexOf("/") + 1);
|
|
||||||
Arrays.sort(files, FILE_COMPARATOR);
|
|
||||||
return Arrays.stream(files).map((file) -> file.listFiles((dir, name) -> name.equals(fileName)))
|
|
||||||
.filter(Objects::nonNull).flatMap((Function<File[], Stream<File>>) Arrays::stream)
|
|
||||||
.map(FileSystemResource::new).toArray(Resource[]::new);
|
|
||||||
}
|
|
||||||
return EMPTY_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addIncludedProfiles(Set<Profile> includeProfiles) {
|
|
||||||
LinkedList<Profile> existingProfiles = new LinkedList<>(this.profiles);
|
|
||||||
this.profiles.clear();
|
|
||||||
this.profiles.addAll(includeProfiles);
|
|
||||||
this.profiles.removeAll(this.processedProfiles);
|
|
||||||
this.profiles.addAll(existingProfiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Document> loadDocuments(PropertySourceLoader loader, String name, Resource resource)
|
|
||||||
throws IOException {
|
|
||||||
DocumentsCacheKey cacheKey = new DocumentsCacheKey(loader, resource);
|
|
||||||
List<Document> documents = this.loadDocumentsCache.get(cacheKey);
|
|
||||||
if (documents == null) {
|
|
||||||
List<PropertySource<?>> loaded = loader.load(name, resource);
|
|
||||||
documents = asDocuments(loaded);
|
|
||||||
this.loadDocumentsCache.put(cacheKey, documents);
|
|
||||||
}
|
|
||||||
return documents;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Document> asDocuments(List<PropertySource<?>> loaded) {
|
|
||||||
if (loaded == null) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
return loaded.stream().map((propertySource) -> {
|
|
||||||
Binder binder = new Binder(ConfigurationPropertySources.from(propertySource),
|
|
||||||
this.placeholdersResolver);
|
|
||||||
String[] profiles = binder.bind("spring.profiles", STRING_ARRAY).orElse(null);
|
|
||||||
Set<Profile> activeProfiles = getProfiles(binder, ACTIVE_PROFILES_PROPERTY);
|
|
||||||
Set<Profile> includeProfiles = getProfiles(binder, INCLUDE_PROFILES_PROPERTY);
|
|
||||||
return new Document(propertySource, profiles, activeProfiles, includeProfiles);
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private StringBuilder getDescription(String prefix, String locationReference, Resource resource,
|
|
||||||
Profile profile) {
|
|
||||||
StringBuilder result = new StringBuilder(prefix);
|
|
||||||
try {
|
|
||||||
if (resource != null) {
|
|
||||||
String uri = resource.getURI().toASCIIString();
|
|
||||||
result.append("'");
|
|
||||||
result.append(uri);
|
|
||||||
result.append("' (");
|
|
||||||
result.append(locationReference);
|
|
||||||
result.append(")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException ex) {
|
|
||||||
result.append(locationReference);
|
|
||||||
}
|
|
||||||
if (profile != null) {
|
|
||||||
result.append(" for profile ");
|
|
||||||
result.append(profile);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<Profile> getProfiles(Binder binder, String name) {
|
|
||||||
return binder.bind(name, STRING_ARRAY).map(this::asProfileSet).orElse(Collections.emptySet());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<Profile> asProfileSet(String[] profileNames) {
|
|
||||||
List<Profile> profiles = new ArrayList<>();
|
|
||||||
for (String profileName : profileNames) {
|
|
||||||
profiles.add(new Profile(profileName));
|
|
||||||
}
|
|
||||||
return new LinkedHashSet<>(profiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addProfileToEnvironment(String profile) {
|
|
||||||
for (String activeProfile : this.environment.getActiveProfiles()) {
|
|
||||||
if (activeProfile.equals(profile)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.environment.addActiveProfile(profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<String> getSearchLocations() {
|
|
||||||
Set<String> locations = getSearchLocations(CONFIG_ADDITIONAL_LOCATION_PROPERTY);
|
|
||||||
if (this.environment.containsProperty(CONFIG_LOCATION_PROPERTY)) {
|
|
||||||
locations.addAll(getSearchLocations(CONFIG_LOCATION_PROPERTY));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
locations.addAll(
|
|
||||||
asResolvedSet(ConfigFileApplicationListener.this.searchLocations, DEFAULT_SEARCH_LOCATIONS));
|
|
||||||
}
|
|
||||||
return locations;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<String> getSearchLocations(String propertyName) {
|
|
||||||
Set<String> locations = new LinkedHashSet<>();
|
|
||||||
if (this.environment.containsProperty(propertyName)) {
|
|
||||||
for (String path : asResolvedSet(this.environment.getProperty(propertyName), null)) {
|
|
||||||
if (!path.contains("$")) {
|
|
||||||
path = StringUtils.cleanPath(path);
|
|
||||||
Assert.state(!path.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX),
|
|
||||||
"Classpath wildcard patterns cannot be used as a search location");
|
|
||||||
validateWildcardLocation(path);
|
|
||||||
if (!ResourceUtils.isUrl(path)) {
|
|
||||||
path = ResourceUtils.FILE_URL_PREFIX + path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
locations.add(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return locations;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateWildcardLocation(String path) {
|
|
||||||
if (path.contains("*")) {
|
|
||||||
Assert.state(StringUtils.countOccurrencesOf(path, "*") == 1,
|
|
||||||
() -> "Search location '" + path + "' cannot contain multiple wildcards");
|
|
||||||
String directoryPath = path.substring(0, path.lastIndexOf("/") + 1);
|
|
||||||
Assert.state(directoryPath.endsWith("*/"), () -> "Search location '" + path + "' must end with '*/'");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<String> getSearchNames() {
|
|
||||||
if (this.environment.containsProperty(CONFIG_NAME_PROPERTY)) {
|
|
||||||
String property = this.environment.getProperty(CONFIG_NAME_PROPERTY);
|
|
||||||
Set<String> names = asResolvedSet(property, null);
|
|
||||||
names.forEach(this::assertValidConfigName);
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
return asResolvedSet(ConfigFileApplicationListener.this.names, DEFAULT_NAMES);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<String> asResolvedSet(String value, String fallback) {
|
|
||||||
List<String> list = Arrays.asList(StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(
|
|
||||||
(value != null) ? this.environment.resolvePlaceholders(value) : fallback)));
|
|
||||||
Collections.reverse(list);
|
|
||||||
return new LinkedHashSet<>(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertValidConfigName(String name) {
|
|
||||||
Assert.state(!name.contains("*"), () -> "Config name '" + name + "' cannot contain wildcards");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addLoadedPropertySources() {
|
|
||||||
MutablePropertySources destination = this.environment.getPropertySources();
|
|
||||||
List<MutablePropertySources> loaded = new ArrayList<>(this.loaded.values());
|
|
||||||
Collections.reverse(loaded);
|
|
||||||
String lastAdded = null;
|
|
||||||
Set<String> added = new HashSet<>();
|
|
||||||
for (MutablePropertySources sources : loaded) {
|
|
||||||
for (PropertySource<?> source : sources) {
|
|
||||||
if (added.add(source.getName())) {
|
|
||||||
addLoadedPropertySource(destination, lastAdded, source);
|
|
||||||
lastAdded = source.getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addLoadedPropertySource(MutablePropertySources destination, String lastAdded,
|
|
||||||
PropertySource<?> source) {
|
|
||||||
if (lastAdded == null) {
|
|
||||||
if (destination.contains(DefaultPropertiesPropertySource.NAME)) {
|
|
||||||
destination.addBefore(DefaultPropertiesPropertySource.NAME, source);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
destination.addLast(source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
destination.addAfter(lastAdded, source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void applyActiveProfiles(PropertySource<?> defaultProperties) {
|
|
||||||
List<String> activeProfiles = new ArrayList<>();
|
|
||||||
if (defaultProperties != null) {
|
|
||||||
Binder binder = new Binder(ConfigurationPropertySources.from(defaultProperties),
|
|
||||||
new PropertySourcesPlaceholdersResolver(this.environment));
|
|
||||||
activeProfiles.addAll(bindStringList(binder, "spring.profiles.include"));
|
|
||||||
if (!this.activatedProfiles) {
|
|
||||||
activeProfiles.addAll(bindStringList(binder, "spring.profiles.active"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.processedProfiles.stream().filter(this::isDefaultProfile).map(Profile::getName)
|
|
||||||
.forEach(activeProfiles::add);
|
|
||||||
this.environment.setActiveProfiles(activeProfiles.toArray(new String[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isDefaultProfile(Profile profile) {
|
|
||||||
return profile != null && !profile.isDefaultProfile();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> bindStringList(Binder binder, String property) {
|
|
||||||
return binder.bind(property, STRING_LIST).orElse(Collections.emptyList());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Spring Profile that can be loaded.
|
|
||||||
*/
|
|
||||||
private static class Profile {
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
private final boolean defaultProfile;
|
|
||||||
|
|
||||||
Profile(String name) {
|
|
||||||
this(name, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
Profile(String name, boolean defaultProfile) {
|
|
||||||
Assert.notNull(name, "Name must not be null");
|
|
||||||
this.name = name;
|
|
||||||
this.defaultProfile = defaultProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getName() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isDefaultProfile() {
|
|
||||||
return this.defaultProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (obj == this) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null || obj.getClass() != getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return ((Profile) obj).name.equals(this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return this.name.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache key used to save loading the same document multiple times.
|
|
||||||
*/
|
|
||||||
private static class DocumentsCacheKey {
|
|
||||||
|
|
||||||
private final PropertySourceLoader loader;
|
|
||||||
|
|
||||||
private final Resource resource;
|
|
||||||
|
|
||||||
DocumentsCacheKey(PropertySourceLoader loader, Resource resource) {
|
|
||||||
this.loader = loader;
|
|
||||||
this.resource = resource;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null || getClass() != obj.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
DocumentsCacheKey other = (DocumentsCacheKey) obj;
|
|
||||||
return this.loader.equals(other.loader) && this.resource.equals(other.resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return this.loader.hashCode() * 31 + this.resource.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A single document loaded by a {@link PropertySourceLoader}.
|
|
||||||
*/
|
|
||||||
private static class Document {
|
|
||||||
|
|
||||||
private final PropertySource<?> propertySource;
|
|
||||||
|
|
||||||
private String[] profiles;
|
|
||||||
|
|
||||||
private final Set<Profile> activeProfiles;
|
|
||||||
|
|
||||||
private final Set<Profile> includeProfiles;
|
|
||||||
|
|
||||||
Document(PropertySource<?> propertySource, String[] profiles, Set<Profile> activeProfiles,
|
|
||||||
Set<Profile> includeProfiles) {
|
|
||||||
this.propertySource = propertySource;
|
|
||||||
this.profiles = profiles;
|
|
||||||
this.activeProfiles = activeProfiles;
|
|
||||||
this.includeProfiles = includeProfiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
PropertySource<?> getPropertySource() {
|
|
||||||
return this.propertySource;
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] getProfiles() {
|
|
||||||
return this.profiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Profile> getActiveProfiles() {
|
|
||||||
return this.activeProfiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Profile> getIncludeProfiles() {
|
|
||||||
return this.includeProfiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return this.propertySource.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory used to create a {@link DocumentFilter}.
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
private interface DocumentFilterFactory {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a filter for the given profile.
|
|
||||||
* @param profile the profile or {@code null}
|
|
||||||
* @return the filter
|
|
||||||
*/
|
|
||||||
DocumentFilter getDocumentFilter(Profile profile);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Filter used to restrict when a {@link Document} is loaded.
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
private interface DocumentFilter {
|
|
||||||
|
|
||||||
boolean match(Document document);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Consumer used to handle a loaded {@link Document}.
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
private interface DocumentConsumer {
|
|
||||||
|
|
||||||
void accept(Profile profile, Document document);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2020 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.springframework.boot.context.properties.bind.BindContext;
|
|
||||||
import org.springframework.boot.context.properties.bind.BindException;
|
|
||||||
import org.springframework.boot.context.properties.bind.BindHandler;
|
|
||||||
import org.springframework.boot.context.properties.bind.Bindable;
|
|
||||||
import org.springframework.boot.context.properties.bind.Binder;
|
|
||||||
import org.springframework.boot.context.properties.source.ConfigurationProperty;
|
|
||||||
import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Exception thrown if legacy processing must be used.
|
|
||||||
*
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @author Madhura Bhave
|
|
||||||
*/
|
|
||||||
final class UseLegacyConfigProcessingException extends ConfigDataException {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The property name used to trigger legacy processing.
|
|
||||||
*/
|
|
||||||
static final ConfigurationPropertyName PROPERTY_NAME = ConfigurationPropertyName
|
|
||||||
.of("spring.config.use-legacy-processing");
|
|
||||||
|
|
||||||
private static final Bindable<Boolean> BOOLEAN = Bindable.of(Boolean.class);
|
|
||||||
|
|
||||||
private static final UseLegacyProcessingBindHandler BIND_HANDLER = new UseLegacyProcessingBindHandler();
|
|
||||||
|
|
||||||
private final ConfigurationProperty configurationProperty;
|
|
||||||
|
|
||||||
UseLegacyConfigProcessingException(ConfigurationProperty configurationProperty) {
|
|
||||||
super("Legacy processing requested from " + configurationProperty, null);
|
|
||||||
this.configurationProperty = configurationProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the source configuration property that requested the use of legacy
|
|
||||||
* processing.
|
|
||||||
* @return the configurationProperty the configuration property
|
|
||||||
*/
|
|
||||||
ConfigurationProperty getConfigurationProperty() {
|
|
||||||
return this.configurationProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Throw a new {@link UseLegacyConfigProcessingException} instance if
|
|
||||||
* {@link #PROPERTY_NAME} binds to {@code true}.
|
|
||||||
* @param binder the binder to use
|
|
||||||
*/
|
|
||||||
static void throwIfRequested(Binder binder) {
|
|
||||||
try {
|
|
||||||
binder.bind(PROPERTY_NAME, BOOLEAN, BIND_HANDLER);
|
|
||||||
}
|
|
||||||
catch (BindException ex) {
|
|
||||||
if (ex.getCause() instanceof UseLegacyConfigProcessingException) {
|
|
||||||
throw (UseLegacyConfigProcessingException) ex.getCause();
|
|
||||||
}
|
|
||||||
throw ex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link BindHandler} used to check for legacy processing properties.
|
|
||||||
*/
|
|
||||||
private static class UseLegacyProcessingBindHandler implements BindHandler {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context,
|
|
||||||
Object result) {
|
|
||||||
if (Boolean.TRUE.equals(result)) {
|
|
||||||
throw new UseLegacyConfigProcessingException(context.getConfigurationProperty());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -39,19 +39,6 @@ public class ApplicationReadyEvent extends SpringApplicationEvent {
|
||||||
|
|
||||||
private final Duration timeTaken;
|
private final Duration timeTaken;
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link ApplicationReadyEvent} instance.
|
|
||||||
* @param application the current application
|
|
||||||
* @param args the arguments the application is running with
|
|
||||||
* @param context the context that was being created
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #ApplicationReadyEvent(SpringApplication, String[], ConfigurableApplicationContext, Duration)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public ApplicationReadyEvent(SpringApplication application, String[] args, ConfigurableApplicationContext context) {
|
|
||||||
this(application, args, context, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link ApplicationReadyEvent} instance.
|
* Create a new {@link ApplicationReadyEvent} instance.
|
||||||
* @param application the current application
|
* @param application the current application
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -38,20 +38,6 @@ public class ApplicationStartedEvent extends SpringApplicationEvent {
|
||||||
|
|
||||||
private final Duration timeTaken;
|
private final Duration timeTaken;
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link ApplicationStartedEvent} instance.
|
|
||||||
* @param application the current application
|
|
||||||
* @param args the arguments the application is running with
|
|
||||||
* @param context the context that was being created
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #ApplicationStartedEvent(SpringApplication, String[], ConfigurableApplicationContext, Duration)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public ApplicationStartedEvent(SpringApplication application, String[] args,
|
|
||||||
ConfigurableApplicationContext context) {
|
|
||||||
this(application, args, context, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new {@link ApplicationStartedEvent} instance.
|
* Create a new {@link ApplicationStartedEvent} instance.
|
||||||
* @param application the current application
|
* @param application the current application
|
||||||
|
|
|
||||||
|
|
@ -1,112 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.jdbc;
|
|
||||||
|
|
||||||
import java.sql.DatabaseMetaData;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
|
||||||
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
|
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
|
|
||||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
|
||||||
import org.springframework.jdbc.support.JdbcUtils;
|
|
||||||
import org.springframework.jdbc.support.MetaDataAccessException;
|
|
||||||
import org.springframework.util.Assert;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class used for {@link DataSource} initialization.
|
|
||||||
*
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @since 1.5.0
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link DataSourceScriptDatabaseInitializer}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public abstract class AbstractDataSourceInitializer implements InitializingBean {
|
|
||||||
|
|
||||||
private static final String PLATFORM_PLACEHOLDER = "@@platform@@";
|
|
||||||
|
|
||||||
private final DataSource dataSource;
|
|
||||||
|
|
||||||
private final ResourceLoader resourceLoader;
|
|
||||||
|
|
||||||
protected AbstractDataSourceInitializer(DataSource dataSource, ResourceLoader resourceLoader) {
|
|
||||||
Assert.notNull(dataSource, "DataSource must not be null");
|
|
||||||
Assert.notNull(resourceLoader, "ResourceLoader must not be null");
|
|
||||||
this.dataSource = dataSource;
|
|
||||||
this.resourceLoader = resourceLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterPropertiesSet() {
|
|
||||||
initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initialize() {
|
|
||||||
if (!isEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
|
|
||||||
String schemaLocation = getSchemaLocation();
|
|
||||||
if (schemaLocation.contains(PLATFORM_PLACEHOLDER)) {
|
|
||||||
String platform = getDatabaseName();
|
|
||||||
schemaLocation = schemaLocation.replace(PLATFORM_PLACEHOLDER, platform);
|
|
||||||
}
|
|
||||||
populator.addScript(this.resourceLoader.getResource(schemaLocation));
|
|
||||||
populator.setContinueOnError(true);
|
|
||||||
customize(populator);
|
|
||||||
DatabasePopulatorUtils.execute(populator, this.dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isEnabled() {
|
|
||||||
if (getMode() == DataSourceInitializationMode.NEVER) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return getMode() != DataSourceInitializationMode.EMBEDDED
|
|
||||||
|| EmbeddedDatabaseConnection.isEmbedded(this.dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Customize the {@link ResourceDatabasePopulator}.
|
|
||||||
* @param populator the configured database populator
|
|
||||||
*/
|
|
||||||
protected void customize(ResourceDatabasePopulator populator) {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract DataSourceInitializationMode getMode();
|
|
||||||
|
|
||||||
protected abstract String getSchemaLocation();
|
|
||||||
|
|
||||||
protected String getDatabaseName() {
|
|
||||||
try {
|
|
||||||
String productName = JdbcUtils.commonDatabaseName(
|
|
||||||
JdbcUtils.extractDatabaseMetaData(this.dataSource, DatabaseMetaData::getDatabaseProductName));
|
|
||||||
DatabaseDriver databaseDriver = DatabaseDriver.fromProductName(productName);
|
|
||||||
if (databaseDriver == DatabaseDriver.UNKNOWN) {
|
|
||||||
throw new IllegalStateException("Unable to detect database type");
|
|
||||||
}
|
|
||||||
return databaseDriver.getId();
|
|
||||||
}
|
|
||||||
catch (MetaDataAccessException ex) {
|
|
||||||
throw new IllegalStateException("Unable to detect database type", ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.jdbc;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.springframework.boot.sql.init.dependency.AbstractBeansOfTypeDatabaseInitializerDetector;
|
|
||||||
import org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector;
|
|
||||||
import org.springframework.core.Ordered;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link DatabaseInitializerDetector} for {@link AbstractDataSourceInitializer}.
|
|
||||||
*
|
|
||||||
* @author Henning Pöttker
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class AbstractDataSourceInitializerDatabaseInitializerDetector extends AbstractBeansOfTypeDatabaseInitializerDetector {
|
|
||||||
|
|
||||||
private static final int PRECEDENCE = Ordered.LOWEST_PRECEDENCE - 100;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Set<Class<?>> getDatabaseInitializerBeanTypes() {
|
|
||||||
return Collections.singleton(AbstractDataSourceInitializer.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getOrder() {
|
|
||||||
return PRECEDENCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.jdbc;
|
|
||||||
|
|
||||||
import org.springframework.boot.sql.init.DatabaseInitializationMode;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Supported {@link javax.sql.DataSource} initialization modes.
|
|
||||||
*
|
|
||||||
* @author Vedran Pavic
|
|
||||||
* @author Stephane Nicoll
|
|
||||||
* @since 2.0.0
|
|
||||||
* @see AbstractDataSourceInitializer
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link DatabaseInitializationMode}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public enum DataSourceInitializationMode {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Always initialize the datasource.
|
|
||||||
*/
|
|
||||||
ALWAYS,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Only initialize an embedded datasource.
|
|
||||||
*/
|
|
||||||
EMBEDDED,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Do not initialize the datasource.
|
|
||||||
*/
|
|
||||||
NEVER
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -193,18 +193,6 @@ public class Log4J2LoggingSystem extends Slf4JLoggingSystem {
|
||||||
loadConfiguration(location, logFile, getOverrides(initializationContext));
|
loadConfiguration(location, logFile, getOverrides(initializationContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the configuration from the given {@code location}.
|
|
||||||
* @param location the location
|
|
||||||
* @param logFile log file configuration
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link #loadConfiguration(String, LogFile, List)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
protected void loadConfiguration(String location, LogFile logFile) {
|
|
||||||
this.loadConfiguration(location, logFile, Collections.emptyList());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the configuration from the given {@code location}, creating a composite using
|
* Load the configuration from the given {@code location}, creating a composite using
|
||||||
* the configuration from the given {@code overrides}.
|
* the configuration from the given {@code overrides}.
|
||||||
|
|
|
||||||
|
|
@ -1,106 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.orm.jpa.hibernate;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy;
|
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
|
||||||
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
|
|
||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hibernate {@link PhysicalNamingStrategy} that follows Spring recommended naming
|
|
||||||
* conventions.
|
|
||||||
*
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @author Madhura Bhave
|
|
||||||
* @since 1.4.0
|
|
||||||
* @deprecated since 2.6.0 for removal in 2.8.0 in favor of
|
|
||||||
* {@link CamelCaseToUnderscoresNamingStrategy}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SpringPhysicalNamingStrategy implements PhysicalNamingStrategy {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Identifier toPhysicalCatalogName(Identifier name, JdbcEnvironment jdbcEnvironment) {
|
|
||||||
return apply(name, jdbcEnvironment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Identifier toPhysicalSchemaName(Identifier name, JdbcEnvironment jdbcEnvironment) {
|
|
||||||
return apply(name, jdbcEnvironment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment jdbcEnvironment) {
|
|
||||||
return apply(name, jdbcEnvironment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Identifier toPhysicalSequenceName(Identifier name, JdbcEnvironment jdbcEnvironment) {
|
|
||||||
return apply(name, jdbcEnvironment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment jdbcEnvironment) {
|
|
||||||
return apply(name, jdbcEnvironment);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Identifier apply(Identifier name, JdbcEnvironment jdbcEnvironment) {
|
|
||||||
if (name == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
StringBuilder builder = new StringBuilder(name.getText().replace('.', '_'));
|
|
||||||
for (int i = 1; i < builder.length() - 1; i++) {
|
|
||||||
if (isUnderscoreRequired(builder.charAt(i - 1), builder.charAt(i), builder.charAt(i + 1))) {
|
|
||||||
builder.insert(i++, '_');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getIdentifier(builder.toString(), name.isQuoted(), jdbcEnvironment);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an identifier for the specified details. By default this method will return an
|
|
||||||
* identifier with the name adapted based on the result of
|
|
||||||
* {@link #isCaseInsensitive(JdbcEnvironment)}
|
|
||||||
* @param name the name of the identifier
|
|
||||||
* @param quoted if the identifier is quoted
|
|
||||||
* @param jdbcEnvironment the JDBC environment
|
|
||||||
* @return an identifier instance
|
|
||||||
*/
|
|
||||||
protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) {
|
|
||||||
if (isCaseInsensitive(jdbcEnvironment)) {
|
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
|
||||||
}
|
|
||||||
return new Identifier(name, quoted);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specify whether the database is case sensitive.
|
|
||||||
* @param jdbcEnvironment the JDBC environment which can be used to determine case
|
|
||||||
* @return true if the database is case insensitive sensitivity
|
|
||||||
*/
|
|
||||||
protected boolean isCaseInsensitive(JdbcEnvironment jdbcEnvironment) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isUnderscoreRequired(char before, char current, char after) {
|
|
||||||
return Character.isLowerCase(before) && Character.isUpperCase(current) && Character.isLowerCase(after);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -315,12 +315,6 @@
|
||||||
"description": "Config file name.",
|
"description": "Config file name.",
|
||||||
"defaultValue": "application"
|
"defaultValue": "application"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "spring.config.use-legacy-processing",
|
|
||||||
"type": "java.lang.Boolean",
|
|
||||||
"description": "Whether to enable configuration data processing legacy mode.",
|
|
||||||
"defaultValue": false
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "spring.jpa.defer-datasource-initialization",
|
"name": "spring.jpa.defer-datasource-initialization",
|
||||||
"type": "java.lang.Boolean",
|
"type": "java.lang.Boolean",
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,6 @@ org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter
|
||||||
# Database Initializer Detectors
|
# Database Initializer Detectors
|
||||||
org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector=\
|
org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector=\
|
||||||
org.springframework.boot.flyway.FlywayDatabaseInitializerDetector,\
|
org.springframework.boot.flyway.FlywayDatabaseInitializerDetector,\
|
||||||
org.springframework.boot.jdbc.AbstractDataSourceInitializerDatabaseInitializerDetector,\
|
|
||||||
org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializerDetector,\
|
org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializerDetector,\
|
||||||
org.springframework.boot.liquibase.LiquibaseDatabaseInitializerDetector,\
|
org.springframework.boot.liquibase.LiquibaseDatabaseInitializerDetector,\
|
||||||
org.springframework.boot.orm.jpa.JpaDatabaseInitializerDetector,\
|
org.springframework.boot.orm.jpa.JpaDatabaseInitializerDetector,\
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ import org.springframework.boot.context.properties.source.ConfigurationPropertyN
|
||||||
import org.springframework.mock.env.MockPropertySource;
|
import org.springframework.mock.env.MockPropertySource;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -353,14 +352,6 @@ class ConfigDataEnvironmentContributorTests {
|
||||||
assertThat(contributor.getChildren(ImportPhase.BEFORE_PROFILE_ACTIVATION)).isEmpty();
|
assertThat(contributor.getChildren(ImportPhase.BEFORE_PROFILE_ACTIVATION)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void bindWhenHasUseLegacyPropertyThrowsException() {
|
|
||||||
MockPropertySource propertySource = new MockPropertySource();
|
|
||||||
propertySource.setProperty("spring.config.use-legacy-processing", "true");
|
|
||||||
assertThatExceptionOfType(UseLegacyConfigProcessingException.class).isThrownBy(
|
|
||||||
() -> createBoundContributor(null, new ConfigData(Collections.singleton(propertySource)), 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test // gh-25029
|
@Test // gh-25029
|
||||||
void withBoundPropertiesWhenIgnoringImportsAndNothingBound() {
|
void withBoundPropertiesWhenIgnoringImportsAndNothingBound() {
|
||||||
TestResource resource = new TestResource("a");
|
TestResource resource = new TestResource("a");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -36,12 +36,9 @@ import org.springframework.core.io.ResourceLoader;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
|
||||||
import static org.mockito.BDDMockito.willReturn;
|
import static org.mockito.BDDMockito.willReturn;
|
||||||
import static org.mockito.BDDMockito.willThrow;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoInteractions;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link ConfigDataEnvironmentPostProcessor}.
|
* Tests for {@link ConfigDataEnvironmentPostProcessor}.
|
||||||
|
|
@ -70,12 +67,6 @@ class ConfigDataEnvironmentPostProcessorTests {
|
||||||
@Captor
|
@Captor
|
||||||
private ArgumentCaptor<ResourceLoader> resourceLoaderCaptor;
|
private ArgumentCaptor<ResourceLoader> resourceLoaderCaptor;
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void defaultOrderMatchesDeprecatedListener() {
|
|
||||||
assertThat(ConfigDataEnvironmentPostProcessor.ORDER).isEqualTo(ConfigFileApplicationListener.DEFAULT_ORDER);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void postProcessEnvironmentWhenNoLoaderCreatesDefaultLoaderInstance() {
|
void postProcessEnvironmentWhenNoLoaderCreatesDefaultLoaderInstance() {
|
||||||
willReturn(this.configDataEnvironment).given(this.postProcessor).getConfigDataEnvironment(any(), any(), any());
|
willReturn(this.configDataEnvironment).given(this.postProcessor).getConfigDataEnvironment(any(), any(), any());
|
||||||
|
|
@ -115,33 +106,6 @@ class ConfigDataEnvironmentPostProcessorTests {
|
||||||
assertThat(this.environment.getActiveProfiles()).isEmpty();
|
assertThat(this.environment.getActiveProfiles()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void postProcessEnvironmentWhenUseLegacyProcessingSwitchesToLegacyMethod() {
|
|
||||||
ConfigDataEnvironmentPostProcessor.LegacyConfigFileApplicationListener legacyListener = mock(
|
|
||||||
ConfigDataEnvironmentPostProcessor.LegacyConfigFileApplicationListener.class);
|
|
||||||
willThrow(new UseLegacyConfigProcessingException(null)).given(this.postProcessor)
|
|
||||||
.getConfigDataEnvironment(any(), any(), any());
|
|
||||||
willReturn(legacyListener).given(this.postProcessor).getLegacyListener();
|
|
||||||
this.postProcessor.postProcessEnvironment(this.environment, this.application);
|
|
||||||
verifyNoInteractions(this.configDataEnvironment);
|
|
||||||
verify(legacyListener).addPropertySources(eq(this.environment), any(DefaultResourceLoader.class));
|
|
||||||
assertThat(this.environment.getActiveProfiles()).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void postProcessEnvironmentWhenHasAdditionalProfilesAndUseLegacyProcessing() {
|
|
||||||
this.application.setAdditionalProfiles("dev");
|
|
||||||
ConfigDataEnvironmentPostProcessor.LegacyConfigFileApplicationListener legacyListener = mock(
|
|
||||||
ConfigDataEnvironmentPostProcessor.LegacyConfigFileApplicationListener.class);
|
|
||||||
willThrow(new UseLegacyConfigProcessingException(null)).given(this.postProcessor)
|
|
||||||
.getConfigDataEnvironment(any(), any(), any());
|
|
||||||
willReturn(legacyListener).given(this.postProcessor).getLegacyListener();
|
|
||||||
this.postProcessor.postProcessEnvironment(this.environment, this.application);
|
|
||||||
verifyNoInteractions(this.configDataEnvironment);
|
|
||||||
verify(legacyListener).addPropertySources(eq(this.environment), any(DefaultResourceLoader.class));
|
|
||||||
assertThat(this.environment.getActiveProfiles()).containsExactly("dev");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void applyToAppliesPostProcessing() {
|
void applyToAppliesPostProcessing() {
|
||||||
int before = this.environment.getPropertySources().size();
|
int before = this.environment.getPropertySources().size();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -67,14 +67,6 @@ class ConfigDataEnvironmentTests {
|
||||||
|
|
||||||
private Collection<String> additionalProfiles = Collections.emptyList();
|
private Collection<String> additionalProfiles = Collections.emptyList();
|
||||||
|
|
||||||
@Test
|
|
||||||
void createWhenUseLegacyPropertyInEnvironmentThrowsException() {
|
|
||||||
this.environment.setProperty("spring.config.use-legacy-processing", "true");
|
|
||||||
assertThatExceptionOfType(UseLegacyConfigProcessingException.class)
|
|
||||||
.isThrownBy(() -> new ConfigDataEnvironment(this.logFactory, this.bootstrapContext, this.environment,
|
|
||||||
this.resourceLoader, this.additionalProfiles, null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createExposesEnvironmentBinderToConfigDataLocationResolvers() {
|
void createExposesEnvironmentBinderToConfigDataLocationResolvers() {
|
||||||
this.environment.setProperty("spring", "boot");
|
this.environment.setProperty("spring", "boot");
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2021 the original author or authors.
|
* Copyright 2012-2022 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -31,7 +31,6 @@ import org.springframework.core.env.PropertySource;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -63,26 +62,6 @@ class ConfigDataTests {
|
||||||
assertThat(configData.getPropertySources()).containsExactly(source);
|
assertThat(configData.getPropertySources()).containsExactly(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void getDeprecatedOptionsReturnsCopyOfOptions() {
|
|
||||||
MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
|
|
||||||
Option[] options = { Option.IGNORE_IMPORTS };
|
|
||||||
ConfigData configData = new ConfigData(Collections.singleton(source), options);
|
|
||||||
options[0] = null;
|
|
||||||
assertThat(configData.getOptions()).containsExactly(Option.IGNORE_IMPORTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Deprecated
|
|
||||||
void getDeprecatedOptionsWhenUsingPropertySourceOptionsThrowsException() {
|
|
||||||
MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
|
|
||||||
PropertySourceOptions propertySourceOptions = (propertySource) -> Options.NONE;
|
|
||||||
ConfigData configData = new ConfigData(Collections.singleton(source), propertySourceOptions);
|
|
||||||
assertThatIllegalStateException().isThrownBy(() -> configData.getOptions())
|
|
||||||
.withMessage("No global options defined");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getOptionsWhenOptionsSetAtConstructionAlwaysReturnsSameOptions() {
|
void getOptionsWhenOptionsSetAtConstructionAlwaysReturnsSameOptions() {
|
||||||
MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
|
MapPropertySource source = new MapPropertySource("test", Collections.emptyMap());
|
||||||
|
|
|
||||||
|
|
@ -1,182 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.WebApplicationType;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.core.env.Profiles;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests to reproduce reported issues.
|
|
||||||
*
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @author Dave Syer
|
|
||||||
* @author Nguyen Bao Sach
|
|
||||||
*/
|
|
||||||
@ExtendWith(UseLegacyProcessing.class)
|
|
||||||
class ConfigFileApplicationListenerLegacyReproTests {
|
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
void cleanUp() {
|
|
||||||
if (this.context != null) {
|
|
||||||
this.context.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void enableProfileViaApplicationProperties() {
|
|
||||||
// gh-308
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
this.context = application.run("--spring.config.name=enableprofileviaapplicationproperties",
|
|
||||||
"--spring.profiles.active=dev");
|
|
||||||
assertThat(this.context.getEnvironment().acceptsProfiles(Profiles.of("dev"))).isTrue();
|
|
||||||
assertThat(this.context.getEnvironment().acceptsProfiles(Profiles.of("a"))).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void activeProfilesWithYamlAndCommandLine() {
|
|
||||||
// gh-322, gh-342
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=activeprofilerepro";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=B");
|
|
||||||
assertVersionProperty(this.context, "B", "B");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void activeProfilesWithYamlOnly() {
|
|
||||||
// gh-322, gh-342
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=activeprofilerepro";
|
|
||||||
this.context = application.run(configName);
|
|
||||||
assertVersionProperty(this.context, "B", "B");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void orderActiveProfilesWithYamlOnly() {
|
|
||||||
// gh-322, gh-342
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=activeprofilerepro-ordered";
|
|
||||||
this.context = application.run(configName);
|
|
||||||
assertVersionProperty(this.context, "B", "A", "B");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void commandLineBeatsProfilesWithYaml() {
|
|
||||||
// gh-322, gh-342
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=activeprofilerepro";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=C");
|
|
||||||
assertVersionProperty(this.context, "C", "C");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void orderProfilesWithYaml() {
|
|
||||||
// gh-322, gh-342
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=activeprofilerepro";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=A,C");
|
|
||||||
assertVersionProperty(this.context, "C", "A", "C");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void reverseOrderOfProfilesWithYaml() {
|
|
||||||
// gh-322, gh-342
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=activeprofilerepro";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=C,A");
|
|
||||||
assertVersionProperty(this.context, "A", "C", "A");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void activeProfilesWithYamlAndCommandLineAndNoOverride() {
|
|
||||||
// gh-322, gh-342
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=activeprofilerepro-without-override";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=B");
|
|
||||||
assertVersionProperty(this.context, "B", "B");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void activeProfilesWithYamlOnlyAndNoOverride() {
|
|
||||||
// gh-322, gh-342
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=activeprofilerepro-without-override";
|
|
||||||
this.context = application.run(configName);
|
|
||||||
assertVersionProperty(this.context, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void commandLineBeatsProfilesWithYamlAndNoOverride() {
|
|
||||||
// gh-322, gh-342
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=activeprofilerepro-without-override";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=C");
|
|
||||||
assertVersionProperty(this.context, "C", "C");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void orderProfilesWithYamlAndNoOverride() {
|
|
||||||
// gh-322, gh-342
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=activeprofilerepro-without-override";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=A,C");
|
|
||||||
assertVersionProperty(this.context, "C", "A", "C");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void reverseOrderOfProfilesWithYamlAndNoOverride() {
|
|
||||||
// gh-322, gh-342
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=activeprofilerepro-without-override";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=C,A");
|
|
||||||
assertVersionProperty(this.context, "A", "C", "A");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertVersionProperty(ConfigurableApplicationContext context, String expectedVersion,
|
|
||||||
String... expectedActiveProfiles) {
|
|
||||||
assertThat(context.getEnvironment().getActiveProfiles()).isEqualTo(expectedActiveProfiles);
|
|
||||||
assertThat(context.getEnvironment().getProperty("version")).as("version mismatch").isEqualTo(expectedVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
static class Config {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,160 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2020 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.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.WebApplicationType;
|
|
||||||
import org.springframework.context.ConfigurableApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link ConfigFileApplicationListener} handling of negated profiles in yaml
|
|
||||||
* configuration files.
|
|
||||||
*
|
|
||||||
* @author Madhura Bhave
|
|
||||||
*/
|
|
||||||
@ExtendWith(UseLegacyProcessing.class)
|
|
||||||
class ConfigFileApplicationListenerYamlProfileNegationTests {
|
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
void cleanUp() {
|
|
||||||
if (this.context != null) {
|
|
||||||
this.context.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void yamlProfileNegationDefaultProfile() {
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=profilenegation";
|
|
||||||
this.context = application.run(configName);
|
|
||||||
assertVersionProperty(this.context, "NOT A");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void yamlProfileNegationWithActiveProfile() {
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=profilenegation";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=C,A");
|
|
||||||
assertVersionProperty(this.context, null, "C", "A");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void yamlProfileNegationLocalActiveProfiles() {
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=profilenegation-local-active-profiles";
|
|
||||||
this.context = application.run(configName);
|
|
||||||
assertVersionProperty(this.context, "NOT A", "B");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void yamlProfileNegationOverrideLocalActiveProfiles() {
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=profilenegation-local-active-profiles";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=C,A");
|
|
||||||
assertVersionProperty(this.context, null, "C", "A");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void yamlProfileNegationWithProfileSpecificFile() {
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=profilenegation";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=C,B");
|
|
||||||
assertVersionProperty(this.context, "NOT A", "C", "B");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void yamlProfileCascading() {
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=cascadingprofiles";
|
|
||||||
this.context = application.run(configName);
|
|
||||||
assertVersionProperty(this.context, "D", "A", "C", "E", "B", "D");
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-a")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-b")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-c")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-d")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-e")).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void yamlProfileCascadingOverrideProfilesA() {
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=cascadingprofiles";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=A");
|
|
||||||
assertVersionProperty(this.context, "E", "A", "C", "E");
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-a")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-b")).isEqualTo("true");
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-c")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-d")).isEqualTo("true");
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-e")).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void yamlProfileCascadingMultipleActiveProfilesViaPropertiesShouldPreserveOrder() {
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=cascadingprofiles";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=A,B");
|
|
||||||
assertVersionProperty(this.context, "D", "A", "C", "E", "B", "D");
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-a")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-b")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-c")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-d")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-e")).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void yamlProfileCascadingOverrideProfilesB() {
|
|
||||||
SpringApplication application = new SpringApplication(Config.class);
|
|
||||||
application.setWebApplicationType(WebApplicationType.NONE);
|
|
||||||
String configName = "--spring.config.name=cascadingprofiles";
|
|
||||||
this.context = application.run(configName, "--spring.profiles.active=B");
|
|
||||||
assertVersionProperty(this.context, "E", "B", "D", "E");
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-a")).isEqualTo("true");
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-b")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-c")).isEqualTo("true");
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-d")).isNull();
|
|
||||||
assertThat(this.context.getEnvironment().getProperty("not-e")).isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertVersionProperty(ConfigurableApplicationContext context, String expectedVersion,
|
|
||||||
String... expectedActiveProfiles) {
|
|
||||||
assertThat(context.getEnvironment().getActiveProfiles()).isEqualTo(expectedActiveProfiles);
|
|
||||||
assertThat(context.getEnvironment().getProperty("version")).as("version mismatch").isEqualTo(expectedVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
static class Config {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2020 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.boot.context.properties.bind.Binder;
|
|
||||||
import org.springframework.boot.context.properties.source.MockConfigurationPropertySource;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link UseLegacyConfigProcessingException}.
|
|
||||||
*
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @author Madhura Bhave
|
|
||||||
*/
|
|
||||||
class UseLegacyConfigProcessingExceptionTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void throwIfRequestedWhenMissingDoesNothing() {
|
|
||||||
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
|
||||||
Binder binder = new Binder(source);
|
|
||||||
UseLegacyConfigProcessingException.throwIfRequested(binder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void throwIfRequestedWhenFalseDoesNothing() {
|
|
||||||
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
|
||||||
source.put("spring.config.use-legacy-processing", "false");
|
|
||||||
Binder binder = new Binder(source);
|
|
||||||
UseLegacyConfigProcessingException.throwIfRequested(binder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void throwIfRequestedWhenTrueThrowsException() {
|
|
||||||
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
|
||||||
source.put("spring.config.use-legacy-processing", "true");
|
|
||||||
Binder binder = new Binder(source);
|
|
||||||
assertThatExceptionOfType(UseLegacyConfigProcessingException.class)
|
|
||||||
.isThrownBy(() -> UseLegacyConfigProcessingException.throwIfRequested(binder))
|
|
||||||
.satisfies((ex) -> assertThat(ex.getConfigurationProperty().getName())
|
|
||||||
.hasToString("spring.config.use-legacy-processing"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2020 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.extension.AfterAllCallback;
|
|
||||||
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
|
||||||
import org.junit.jupiter.api.extension.Extension;
|
|
||||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JUnit {@link Extension @Extension} to switch a test to use legacy processing.
|
|
||||||
*
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @author Madhura Bhave
|
|
||||||
*/
|
|
||||||
public class UseLegacyProcessing implements BeforeAllCallback, AfterAllCallback {
|
|
||||||
|
|
||||||
private static final String PROPERTY_NAME = "spring.config.use-legacy-processing";
|
|
||||||
|
|
||||||
private String propertyValue;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beforeAll(ExtensionContext context) throws Exception {
|
|
||||||
this.propertyValue = System.setProperty(PROPERTY_NAME, "true");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterAll(ExtensionContext context) throws Exception {
|
|
||||||
if (this.propertyValue != null) {
|
|
||||||
System.setProperty(PROPERTY_NAME, this.propertyValue);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
System.clearProperty(PROPERTY_NAME);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,97 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.jdbc;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer;
|
|
||||||
import org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitialization;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
import org.springframework.core.io.ResourceLoader;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for the configuration of dependencies on {@link AbstractDataSourceInitializer}
|
|
||||||
* beans.
|
|
||||||
*
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class AbstractDataSourceInitializerDependencyConfigurationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void beansThatDependOnDatabaseInitializationDependOnAbstractDataSourceInitializerBeans() {
|
|
||||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
|
||||||
TestConfiguration.class)) {
|
|
||||||
assertThat(context.getBeanFactory().getBeanDefinition("factoryMethodDependsOnDatabaseInitialization")
|
|
||||||
.getDependsOn()).contains("initializer");
|
|
||||||
assertThat(context.getBeanFactory().getBeanDefinition("beanClassDependsOnDatabaseInitialization")
|
|
||||||
.getDependsOn()).contains("initializer");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Import(DatabaseInitializationDependencyConfigurer.class)
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
|
||||||
static class TestConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
DataSource dataSource() {
|
|
||||||
return DataSourceBuilder.create().build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@DependsOnDatabaseInitialization
|
|
||||||
String factoryMethodDependsOnDatabaseInitialization() {
|
|
||||||
return "test";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
DatabaseInitializationDependent beanClassDependsOnDatabaseInitialization() {
|
|
||||||
return new DatabaseInitializationDependent();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
AbstractDataSourceInitializer initializer(DataSource dataSource, ResourceLoader resourceLoader) {
|
|
||||||
return new AbstractDataSourceInitializer(dataSource, resourceLoader) {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getSchemaLocation() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected DataSourceInitializationMode getMode() {
|
|
||||||
return DataSourceInitializationMode.NEVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@DependsOnDatabaseInitialization
|
|
||||||
static class DatabaseInitializationDependent {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,80 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.orm.jpa.hibernate;
|
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
|
||||||
import org.hibernate.boot.MetadataSources;
|
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
|
||||||
import org.hibernate.dialect.H2Dialect;
|
|
||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
|
||||||
import org.hibernate.mapping.PersistentClass;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link SpringPhysicalNamingStrategy}.
|
|
||||||
*
|
|
||||||
* @author Phillip Webb
|
|
||||||
* @author Madhura Bhave
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
class SpringPhysicalNamingStrategyTests {
|
|
||||||
|
|
||||||
private Metadata metadata;
|
|
||||||
|
|
||||||
private MetadataSources metadataSources;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setup() {
|
|
||||||
this.metadataSources = new MetadataSources(createServiceRegistry());
|
|
||||||
this.metadataSources.addAnnotatedClass(TelephoneNumber.class);
|
|
||||||
this.metadata = this.metadataSources.getMetadataBuilder()
|
|
||||||
.applyPhysicalNamingStrategy(new SpringPhysicalNamingStrategy()).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private StandardServiceRegistry createServiceRegistry() {
|
|
||||||
return new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, H2Dialect.class).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void tableNameShouldBeLowercaseUnderscore() {
|
|
||||||
PersistentClass binding = this.metadata.getEntityBinding(TelephoneNumber.class.getName());
|
|
||||||
assertThat(binding.getTable().getQuotedName()).isEqualTo("telephone_number");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void tableNameShouldNotBeLowerCaseIfCaseSensitive() {
|
|
||||||
this.metadata = this.metadataSources.getMetadataBuilder()
|
|
||||||
.applyPhysicalNamingStrategy(new TestSpringPhysicalNamingStrategy()).build();
|
|
||||||
PersistentClass binding = this.metadata.getEntityBinding(TelephoneNumber.class.getName());
|
|
||||||
assertThat(binding.getTable().getQuotedName()).isEqualTo("Telephone_Number");
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TestSpringPhysicalNamingStrategy extends SpringPhysicalNamingStrategy {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isCaseInsensitive(JdbcEnvironment jdbcEnvironment) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2021 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.orm.jpa.hibernate;
|
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
|
||||||
import jakarta.persistence.Id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple entity used in {@link SpringPhysicalNamingStrategyTests}.
|
|
||||||
*
|
|
||||||
* @author Phillip Webb
|
|
||||||
*/
|
|
||||||
@Entity
|
|
||||||
public class TelephoneNumber {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
|
||||||
Long id;
|
|
||||||
|
|
||||||
String areaCode;
|
|
||||||
|
|
||||||
String number;
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue