Merge branch '2.7.x'
commit
11e604af41
@ -1,44 +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.actuate.endpoint.http;
|
||||
|
||||
/**
|
||||
* Media types that can be consumed and produced by Actuator endpoints.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Madhura Bhave
|
||||
* @since 2.0.0
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of
|
||||
* {@link org.springframework.boot.actuate.endpoint.ApiVersion#getProducedMimeType()}
|
||||
*/
|
||||
@Deprecated
|
||||
public final class ActuatorMediaType {
|
||||
|
||||
/**
|
||||
* Constant for the Actuator {@link ApiVersion#V2 v2} media type.
|
||||
*/
|
||||
public static final String V2_JSON = "application/vnd.spring-boot.actuator.v2+json";
|
||||
|
||||
/**
|
||||
* Constant for the Actuator {@link ApiVersion#V3 v3} media type.
|
||||
*/
|
||||
public static final String V3_JSON = "application/vnd.spring-boot.actuator.v3+json";
|
||||
|
||||
private ActuatorMediaType() {
|
||||
}
|
||||
|
||||
}
|
@ -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.actuate.endpoint.http;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.ProducibleOperationArgumentResolver;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
/**
|
||||
* API versions supported for the actuator HTTP API. This enum may be injected into
|
||||
* actuator endpoints in order to return a response compatible with the requested version.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 2.2.0
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of
|
||||
* {@link org.springframework.boot.actuate.endpoint.ApiVersion}
|
||||
*/
|
||||
@Deprecated
|
||||
public enum ApiVersion {
|
||||
|
||||
/**
|
||||
* Version 2 (supported by Spring Boot 2.0+).
|
||||
*/
|
||||
V2,
|
||||
|
||||
/**
|
||||
* Version 3 (supported by Spring Boot 2.2+).
|
||||
*/
|
||||
V3;
|
||||
|
||||
private static final String MEDIA_TYPE_PREFIX = "application/vnd.spring-boot.actuator.";
|
||||
|
||||
/**
|
||||
* The latest API version.
|
||||
*/
|
||||
public static final ApiVersion LATEST = ApiVersion.V3;
|
||||
|
||||
/**
|
||||
* Return the {@link ApiVersion} to use based on the HTTP request headers. The version
|
||||
* will be deduced based on the {@code Accept} header.
|
||||
* @param headers the HTTP headers
|
||||
* @return the API version to use
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of direct injection with
|
||||
* resolution via the {@link ProducibleOperationArgumentResolver}.
|
||||
*/
|
||||
@Deprecated
|
||||
public static ApiVersion fromHttpHeaders(Map<String, List<String>> headers) {
|
||||
ApiVersion version = null;
|
||||
List<String> accepts = headers.get("Accept");
|
||||
if (!CollectionUtils.isEmpty(accepts)) {
|
||||
for (String accept : accepts) {
|
||||
for (String type : MimeTypeUtils.tokenize(accept)) {
|
||||
version = mostRecent(version, forType(type));
|
||||
}
|
||||
}
|
||||
}
|
||||
return (version != null) ? version : LATEST;
|
||||
}
|
||||
|
||||
private static ApiVersion forType(String type) {
|
||||
if (type.startsWith(MEDIA_TYPE_PREFIX)) {
|
||||
type = type.substring(MEDIA_TYPE_PREFIX.length());
|
||||
int suffixIndex = type.indexOf('+');
|
||||
type = (suffixIndex != -1) ? type.substring(0, suffixIndex) : type;
|
||||
try {
|
||||
return valueOf(type.toUpperCase());
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ApiVersion mostRecent(ApiVersion existing, ApiVersion candidate) {
|
||||
int existingOrdinal = (existing != null) ? existing.ordinal() : -1;
|
||||
int candidateOrdinal = (candidate != null) ? candidate.ordinal() : -1;
|
||||
return (candidateOrdinal > existingOrdinal) ? candidate : existing;
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Actuator endpoint HTTP concerns (not tied to any specific implementation).
|
||||
*/
|
||||
package org.springframework.boot.actuate.endpoint.http;
|
@ -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.actuate.endpoint.http;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test for {@link ApiVersion}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@Deprecated
|
||||
class ApiVersionTests {
|
||||
|
||||
@Test
|
||||
void latestIsLatestVersion() {
|
||||
ApiVersion[] values = ApiVersion.values();
|
||||
assertThat(ApiVersion.LATEST).isEqualTo(values[values.length - 1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void fromHttpHeadersWhenEmptyReturnsLatest() {
|
||||
ApiVersion version = ApiVersion.fromHttpHeaders(Collections.emptyMap());
|
||||
assertThat(version).isEqualTo(ApiVersion.V3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void fromHttpHeadersWhenHasSingleV2HeaderReturnsV2() {
|
||||
ApiVersion version = ApiVersion.fromHttpHeaders(acceptHeader(ActuatorMediaType.V2_JSON));
|
||||
assertThat(version).isEqualTo(ApiVersion.V2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void fromHttpHeadersWhenHasSingleV3HeaderReturnsV3() {
|
||||
ApiVersion version = ApiVersion.fromHttpHeaders(acceptHeader(ActuatorMediaType.V3_JSON));
|
||||
assertThat(version).isEqualTo(ApiVersion.V3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void fromHttpHeadersWhenHasV2AndV3HeaderReturnsV3() {
|
||||
ApiVersion version = ApiVersion
|
||||
.fromHttpHeaders(acceptHeader(ActuatorMediaType.V2_JSON, ActuatorMediaType.V3_JSON));
|
||||
assertThat(version).isEqualTo(ApiVersion.V3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void fromHttpHeadersWhenHasV2AndV3AsOneHeaderReturnsV3() {
|
||||
ApiVersion version = ApiVersion
|
||||
.fromHttpHeaders(acceptHeader(ActuatorMediaType.V2_JSON + "," + ActuatorMediaType.V3_JSON));
|
||||
assertThat(version).isEqualTo(ApiVersion.V3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void fromHttpHeadersWhenHasSingleHeaderWithoutJsonReturnsHeader() {
|
||||
ApiVersion version = ApiVersion.fromHttpHeaders(acceptHeader("application/vnd.spring-boot.actuator.v2"));
|
||||
assertThat(version).isEqualTo(ApiVersion.V2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void fromHttpHeadersWhenHasUnknownVersionReturnsLatest() {
|
||||
ApiVersion version = ApiVersion.fromHttpHeaders(acceptHeader("application/vnd.spring-boot.actuator.v200"));
|
||||
assertThat(version).isEqualTo(ApiVersion.V3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void fromHttpHeadersWhenAcceptsEverythingReturnsLatest() {
|
||||
ApiVersion version = ApiVersion.fromHttpHeaders(acceptHeader("*/*"));
|
||||
assertThat(version).isEqualTo(ApiVersion.V3);
|
||||
}
|
||||
|
||||
private Map<String, List<String>> acceptHeader(String... types) {
|
||||
List<String> value = Arrays.asList(types);
|
||||
return value.isEmpty() ? Collections.emptyMap() : Collections.singletonMap("Accept", value);
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +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.jpa;
|
||||
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
|
||||
/**
|
||||
* {@link BeanFactoryPostProcessor} that can be used to dynamically declare that all
|
||||
* {@link EntityManagerFactory} beans should "depend on" one or more specific beans.
|
||||
*
|
||||
* @author Marcel Overdijk
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
* @author Andrii Hrytsiuk
|
||||
* @since 1.1.0
|
||||
* @see BeanDefinition#setDependsOn(String[])
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of
|
||||
* {@link org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor}
|
||||
*/
|
||||
@Deprecated
|
||||
public class EntityManagerFactoryDependsOnPostProcessor
|
||||
extends org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor {
|
||||
|
||||
/**
|
||||
* Creates a new {@code EntityManagerFactoryDependsOnPostProcessor} that will set up
|
||||
* dependencies upon beans with the given names.
|
||||
* @param dependsOn names of the beans to depend upon
|
||||
*/
|
||||
public EntityManagerFactoryDependsOnPostProcessor(String... dependsOn) {
|
||||
super(dependsOn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code EntityManagerFactoryDependsOnPostProcessor} that will set up
|
||||
* dependencies upon beans with the given types.
|
||||
* @param dependsOn types of the beans to depend upon
|
||||
* @since 2.1.8
|
||||
*/
|
||||
public EntityManagerFactoryDependsOnPostProcessor(Class<?>... dependsOn) {
|
||||
super(dependsOn);
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +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.flyway;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Exception thrown when no Flyway migration script is available.
|
||||
*
|
||||
* @author Anand Shastri
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.2.0
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 as location checking is deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
public class FlywayMigrationScriptMissingException extends RuntimeException {
|
||||
|
||||
private final List<String> locations;
|
||||
|
||||
FlywayMigrationScriptMissingException(List<String> locations) {
|
||||
super(locations.isEmpty() ? "Migration script locations not configured" : "Cannot find migration scripts in: "
|
||||
+ locations + " (please add migration scripts or check your Flyway configuration)");
|
||||
this.locations = new ArrayList<>(locations);
|
||||
}
|
||||
|
||||
public List<String> getLocations() {
|
||||
return this.locations;
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +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.flyway;
|
||||
|
||||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
|
||||
/**
|
||||
* A {@code FailureAnalyzer} that performs analysis of failures caused by a
|
||||
* {@link FlywayMigrationScriptMissingException}.
|
||||
*
|
||||
* @author Anand Shastri
|
||||
* @author Stephane Nicoll
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 as location checking is deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
class FlywayMigrationScriptMissingFailureAnalyzer
|
||||
extends AbstractFailureAnalyzer<FlywayMigrationScriptMissingException> {
|
||||
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, FlywayMigrationScriptMissingException cause) {
|
||||
StringBuilder description = new StringBuilder("Flyway failed to initialize: ");
|
||||
if (cause.getLocations().isEmpty()) {
|
||||
return new FailureAnalysis(description.append("no migration scripts location is configured").toString(),
|
||||
"Check your Flyway configuration", cause);
|
||||
}
|
||||
description.append(String.format("none of the following migration scripts locations could be found:%n%n"));
|
||||
cause.getLocations().forEach((location) -> description.append(String.format("\t- %s%n", location)));
|
||||
return new FailureAnalysis(description.toString(),
|
||||
"Review the locations above or check your Flyway configuration", cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,103 +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.hateoas;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.hateoas.mediatype.hal.HalConfiguration;
|
||||
import org.springframework.hateoas.server.mvc.TypeConstrainedMappingJackson2HttpMessageConverter;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.AbstractHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
|
||||
/**
|
||||
* Configuration for {@link HttpMessageConverter HttpMessageConverters} when hypermedia is
|
||||
* enabled.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @since 1.3.0
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of a {@link HalConfiguration}
|
||||
* bean
|
||||
*/
|
||||
@Deprecated
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class HypermediaHttpMessageConverterConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "spring.hateoas", name = "use-hal-as-default-json-media-type",
|
||||
matchIfMissing = true)
|
||||
public static HalMessageConverterSupportedMediaTypesCustomizer halMessageConverterSupportedMediaTypeCustomizer() {
|
||||
return new HalMessageConverterSupportedMediaTypesCustomizer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates any {@link TypeConstrainedMappingJackson2HttpMessageConverter}s to support
|
||||
* {@code application/json} in addition to {@code application/hal+json}. Cannot be a
|
||||
* {@link BeanPostProcessor} as processing must be performed after
|
||||
* {@code Jackson2ModuleRegisteringBeanPostProcessor} has registered the converter and
|
||||
* it is unordered.
|
||||
*/
|
||||
static class HalMessageConverterSupportedMediaTypesCustomizer implements BeanFactoryAware, InitializingBean {
|
||||
|
||||
private volatile BeanFactory beanFactory;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (this.beanFactory instanceof ListableBeanFactory) {
|
||||
configureHttpMessageConverters(((ListableBeanFactory) this.beanFactory)
|
||||
.getBeansOfType(RequestMappingHandlerAdapter.class).values());
|
||||
}
|
||||
}
|
||||
|
||||
private void configureHttpMessageConverters(Collection<RequestMappingHandlerAdapter> handlerAdapters) {
|
||||
for (RequestMappingHandlerAdapter handlerAdapter : handlerAdapters) {
|
||||
for (HttpMessageConverter<?> messageConverter : handlerAdapter.getMessageConverters()) {
|
||||
configureHttpMessageConverter(messageConverter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void configureHttpMessageConverter(HttpMessageConverter<?> converter) {
|
||||
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
|
||||
List<MediaType> supportedMediaTypes = new ArrayList<>(converter.getSupportedMediaTypes());
|
||||
if (!supportedMediaTypes.contains(MediaType.APPLICATION_JSON)) {
|
||||
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
((AbstractHttpMessageConverter<?>) converter).setSupportedMediaTypes(supportedMediaTypes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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.autoconfigure.jdbc;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* {@link ApplicationEvent} used internally to indicate that the schema of a new
|
||||
* {@link DataSource} has been created. This happens when {@literal schema-*.sql} files
|
||||
* are executed or when Hibernate initializes the database.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.0.0
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 with no replacement as the event is no
|
||||
* longer published
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@Deprecated
|
||||
public class DataSourceSchemaCreatedEvent extends ApplicationEvent {
|
||||
|
||||
/**
|
||||
* Create a new {@link DataSourceSchemaCreatedEvent}.
|
||||
* @param source the source {@link DataSource}.
|
||||
*/
|
||||
public DataSourceSchemaCreatedEvent(DataSource source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
}
|
@ -1,61 +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 org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor;
|
||||
import org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
|
||||
/**
|
||||
* {@link BeanFactoryPostProcessor} that can be used to dynamically declare that all
|
||||
* {@link JdbcOperations} beans should "depend on" one or more specific beans.
|
||||
*
|
||||
* @author Marcel Overdijk
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
* @author Andrii Hrytsiuk
|
||||
* @since 2.0.4
|
||||
* @see BeanDefinition#setDependsOn(String[])
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of
|
||||
* {@link DependsOnDatabaseInitializationDetector}
|
||||
*/
|
||||
@Deprecated
|
||||
public class JdbcOperationsDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
|
||||
|
||||
/**
|
||||
* Creates a new {@code JdbcOperationsDependsOnPostProcessor} that will set up
|
||||
* dependencies upon beans with the given names.
|
||||
* @param dependsOn names of the beans to depend upon
|
||||
*/
|
||||
public JdbcOperationsDependsOnPostProcessor(String... dependsOn) {
|
||||
super(JdbcOperations.class, dependsOn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code JdbcOperationsDependsOnPostProcessor} that will set up
|
||||
* dependencies upon beans with the given types.
|
||||
* @param dependsOn types of the beans to depend upon
|
||||
* @since 2.1.8
|
||||
*/
|
||||
public JdbcOperationsDependsOnPostProcessor(Class<?>... dependsOn) {
|
||||
super(JdbcOperations.class, dependsOn);
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +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 org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor;
|
||||
import org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
|
||||
/**
|
||||
* {@link BeanFactoryPostProcessor} that can be used to dynamically declare that all
|
||||
* {@link NamedParameterJdbcOperations} beans should "depend on" one or more specific
|
||||
* beans.
|
||||
*
|
||||
* @author Dan Zheng
|
||||
* @author Andrii Hrytsiuk
|
||||
* @since 2.1.4
|
||||
* @see BeanDefinition#setDependsOn(String[])
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of
|
||||
* {@link DependsOnDatabaseInitializationDetector}
|
||||
*/
|
||||
@Deprecated
|
||||
public class NamedParameterJdbcOperationsDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
|
||||
|
||||
/**
|
||||
* Creates a new {@code NamedParameterJdbcOperationsDependsOnPostProcessor} that will
|
||||
* set up dependencies upon beans with the given names.
|
||||
* @param dependsOn names of the beans to depend upon
|
||||
*/
|
||||
public NamedParameterJdbcOperationsDependsOnPostProcessor(String... dependsOn) {
|
||||
super(NamedParameterJdbcOperations.class, dependsOn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code NamedParameterJdbcOperationsDependsOnPostProcessor} that will
|
||||
* set up dependencies upon beans with the given types.
|
||||
* @param dependsOn types of the beans to depend upon
|
||||
* @since 2.1.8
|
||||
*/
|
||||
public NamedParameterJdbcOperationsDependsOnPostProcessor(Class<?>... dependsOn) {
|
||||
super(NamedParameterJdbcOperations.class, dependsOn);
|
||||
}
|
||||
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2022 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.jooq;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.boot.autoconfigure.AbstractDependsOnBeanFactoryPostProcessor;
|
||||
import org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector;
|
||||
|
||||
/**
|
||||
* {@link BeanFactoryPostProcessor} that can be used to dynamically declare that all
|
||||
* {@link DSLContext} beans should "depend on" one or more specific beans.
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
* @since 2.3.9
|
||||
* @see BeanDefinition#setDependsOn(String[])
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of
|
||||
* {@link DependsOnDatabaseInitializationDetector}
|
||||
*/
|
||||
@Deprecated
|
||||
public class DslContextDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
|
||||
|
||||
/**
|
||||
* Creates a new {@code DslContextDependsOnPostProcessor} that will set up
|
||||
* dependencies upon beans with the given names.
|
||||
* @param dependsOn names of the beans to depend upon
|
||||
*/
|
||||
public DslContextDependsOnPostProcessor(String... dependsOn) {
|
||||
super(DSLContext.class, dependsOn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code DslContextDependsOnPostProcessor} that will set up
|
||||
* dependencies upon beans with the given types.
|
||||
* @param dependsOn types of the beans to depend upon
|
||||
*/
|
||||
public DslContextDependsOnPostProcessor(Class<?>... dependsOn) {
|
||||
super(DSLContext.class, dependsOn);
|
||||
}
|
||||
|
||||
}
|
@ -1,82 +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.mustache;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import com.samskivert.mustache.DefaultCollector;
|
||||
import com.samskivert.mustache.Mustache.Collector;
|
||||
import com.samskivert.mustache.Mustache.VariableFetcher;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* Mustache {@link Collector} to expose properties from the Spring {@link Environment}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Madhura Bhave
|
||||
* @since 1.2.2
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of direct addition of values from
|
||||
* the Environment to the model
|
||||
*/
|
||||
@Deprecated
|
||||
public class MustacheEnvironmentCollector extends DefaultCollector implements EnvironmentAware {
|
||||
|
||||
private ConfigurableEnvironment environment;
|
||||
|
||||
private final VariableFetcher propertyFetcher = new PropertyVariableFetcher();
|
||||
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = (ConfigurableEnvironment) environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VariableFetcher createFetcher(Object ctx, String name) {
|
||||
VariableFetcher fetcher = super.createFetcher(ctx, name);
|
||||
if (fetcher != null) {
|
||||
return fetcher;
|
||||
}
|
||||
if (this.environment.containsProperty(name)) {
|
||||
return this.propertyFetcher;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private class PropertyVariableFetcher implements VariableFetcher {
|
||||
|
||||
private final Log log = LogFactory.getLog(PropertyVariableFetcher.class);
|
||||
|
||||
private final AtomicBoolean logDeprecationWarning = new AtomicBoolean();
|
||||
|
||||
@Override
|
||||
public Object get(Object ctx, String name) {
|
||||
String property = MustacheEnvironmentCollector.this.environment.getProperty(name);
|
||||
if (property != null && this.logDeprecationWarning.compareAndSet(false, true)) {
|
||||
this.log.warn("Mustache variable resolution relied upon deprecated support for falling back to the "
|
||||
+ "Spring Environment. Please add values from the Environment directly to the model instead.");
|
||||
}
|
||||
return property;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,143 +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.r2dbc;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import io.r2dbc.spi.ConnectionFactories;
|
||||
import io.r2dbc.spi.ConnectionFactory;
|
||||
import io.r2dbc.spi.ConnectionFactoryOptions;
|
||||
import io.r2dbc.spi.ConnectionFactoryOptions.Builder;
|
||||
|
||||
/**
|
||||
* Builder for {@link ConnectionFactory}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Tadaya Tsuyukubo
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.3.0
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of
|
||||
* {@link org.springframework.boot.r2dbc.ConnectionFactoryBuilder}
|
||||
*/
|
||||
@Deprecated
|
||||
public final class ConnectionFactoryBuilder {
|
||||
|
||||
private final ConnectionFactoryOptions.Builder optionsBuilder;
|
||||
|
||||
private ConnectionFactoryBuilder(ConnectionFactoryOptions.Builder optionsBuilder) {
|
||||
this.optionsBuilder = optionsBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a new {@link ConnectionFactoryBuilder} based on the specified
|
||||
* {@link R2dbcProperties}. If no url is specified, the
|
||||
* {@link EmbeddedDatabaseConnection} supplier is invoked to determine if an embedded
|
||||
* database can be configured instead.
|
||||
* @param properties the properties to use to initialize the builder
|
||||
* @param embeddedDatabaseConnection a supplier for an
|
||||
* {@link EmbeddedDatabaseConnection}
|
||||
* @return a new builder initialized with the settings defined in
|
||||
* {@link R2dbcProperties}
|
||||
*/
|
||||
public static ConnectionFactoryBuilder of(R2dbcProperties properties,
|
||||
Supplier<EmbeddedDatabaseConnection> embeddedDatabaseConnection) {
|
||||
return new ConnectionFactoryBuilder(
|
||||
new ConnectionFactoryOptionsInitializer().initialize(properties, adapt(embeddedDatabaseConnection)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure additional options.
|
||||
* @param options a {@link Consumer} to customize the options
|
||||
* @return this for method chaining
|
||||
*/
|
||||
public ConnectionFactoryBuilder configure(Consumer<Builder> options) {
|
||||
options.accept(this.optionsBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the {@linkplain ConnectionFactoryOptions#USER username}.
|
||||
* @param username the connection factory username
|
||||
* @return this for method chaining
|
||||
*/
|
||||
public ConnectionFactoryBuilder username(String username) {
|
||||
return configure((options) -> options.option(ConnectionFactoryOptions.USER, username));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the {@linkplain ConnectionFactoryOptions#PASSWORD password}.
|
||||
* @param password the connection factory password
|
||||
* @return this for method chaining
|
||||
*/
|
||||
public ConnectionFactoryBuilder password(CharSequence password) {
|
||||
return configure((options) -> options.option(ConnectionFactoryOptions.PASSWORD, password));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the {@linkplain ConnectionFactoryOptions#HOST host name}.
|
||||
* @param host the connection factory hostname
|
||||
* @return this for method chaining
|
||||
*/
|
||||
public ConnectionFactoryBuilder hostname(String host) {
|
||||
return configure((options) -> options.option(ConnectionFactoryOptions.HOST, host));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the {@linkplain ConnectionFactoryOptions#PORT port}.
|
||||
* @param port the connection factory port
|
||||
* @return this for method chaining
|
||||
*/
|
||||
public ConnectionFactoryBuilder port(int port) {
|
||||
return configure((options) -> options.option(ConnectionFactoryOptions.PORT, port));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the {@linkplain ConnectionFactoryOptions#DATABASE database}.
|
||||
* @param database the connection factory database
|
||||
* @return this for method chaining
|
||||
*/
|
||||
public ConnectionFactoryBuilder database(String database) {
|
||||
return configure((options) -> options.option(ConnectionFactoryOptions.DATABASE, database));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a {@link ConnectionFactory} based on the state of this builder.
|
||||
* @return a connection factory
|
||||
*/
|
||||
public ConnectionFactory build() {
|
||||
return ConnectionFactories.get(buildOptions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a {@link ConnectionFactoryOptions} based on the state of this builder.
|
||||
* @return the options
|
||||
*/
|
||||
public ConnectionFactoryOptions buildOptions() {
|
||||
return this.optionsBuilder.build();
|
||||
}
|
||||
|
||||
private static Supplier<org.springframework.boot.r2dbc.EmbeddedDatabaseConnection> adapt(
|
||||
Supplier<EmbeddedDatabaseConnection> embeddedDatabaseConnection) {
|
||||
return () -> {
|
||||
EmbeddedDatabaseConnection connection = embeddedDatabaseConnection.get();
|
||||
return (connection != null)
|
||||
? org.springframework.boot.r2dbc.EmbeddedDatabaseConnection.valueOf(connection.name()) : null;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -1,98 +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.r2dbc;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Connection details for embedded databases compatible with r2dbc.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.3.0
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of
|
||||
* {@link org.springframework.boot.r2dbc.EmbeddedDatabaseConnection}
|
||||
*/
|
||||
@Deprecated
|
||||
public enum EmbeddedDatabaseConnection {
|
||||
|
||||
/**
|
||||
* No Connection.
|
||||
*/
|
||||
NONE(null, null, null),
|
||||
|
||||
/**
|
||||
* H2 Database Connection.
|
||||
*/
|
||||
H2("H2", "io.r2dbc.h2.H2ConnectionFactoryProvider",
|
||||
"r2dbc:h2:mem:///%s?options=DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
|
||||
|
||||
private final String type;
|
||||
|
||||
private final String driverClassName;
|
||||
|
||||
private final String url;
|
||||
|
||||
EmbeddedDatabaseConnection(String type, String driverClassName, String url) {
|
||||
this.type = type;
|
||||
this.driverClassName = driverClassName;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the driver class name.
|
||||
* @return the driver class name
|
||||
*/
|
||||
public String getDriverClassName() {
|
||||
return this.driverClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the embedded database type name for the connection.
|
||||
* @return the database type
|
||||
*/
|
||||
public String getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the R2DBC URL for the connection using the specified {@code databaseName}.
|
||||
* @param databaseName the name of the database
|
||||
* @return the connection URL
|
||||
*/
|
||||
public String getUrl(String databaseName) {
|
||||
Assert.hasText(databaseName, "DatabaseName must not be empty");
|
||||
return (this.url != null) ? String.format(this.url, databaseName) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the most suitable {@link EmbeddedDatabaseConnection} for the given class
|
||||
* loader.
|
||||
* @param classLoader the class loader used to check for classes
|
||||
* @return an {@link EmbeddedDatabaseConnection} or {@link #NONE}.
|
||||
*/
|
||||
public static EmbeddedDatabaseConnection get(ClassLoader classLoader) {
|
||||
for (EmbeddedDatabaseConnection candidate : EmbeddedDatabaseConnection.values()) {
|
||||
if (candidate != NONE && ClassUtils.isPresent(candidate.getDriverClassName(), classLoader)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +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.flyway;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link FlywayMigrationScriptMissingFailureAnalyzer}.
|
||||
*
|
||||
* @author Anand Shastri
|
||||
* @deprecated since 2.5.0 for removal in 2.7.0 as location checking is deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
class FlywayMigrationScriptMissingFailureAnalyzerTests {
|
||||
|
||||
@Test
|
||||
void analysisForMissingScriptLocation() {
|
||||
FailureAnalysis failureAnalysis = performAnalysis();
|
||||
assertThat(failureAnalysis.getDescription()).contains("no migration scripts location is configured");
|
||||
assertThat(failureAnalysis.getAction()).contains("Check your Flyway configuration");
|
||||
}
|
||||
|
||||
@Test
|
||||
void analysisForScriptLocationsNotFound() {
|
||||
FailureAnalysis failureAnalysis = performAnalysis("classpath:db/migration");
|
||||
assertThat(failureAnalysis.getDescription())
|
||||
.contains("none of the following migration scripts locations could be found")
|
||||
.contains("classpath:db/migration");
|
||||
assertThat(failureAnalysis.getAction())
|
||||
.contains("Review the locations above or check your Flyway configuration");
|
||||
}
|
||||
|
||||
private FailureAnalysis performAnalysis(String... locations) {
|
||||
FlywayMigrationScriptMissingException exception = new FlywayMigrationScriptMissingException(
|
||||
Arrays.asList(locations));
|
||||
return new FlywayMigrationScriptMissingFailureAnalyzer().analyze(exception);
|
||||
}
|
||||
|
||||
}
|
@ -1,214 +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.r2dbc;
|
||||
|
||||
import io.r2dbc.spi.ConnectionFactoryOptions;
|
||||
import io.r2dbc.spi.Option;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.autoconfigure.r2dbc.ConnectionFactoryOptionsInitializer.ConnectionFactoryBeanCreationException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link ConnectionFactoryBuilder}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Tadaya Tsuyukubo
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Deprecated
|
||||
class ConnectionFactoryBuilderTests {
|
||||
|
||||
@Test
|
||||
void propertiesWithoutUrlAndNoAvailableEmbeddedConnectionShouldFail() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
assertThatThrownBy(() -> ConnectionFactoryBuilder.of(properties, () -> EmbeddedDatabaseConnection.NONE))
|
||||
.isInstanceOf(ConnectionFactoryBeanCreationException.class)
|
||||
.hasMessage("Failed to determine a suitable R2DBC Connection URL");
|
||||
}
|
||||
|
||||
@Test
|
||||
void connectionFactoryBeanCreationProvidesConnectionAndProperties() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
try {
|
||||
ConnectionFactoryBuilder.of(properties, () -> EmbeddedDatabaseConnection.NONE);
|
||||
fail("Should have thrown a " + ConnectionFactoryBeanCreationException.class.getName());
|
||||
}
|
||||
catch (ConnectionFactoryBeanCreationException ex) {
|
||||
assertThat(ex.getEmbeddedDatabaseConnection())
|
||||
.isEqualTo(org.springframework.boot.r2dbc.EmbeddedDatabaseConnection.NONE);
|
||||
assertThat(ex.getProperties()).isSameAs(properties);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionIsConfiguredAutomaticallyWithUrl() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple://:pool:");
|
||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder
|
||||
.of(properties, () -> EmbeddedDatabaseConnection.NONE).buildOptions();
|
||||
assertThat(options.hasOption(ConnectionFactoryOptions.USER)).isFalse();
|
||||
assertThat(options.hasOption(ConnectionFactoryOptions.PASSWORD)).isFalse();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("simple");
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionShouldInitializeUrlOptions() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple:proto://user:password@myhost:4711/mydatabase");
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("simple");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PROTOCOL)).isEqualTo("proto");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("user");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("password");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.HOST)).isEqualTo("myhost");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PORT)).isEqualTo(4711);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("mydatabase");
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionShouldUseUrlOptionsOverProperties() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple://user:password@myhost/mydatabase");
|
||||
properties.setUsername("another-user");
|
||||
properties.setPassword("another-password");
|
||||
properties.setName("another-database");
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("user");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("password");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("mydatabase");
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionShouldUseDatabaseNameOverRandomName() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple://user:password@myhost/mydatabase");
|
||||
properties.setGenerateUniqueName(true);
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("mydatabase");
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionWithRandomNameShouldIgnoreNameFromProperties() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:h2://host");
|
||||
properties.setName("test-database");
|
||||
properties.setGenerateUniqueName(true);
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isNotEqualTo("test-database")
|
||||
.isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionShouldSetCustomDriverProperties() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple://user:password@myhost");
|
||||
properties.getProperties().put("simpleOne", "one");
|
||||
properties.getProperties().put("simpleTwo", "two");
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(Option.<String>valueOf("simpleOne"))).isEqualTo("one");
|
||||
assertThat(options.getRequiredValue(Option.<String>valueOf("simpleTwo"))).isEqualTo("two");
|
||||
}
|
||||
|
||||
@Test
|
||||
void regularConnectionShouldUseBuilderValuesOverProperties() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUrl("r2dbc:simple://user:password@myhost:47111/mydatabase");
|
||||
properties.setUsername("user");
|
||||
properties.setPassword("password");
|
||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder
|
||||
.of(properties, () -> EmbeddedDatabaseConnection.NONE).username("another-user")
|
||||
.password("another-password").hostname("another-host").port(1234).database("another-database")
|
||||
.buildOptions();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("another-user");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("another-password");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.HOST)).isEqualTo("another-host");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PORT)).isEqualTo(1234);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("another-database");
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionIsConfiguredAutomaticallyWithoutUrl() {
|
||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder
|
||||
.of(new R2dbcProperties(), () -> EmbeddedDatabaseConnection.H2).buildOptions();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("sa");
|
||||
assertThat(options.hasOption(ConnectionFactoryOptions.PASSWORD)).isFalse();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("h2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionWithUsernameAndPassword() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setUsername("embedded");
|
||||
properties.setPassword("secret");
|
||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder.of(properties, () -> EmbeddedDatabaseConnection.H2)
|
||||
.buildOptions();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("embedded");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("secret");
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("h2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionUseDefaultDatabaseName() {
|
||||
ConnectionFactoryOptions options = ConnectionFactoryBuilder
|
||||
.of(new R2dbcProperties(), () -> EmbeddedDatabaseConnection.H2).buildOptions();
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("testdb");
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionUseNameIfSet() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setName("test-database");
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo("test-database");
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionCanGenerateUniqueDatabaseName() {
|
||||
R2dbcProperties firstProperties = new R2dbcProperties();
|
||||
firstProperties.setGenerateUniqueName(true);
|
||||
ConnectionFactoryOptions options11 = buildOptions(firstProperties);
|
||||
ConnectionFactoryOptions options12 = buildOptions(firstProperties);
|
||||
assertThat(options11.getRequiredValue(ConnectionFactoryOptions.DATABASE))
|
||||
.isEqualTo(options12.getRequiredValue(ConnectionFactoryOptions.DATABASE));
|
||||
R2dbcProperties secondProperties = new R2dbcProperties();
|
||||
firstProperties.setGenerateUniqueName(true);
|
||||
ConnectionFactoryOptions options21 = buildOptions(secondProperties);
|
||||
ConnectionFactoryOptions options22 = buildOptions(secondProperties);
|
||||
assertThat(options21.getRequiredValue(ConnectionFactoryOptions.DATABASE))
|
||||
.isEqualTo(options22.getRequiredValue(ConnectionFactoryOptions.DATABASE));
|
||||
assertThat(options11.getRequiredValue(ConnectionFactoryOptions.DATABASE))
|
||||
.isNotEqualTo(options21.getRequiredValue(ConnectionFactoryOptions.DATABASE));
|
||||
}
|
||||
|
||||
@Test
|
||||
void embeddedConnectionShouldIgnoreNameIfRandomNameIsRequired() {
|
||||
R2dbcProperties properties = new R2dbcProperties();
|
||||
properties.setGenerateUniqueName(true);
|
||||
properties.setName("test-database");
|
||||
ConnectionFactoryOptions options = buildOptions(properties);
|
||||
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isNotEqualTo("test-database");
|
||||
}
|
||||
|
||||
private ConnectionFactoryOptions buildOptions(R2dbcProperties properties) {
|
||||
return ConnectionFactoryBuilder.of(properties, () -> EmbeddedDatabaseConnection.H2).buildOptions();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue