This commit is contained in:
Phillip Webb 2018-01-03 16:21:29 -08:00
parent a62a27e686
commit 25609c060e
17 changed files with 221 additions and 185 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 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,6 +34,7 @@ import org.springframework.context.ApplicationContext;
* specific extensions for the {@link HealthEndpoint}. * specific extensions for the {@link HealthEndpoint}.
* *
* @author Madhura Bhave * @author Madhura Bhave
* @since 2.0.0
*/ */
public class CloudFoundryWebAnnotationEndpointDiscoverer public class CloudFoundryWebAnnotationEndpointDiscoverer
extends WebAnnotationEndpointDiscoverer { extends WebAnnotationEndpointDiscoverer {

View File

@ -131,8 +131,7 @@ public class MetricsEndpoint {
return availableTags; return availableTags;
} }
private void mergeAvailableTags(Map<String, Set<String>> availableTags, private void mergeAvailableTags(Map<String, Set<String>> availableTags, Meter meter) {
Meter meter) {
meter.getId().getTags().forEach((tag) -> { meter.getId().getTags().forEach((tag) -> {
Set<String> value = Collections.singleton(tag.getValue()); Set<String> value = Collections.singleton(tag.getValue());
availableTags.merge(tag.getKey(), value, this::merge); availableTags.merge(tag.getKey(), value, this::merge);

View File

@ -720,6 +720,11 @@
<artifactId>johnzon-jsonb</artifactId> <artifactId>johnzon-jsonb</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.hsqldb</groupId> <groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId> <artifactId>hsqldb</artifactId>
@ -750,20 +755,15 @@
<artifactId>spring-security-test</artifactId> <artifactId>spring-security-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.testcontainers</groupId> <groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId> <artifactId>testcontainers</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -102,12 +102,14 @@ public class ConcurrentKafkaListenerContainerFactoryConfigurer {
.to(container::setAckTime); .to(container::setAckTime);
map.from(properties::getPollTimeout).whenNonNull().as(Duration::toMillis) map.from(properties::getPollTimeout).whenNonNull().as(Duration::toMillis)
.to(container::setPollTimeout); .to(container::setPollTimeout);
map.from(properties::getNoPollThreshold).whenNonNull().to(container::setNoPollThreshold); map.from(properties::getNoPollThreshold).whenNonNull()
.to(container::setNoPollThreshold);
map.from(properties::getIdleEventInterval).whenNonNull().as(Duration::toMillis) map.from(properties::getIdleEventInterval).whenNonNull().as(Duration::toMillis)
.to(container::setIdleEventInterval); .to(container::setIdleEventInterval);
map.from(properties::getMonitorInterval).whenNonNull().as(Duration::getSeconds) map.from(properties::getMonitorInterval).whenNonNull().as(Duration::getSeconds)
.as(Number::intValue).to(container::setMonitorInterval); .as(Number::intValue).to(container::setMonitorInterval);
map.from(properties::getLogContainerConfig).whenNonNull().to(container::setLogContainerConfig); map.from(properties::getLogContainerConfig).whenNonNull()
.to(container::setLogContainerConfig);
} }
} }

View File

@ -815,7 +815,8 @@ public class KafkaProperties {
private Duration pollTimeout; private Duration pollTimeout;
/** /**
* Multiplier applied to "pollTimeout" to determine if a consumer is non-responsive. * Multiplier applied to "pollTimeout" to determine if a consumer is
* non-responsive.
*/ */
private Float noPollThreshold; private Float noPollThreshold;

View File

@ -23,13 +23,14 @@ import java.util.Map;
* properties before it is used by an auto-configured {@code EntityManagerFactory}. * properties before it is used by an auto-configured {@code EntityManagerFactory}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 2.0.0
*/ */
@FunctionalInterface @FunctionalInterface
public interface HibernatePropertiesCustomizer { public interface HibernatePropertiesCustomizer {
/** /**
* Customize the specified JPA vendor properties. * Customize the specified JPA vendor properties.
* @param hibernateProperties the current JPA vendor properties * @param hibernateProperties the JPA vendor properties to customize
*/ */
void customize(Map<String, Object> hibernateProperties); void customize(Map<String, Object> hibernateProperties);

View File

@ -69,8 +69,8 @@ public class HibernateSettings {
public HibernateSettings hibernatePropertiesCustomizers( public HibernateSettings hibernatePropertiesCustomizers(
Collection<HibernatePropertiesCustomizer> hibernatePropertiesCustomizers) { Collection<HibernatePropertiesCustomizer> hibernatePropertiesCustomizers) {
this.hibernatePropertiesCustomizers = new ArrayList<>(); this.hibernatePropertiesCustomizers = new ArrayList<>(
this.hibernatePropertiesCustomizers.addAll(hibernatePropertiesCustomizers); hibernatePropertiesCustomizers);
return this; return this;
} }

View File

@ -224,11 +224,10 @@ public class JpaProperties {
else { else {
result.remove("hibernate.hbm2ddl.auto"); result.remove("hibernate.hbm2ddl.auto");
} }
Collection<HibernatePropertiesCustomizer> hibernatePropertiesCustomizers = Collection<HibernatePropertiesCustomizer> customizers = settings
settings.getHibernatePropertiesCustomizers(); .getHibernatePropertiesCustomizers();
if (!ObjectUtils.isEmpty(hibernatePropertiesCustomizers)) { if (!ObjectUtils.isEmpty(customizers)) {
hibernatePropertiesCustomizers.forEach((customizer) customizers.forEach((customizer) -> customizer.customize(result));
-> customizer.customize(result));
} }
return result; return result;
} }

View File

@ -299,13 +299,17 @@ public class KafkaAutoConfigurationTests {
assertThat(dfa.getPropertyValue("concurrency")).isEqualTo(3); assertThat(dfa.getPropertyValue("concurrency")).isEqualTo(3);
assertThat(dfa.getPropertyValue("containerProperties.pollTimeout")) assertThat(dfa.getPropertyValue("containerProperties.pollTimeout"))
.isEqualTo(2000L); .isEqualTo(2000L);
assertThat(dfa.getPropertyValue("containerProperties.noPollThreshold")) assertThat(
dfa.getPropertyValue("containerProperties.noPollThreshold"))
.isEqualTo(2.5f); .isEqualTo(2.5f);
assertThat(dfa.getPropertyValue("containerProperties.idleEventInterval")) assertThat(
dfa.getPropertyValue("containerProperties.idleEventInterval"))
.isEqualTo(1000L); .isEqualTo(1000L);
assertThat(dfa.getPropertyValue("containerProperties.monitorInterval")) assertThat(
dfa.getPropertyValue("containerProperties.monitorInterval"))
.isEqualTo(45); .isEqualTo(45);
assertThat(dfa.getPropertyValue("containerProperties.logContainerConfig")) assertThat(dfa
.getPropertyValue("containerProperties.logContainerConfig"))
.isEqualTo(Boolean.TRUE); .isEqualTo(Boolean.TRUE);
assertThat(dfa.getPropertyValue("batchListener")).isEqualTo(true); assertThat(dfa.getPropertyValue("batchListener")).isEqualTo(true);
assertThat( assertThat(

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 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.
@ -43,25 +43,25 @@ public class MongoAutoConfigurationTests {
@Test @Test
public void clientExists() { public void clientExists() {
this.contextRunner.run((context) -> this.contextRunner
assertThat(context).hasSingleBean(MongoClient.class)); .run((context) -> assertThat(context).hasSingleBean(MongoClient.class));
} }
@Test @Test
public void optionsAdded() { public void optionsAdded() {
this.contextRunner.withPropertyValues("spring.data.mongodb.host:localhost") this.contextRunner.withPropertyValues("spring.data.mongodb.host:localhost")
.withUserConfiguration(OptionsConfig.class).run((context) -> .withUserConfiguration(OptionsConfig.class)
assertThat(context.getBean(MongoClient.class).getMongoClientOptions() .run((context) -> assertThat(context.getBean(MongoClient.class)
.getSocketTimeout()).isEqualTo(300)); .getMongoClientOptions().getSocketTimeout()).isEqualTo(300));
} }
@Test @Test
public void optionsAddedButNoHost() { public void optionsAddedButNoHost() {
this.contextRunner this.contextRunner
.withPropertyValues("spring.data.mongodb.uri:mongodb://localhost/test") .withPropertyValues("spring.data.mongodb.uri:mongodb://localhost/test")
.withUserConfiguration(OptionsConfig.class).run((context) -> .withUserConfiguration(OptionsConfig.class)
assertThat(context.getBean(MongoClient.class).getMongoClientOptions() .run((context) -> assertThat(context.getBean(MongoClient.class)
.getSocketTimeout()).isEqualTo(300)); .getMongoClientOptions().getSocketTimeout()).isEqualTo(300));
} }
@Test @Test

View File

@ -77,13 +77,16 @@ public class JpaPropertiesTests {
this.contextRunner this.contextRunner
.withPropertyValues( .withPropertyValues(
"spring.jpa.hibernate.naming.implicit-strategy:com.example.Implicit", "spring.jpa.hibernate.naming.implicit-strategy:com.example.Implicit",
"spring.jpa.hibernate.naming.physical-strategy:com.example.Physical" "spring.jpa.hibernate.naming.physical-strategy:com.example.Physical")
).run(assertJpaProperties((properties) -> { .run(assertJpaProperties((properties) -> {
Map<String, Object> hibernateProperties = properties Map<String, Object> hibernateProperties = properties
.getHibernateProperties(new HibernateSettings().ddlAuto("none")); .getHibernateProperties(
new HibernateSettings().ddlAuto("none"));
assertThat(hibernateProperties).contains( assertThat(hibernateProperties).contains(
entry("hibernate.implicit_naming_strategy", "com.example.Implicit"), entry("hibernate.implicit_naming_strategy",
entry("hibernate.physical_naming_strategy", "com.example.Physical")); "com.example.Implicit"),
entry("hibernate.physical_naming_strategy",
"com.example.Physical"));
assertThat(hibernateProperties) assertThat(hibernateProperties)
.doesNotContainKeys("hibernate.ejb.naming_strategy"); .doesNotContainKeys("hibernate.ejb.naming_strategy");
})); }));
@ -111,32 +114,37 @@ public class JpaPropertiesTests {
this.contextRunner this.contextRunner
.withPropertyValues( .withPropertyValues(
"spring.jpa.hibernate.naming.implicit-strategy:com.example.Implicit", "spring.jpa.hibernate.naming.implicit-strategy:com.example.Implicit",
"spring.jpa.hibernate.naming.physical-strategy:com.example.Physical" "spring.jpa.hibernate.naming.physical-strategy:com.example.Physical")
).run(assertJpaProperties((properties) -> { .run(assertJpaProperties((properties) -> {
ImplicitNamingStrategy implicitStrategy = mock(ImplicitNamingStrategy.class); ImplicitNamingStrategy implicitStrategy = mock(
PhysicalNamingStrategy physicalStrategy = mock(PhysicalNamingStrategy.class); ImplicitNamingStrategy.class);
PhysicalNamingStrategy physicalStrategy = mock(
PhysicalNamingStrategy.class);
Map<String, Object> hibernateProperties = properties Map<String, Object> hibernateProperties = properties
.getHibernateProperties(new HibernateSettings().ddlAuto("none") .getHibernateProperties(
new HibernateSettings().ddlAuto("none")
.implicitNamingStrategy(implicitStrategy) .implicitNamingStrategy(implicitStrategy)
.physicalNamingStrategy(physicalStrategy)); .physicalNamingStrategy(physicalStrategy));
assertThat(hibernateProperties).contains( assertThat(hibernateProperties).contains(
entry("hibernate.implicit_naming_strategy", implicitStrategy), entry("hibernate.implicit_naming_strategy", implicitStrategy),
entry("hibernate.physical_naming_strategy", physicalStrategy)); entry("hibernate.physical_naming_strategy",
physicalStrategy));
assertThat(hibernateProperties) assertThat(hibernateProperties)
.doesNotContainKeys("hibernate.ejb.naming_strategy"); .doesNotContainKeys("hibernate.ejb.naming_strategy");
})); }));
} }
@Test @Test
public void hibernatePropertiesCustomizerTakePrecedenceOverStrategyInstancesAndNamingStrategyProperties() { public void hibernatePropertiesCustomizerTakePrecedenceOverStrategyInstancesAndNamingStrategyProperties() {
this.contextRunner this.contextRunner
.withPropertyValues( .withPropertyValues(
"spring.jpa.hibernate.naming.implicit-strategy:com.example.Implicit", "spring.jpa.hibernate.naming.implicit-strategy:com.example.Implicit",
"spring.jpa.hibernate.naming.physical-strategy:com.example.Physical" "spring.jpa.hibernate.naming.physical-strategy:com.example.Physical")
).run(assertJpaProperties((properties) -> { .run(assertJpaProperties((properties) -> {
ImplicitNamingStrategy implicitStrategy = mock(ImplicitNamingStrategy.class); ImplicitNamingStrategy implicitStrategy = mock(
PhysicalNamingStrategy physicalStrategy = mock(PhysicalNamingStrategy.class); ImplicitNamingStrategy.class);
PhysicalNamingStrategy physicalStrategy = mock(
PhysicalNamingStrategy.class);
ImplicitNamingStrategy effectiveImplicitStrategy = mock( ImplicitNamingStrategy effectiveImplicitStrategy = mock(
ImplicitNamingStrategy.class); ImplicitNamingStrategy.class);
PhysicalNamingStrategy effectivePhysicalStrategy = mock( PhysicalNamingStrategy effectivePhysicalStrategy = mock(
@ -148,14 +156,17 @@ public class JpaPropertiesTests {
effectivePhysicalStrategy); effectivePhysicalStrategy);
}; };
Map<String, Object> hibernateProperties = properties Map<String, Object> hibernateProperties = properties
.getHibernateProperties(new HibernateSettings().ddlAuto("none") .getHibernateProperties(
new HibernateSettings().ddlAuto("none")
.implicitNamingStrategy(implicitStrategy) .implicitNamingStrategy(implicitStrategy)
.physicalNamingStrategy(physicalStrategy) .physicalNamingStrategy(physicalStrategy)
.hibernatePropertiesCustomizers( .hibernatePropertiesCustomizers(
Collections.singleton(customizer))); Collections.singleton(customizer)));
assertThat(hibernateProperties).contains( assertThat(hibernateProperties).contains(
entry("hibernate.implicit_naming_strategy", effectiveImplicitStrategy), entry("hibernate.implicit_naming_strategy",
entry("hibernate.physical_naming_strategy", effectivePhysicalStrategy)); effectiveImplicitStrategy),
entry("hibernate.physical_naming_strategy",
effectivePhysicalStrategy));
assertThat(hibernateProperties) assertThat(hibernateProperties)
.doesNotContainKeys("hibernate.ejb.naming_strategy"); .doesNotContainKeys("hibernate.ejb.naming_strategy");
})); }));
@ -166,14 +177,17 @@ public class JpaPropertiesTests {
this.contextRunner this.contextRunner
.withPropertyValues( .withPropertyValues(
"spring.jpa.properties.hibernate.implicit_naming_strategy:com.example.Implicit", "spring.jpa.properties.hibernate.implicit_naming_strategy:com.example.Implicit",
"spring.jpa.properties.hibernate.physical_naming_strategy:com.example.Physical" "spring.jpa.properties.hibernate.physical_naming_strategy:com.example.Physical")
).run(assertJpaProperties((properties) -> { .run(assertJpaProperties((properties) -> {
Map<String, Object> hibernateProperties = properties Map<String, Object> hibernateProperties = properties
.getHibernateProperties(new HibernateSettings().ddlAuto("none")); .getHibernateProperties(
new HibernateSettings().ddlAuto("none"));
// You can override them as we don't provide any default // You can override them as we don't provide any default
assertThat(hibernateProperties).contains( assertThat(hibernateProperties).contains(
entry("hibernate.implicit_naming_strategy", "com.example.Implicit"), entry("hibernate.implicit_naming_strategy",
entry("hibernate.physical_naming_strategy", "com.example.Physical")); "com.example.Implicit"),
entry("hibernate.physical_naming_strategy",
"com.example.Physical"));
assertThat(hibernateProperties) assertThat(hibernateProperties)
.doesNotContainKeys("hibernate.ejb.naming_strategy"); .doesNotContainKeys("hibernate.ejb.naming_strategy");
})); }));
@ -184,8 +198,8 @@ public class JpaPropertiesTests {
this.contextRunner.run(assertJpaProperties((properties) -> { this.contextRunner.run(assertJpaProperties((properties) -> {
Map<String, Object> hibernateProperties = properties Map<String, Object> hibernateProperties = properties
.getHibernateProperties(new HibernateSettings().ddlAuto("none")); .getHibernateProperties(new HibernateSettings().ddlAuto("none"));
assertThat(hibernateProperties) assertThat(hibernateProperties).containsEntry(
.containsEntry(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true"); AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "true");
})); }));
} }
@ -193,19 +207,19 @@ public class JpaPropertiesTests {
public void useNewIdGeneratorMappingsFalse() { public void useNewIdGeneratorMappingsFalse() {
this.contextRunner this.contextRunner
.withPropertyValues( .withPropertyValues(
"spring.jpa.hibernate.use-new-id-generator-mappings:false" "spring.jpa.hibernate.use-new-id-generator-mappings:false")
).run(assertJpaProperties((properties) -> { .run(assertJpaProperties((properties) -> {
Map<String, Object> hibernateProperties = properties Map<String, Object> hibernateProperties = properties
.getHibernateProperties(new HibernateSettings().ddlAuto("none")); .getHibernateProperties(
assertThat(hibernateProperties) new HibernateSettings().ddlAuto("none"));
.containsEntry(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false"); assertThat(hibernateProperties).containsEntry(
AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, "false");
})); }));
} }
@Test @Test
public void determineDatabaseNoCheckIfDatabaseIsSet() { public void determineDatabaseNoCheckIfDatabaseIsSet() {
this.contextRunner this.contextRunner.withPropertyValues("spring.jpa.database=postgresql")
.withPropertyValues("spring.jpa.database=postgresql")
.run(assertJpaProperties((properties) -> { .run(assertJpaProperties((properties) -> {
DataSource dataSource = mockStandaloneDataSource(); DataSource dataSource = mockStandaloneDataSource();
Database database = properties.determineDatabase(dataSource); Database database = properties.determineDatabase(dataSource);
@ -230,8 +244,7 @@ public class JpaPropertiesTests {
@Test @Test
public void determineDatabaseWithKnownUrlAndUserConfig() { public void determineDatabaseWithKnownUrlAndUserConfig() {
this.contextRunner this.contextRunner.withPropertyValues("spring.jpa.database=mysql")
.withPropertyValues("spring.jpa.database=mysql")
.run(assertJpaProperties((properties) -> { .run(assertJpaProperties((properties) -> {
Database database = properties Database database = properties
.determineDatabase(mockDataSource("jdbc:h2:mem:testdb")); .determineDatabase(mockDataSource("jdbc:h2:mem:testdb"));

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -183,6 +184,11 @@
<artifactId>unboundid-ldapsdk</artifactId> <artifactId>unboundid-ldapsdk</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>io.lettuce</groupId> <groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId> <artifactId>lettuce-core</artifactId>
@ -203,11 +209,21 @@
<artifactId>commons-pool2</artifactId> <artifactId>commons-pool2</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jsonb</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.apache.tomcat.embed</groupId> <groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId> <artifactId>tomcat-embed-core</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.aspectj</groupId> <groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId> <artifactId>aspectjrt</artifactId>
@ -218,6 +234,11 @@
<artifactId>aspectjweaver</artifactId> <artifactId>aspectjweaver</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.hsqldb</groupId> <groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId> <artifactId>hsqldb</artifactId>
@ -228,11 +249,6 @@
<artifactId>jooq</artifactId> <artifactId>jooq</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jsonb</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.mongodb</groupId> <groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-async</artifactId> <artifactId>mongodb-driver-async</artifactId>
@ -258,21 +274,6 @@
<artifactId>spring-plugin-core</artifactId> <artifactId>spring-plugin-core</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.testcontainers</groupId> <groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId> <artifactId>testcontainers</artifactId>

View File

@ -87,7 +87,8 @@ public class DataNeo4jTestIntegrationTests {
public void initialize( public void initialize(
ConfigurableApplicationContext configurableApplicationContext) { ConfigurableApplicationContext configurableApplicationContext) {
TestPropertyValues TestPropertyValues
.of("spring.data.neo4j.uri=bolt://localhost:" + neo4j.getMappedPort(7687)) .of("spring.data.neo4j.uri=bolt://localhost:"
+ neo4j.getMappedPort(7687))
.applyTo(configurableApplicationContext.getEnvironment()); .applyTo(configurableApplicationContext.getEnvironment());
} }

View File

@ -146,9 +146,10 @@ public class RestTemplateBuilder {
*/ */
public RestTemplateBuilder detectRequestFactory(boolean detectRequestFactory) { public RestTemplateBuilder detectRequestFactory(boolean detectRequestFactory) {
return new RestTemplateBuilder(detectRequestFactory, this.rootUri, return new RestTemplateBuilder(detectRequestFactory, this.rootUri,
this.messageConverters, this.requestFactorySupplier, this.uriTemplateHandler, this.messageConverters, this.requestFactorySupplier,
this.errorHandler, this.basicAuthorization, this.restTemplateCustomizers, this.uriTemplateHandler, this.errorHandler, this.basicAuthorization,
this.requestFactoryCustomizers, this.interceptors); this.restTemplateCustomizers, this.requestFactoryCustomizers,
this.interceptors);
} }
/** /**
@ -159,9 +160,10 @@ public class RestTemplateBuilder {
*/ */
public RestTemplateBuilder rootUri(String rootUri) { public RestTemplateBuilder rootUri(String rootUri) {
return new RestTemplateBuilder(this.detectRequestFactory, rootUri, return new RestTemplateBuilder(this.detectRequestFactory, rootUri,
this.messageConverters, this.requestFactorySupplier, this.uriTemplateHandler, this.messageConverters, this.requestFactorySupplier,
this.errorHandler, this.basicAuthorization, this.restTemplateCustomizers, this.uriTemplateHandler, this.errorHandler, this.basicAuthorization,
this.requestFactoryCustomizers, this.interceptors); this.restTemplateCustomizers, this.requestFactoryCustomizers,
this.interceptors);
} }
/** /**
@ -221,10 +223,10 @@ public class RestTemplateBuilder {
Collection<? extends HttpMessageConverter<?>> messageConverters) { Collection<? extends HttpMessageConverter<?>> messageConverters) {
Assert.notNull(messageConverters, "MessageConverters must not be null"); Assert.notNull(messageConverters, "MessageConverters must not be null");
return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri, return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri,
append(this.messageConverters, messageConverters), this.requestFactorySupplier, append(this.messageConverters, messageConverters),
this.uriTemplateHandler, this.errorHandler, this.basicAuthorization, this.requestFactorySupplier, this.uriTemplateHandler, this.errorHandler,
this.restTemplateCustomizers, this.requestFactoryCustomizers, this.basicAuthorization, this.restTemplateCustomizers,
this.interceptors); this.requestFactoryCustomizers, this.interceptors);
} }
/** /**
@ -271,9 +273,9 @@ public class RestTemplateBuilder {
Collection<ClientHttpRequestInterceptor> interceptors) { Collection<ClientHttpRequestInterceptor> interceptors) {
Assert.notNull(interceptors, "interceptors must not be null"); Assert.notNull(interceptors, "interceptors must not be null");
return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri, return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri,
this.messageConverters, this.requestFactorySupplier, this.uriTemplateHandler, this.messageConverters, this.requestFactorySupplier,
this.errorHandler, this.basicAuthorization, this.restTemplateCustomizers, this.uriTemplateHandler, this.errorHandler, this.basicAuthorization,
this.requestFactoryCustomizers, this.restTemplateCustomizers, this.requestFactoryCustomizers,
Collections.unmodifiableSet(new LinkedHashSet<>(interceptors))); Collections.unmodifiableSet(new LinkedHashSet<>(interceptors)));
} }
@ -303,9 +305,10 @@ public class RestTemplateBuilder {
Collection<? extends ClientHttpRequestInterceptor> interceptors) { Collection<? extends ClientHttpRequestInterceptor> interceptors) {
Assert.notNull(interceptors, "interceptors must not be null"); Assert.notNull(interceptors, "interceptors must not be null");
return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri, return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri,
this.messageConverters, this.requestFactorySupplier, this.uriTemplateHandler, this.messageConverters, this.requestFactorySupplier,
this.errorHandler, this.basicAuthorization, this.restTemplateCustomizers, this.uriTemplateHandler, this.errorHandler, this.basicAuthorization,
this.requestFactoryCustomizers, append(this.interceptors, interceptors)); this.restTemplateCustomizers, this.requestFactoryCustomizers,
append(this.interceptors, interceptors));
} }
/** /**
@ -333,15 +336,16 @@ public class RestTemplateBuilder {
} }
/** /**
* Set the {@code Supplier} of {@link ClientHttpRequestFactory} * Set the {@code Supplier} of {@link ClientHttpRequestFactory} that should be called
* that should be called each time we {@link #build()} a new * each time we {@link #build()} a new {@link RestTemplate} instance.
* {@link RestTemplate} instance.
* @param requestFactorySupplier the supplier for the request factory * @param requestFactorySupplier the supplier for the request factory
* @return a new builder instance * @return a new builder instance
* @since 2.0.0 * @since 2.0.0
*/ */
public RestTemplateBuilder requestFactory(Supplier<ClientHttpRequestFactory> requestFactorySupplier) { public RestTemplateBuilder requestFactory(
Assert.notNull(requestFactorySupplier, "RequestFactory Supplier must not be null"); Supplier<ClientHttpRequestFactory> requestFactorySupplier) {
Assert.notNull(requestFactorySupplier,
"RequestFactory Supplier must not be null");
return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri, return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri,
this.messageConverters, requestFactorySupplier, this.uriTemplateHandler, this.messageConverters, requestFactorySupplier, this.uriTemplateHandler,
this.errorHandler, this.basicAuthorization, this.restTemplateCustomizers, this.errorHandler, this.basicAuthorization, this.restTemplateCustomizers,
@ -371,9 +375,10 @@ public class RestTemplateBuilder {
public RestTemplateBuilder errorHandler(ResponseErrorHandler errorHandler) { public RestTemplateBuilder errorHandler(ResponseErrorHandler errorHandler) {
Assert.notNull(errorHandler, "ErrorHandler must not be null"); Assert.notNull(errorHandler, "ErrorHandler must not be null");
return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri, return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri,
this.messageConverters, this.requestFactorySupplier, this.uriTemplateHandler, this.messageConverters, this.requestFactorySupplier,
errorHandler, this.basicAuthorization, this.restTemplateCustomizers, this.uriTemplateHandler, errorHandler, this.basicAuthorization,
this.requestFactoryCustomizers, this.interceptors); this.restTemplateCustomizers, this.requestFactoryCustomizers,
this.interceptors);
} }
/** /**
@ -385,8 +390,9 @@ public class RestTemplateBuilder {
*/ */
public RestTemplateBuilder basicAuthorization(String username, String password) { public RestTemplateBuilder basicAuthorization(String username, String password) {
return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri, return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri,
this.messageConverters, this.requestFactorySupplier, this.uriTemplateHandler, this.messageConverters, this.requestFactorySupplier,
this.errorHandler, new BasicAuthorizationInterceptor(username, password), this.uriTemplateHandler, this.errorHandler,
new BasicAuthorizationInterceptor(username, password),
this.restTemplateCustomizers, this.requestFactoryCustomizers, this.restTemplateCustomizers, this.requestFactoryCustomizers,
this.interceptors); this.interceptors);
} }
@ -421,8 +427,8 @@ public class RestTemplateBuilder {
Assert.notNull(restTemplateCustomizers, Assert.notNull(restTemplateCustomizers,
"RestTemplateCustomizers must not be null"); "RestTemplateCustomizers must not be null");
return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri, return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri,
this.messageConverters, this.requestFactorySupplier, this.uriTemplateHandler, this.messageConverters, this.requestFactorySupplier,
this.errorHandler, this.basicAuthorization, this.uriTemplateHandler, this.errorHandler, this.basicAuthorization,
Collections.unmodifiableSet(new LinkedHashSet<RestTemplateCustomizer>( Collections.unmodifiableSet(new LinkedHashSet<RestTemplateCustomizer>(
restTemplateCustomizers)), restTemplateCustomizers)),
this.requestFactoryCustomizers, this.interceptors); this.requestFactoryCustomizers, this.interceptors);
@ -455,8 +461,8 @@ public class RestTemplateBuilder {
Collection<? extends RestTemplateCustomizer> customizers) { Collection<? extends RestTemplateCustomizer> customizers) {
Assert.notNull(customizers, "RestTemplateCustomizers must not be null"); Assert.notNull(customizers, "RestTemplateCustomizers must not be null");
return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri, return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri,
this.messageConverters, this.requestFactorySupplier, this.uriTemplateHandler, this.messageConverters, this.requestFactorySupplier,
this.errorHandler, this.basicAuthorization, this.uriTemplateHandler, this.errorHandler, this.basicAuthorization,
append(this.restTemplateCustomizers, customizers), append(this.restTemplateCustomizers, customizers),
this.requestFactoryCustomizers, this.interceptors); this.requestFactoryCustomizers, this.interceptors);
} }
@ -469,8 +475,9 @@ public class RestTemplateBuilder {
*/ */
public RestTemplateBuilder setConnectTimeout(int connectTimeout) { public RestTemplateBuilder setConnectTimeout(int connectTimeout) {
return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri, return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri,
this.messageConverters, this.requestFactorySupplier, this.uriTemplateHandler, this.messageConverters, this.requestFactorySupplier,
this.errorHandler, this.basicAuthorization, this.restTemplateCustomizers, this.uriTemplateHandler, this.errorHandler, this.basicAuthorization,
this.restTemplateCustomizers,
append(this.requestFactoryCustomizers, append(this.requestFactoryCustomizers,
new ConnectTimeoutRequestFactoryCustomizer(connectTimeout)), new ConnectTimeoutRequestFactoryCustomizer(connectTimeout)),
this.interceptors); this.interceptors);
@ -484,8 +491,9 @@ public class RestTemplateBuilder {
*/ */
public RestTemplateBuilder setReadTimeout(int readTimeout) { public RestTemplateBuilder setReadTimeout(int readTimeout) {
return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri, return new RestTemplateBuilder(this.detectRequestFactory, this.rootUri,
this.messageConverters, this.requestFactorySupplier, this.uriTemplateHandler, this.messageConverters, this.requestFactorySupplier,
this.errorHandler, this.basicAuthorization, this.restTemplateCustomizers, this.uriTemplateHandler, this.errorHandler, this.basicAuthorization,
this.restTemplateCustomizers,
append(this.requestFactoryCustomizers, append(this.requestFactoryCustomizers,
new ReadTimeoutRequestFactoryCustomizer(readTimeout)), new ReadTimeoutRequestFactoryCustomizer(readTimeout)),
this.interceptors); this.interceptors);

View File

@ -123,7 +123,8 @@ public class FailureAnalyzersTests {
} }
interface AwareFailureAnalyzer extends BeanFactoryAware, EnvironmentAware, FailureAnalyzer { interface AwareFailureAnalyzer
extends BeanFactoryAware, EnvironmentAware, FailureAnalyzer {
} }

View File

@ -467,7 +467,9 @@ public class RestTemplateBuilderTests {
@Test @Test
public void connectTimeoutCanBeConfiguredOnAWrappedRequestFactory() { public void connectTimeoutCanBeConfiguredOnAWrappedRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)) this.builder
.requestFactory(
() -> new BufferingClientHttpRequestFactory(requestFactory))
.setConnectTimeout(1234).build(); .setConnectTimeout(1234).build();
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout")) assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout"))
.isEqualTo(1234); .isEqualTo(1234);
@ -476,7 +478,9 @@ public class RestTemplateBuilderTests {
@Test @Test
public void readTimeoutCanBeConfiguredOnAWrappedRequestFactory() { public void readTimeoutCanBeConfiguredOnAWrappedRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)) this.builder
.requestFactory(
() -> new BufferingClientHttpRequestFactory(requestFactory))
.setReadTimeout(1234).build(); .setReadTimeout(1234).build();
assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout")) assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout"))
.isEqualTo(1234); .isEqualTo(1234);
@ -486,7 +490,8 @@ public class RestTemplateBuilderTests {
public void unwrappingDoesNotAffectRequestFactoryThatIsSetOnTheBuiltTemplate() { public void unwrappingDoesNotAffectRequestFactoryThatIsSetOnTheBuiltTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
RestTemplate template = this.builder RestTemplate template = this.builder
.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)) .requestFactory(
() -> new BufferingClientHttpRequestFactory(requestFactory))
.build(); .build();
assertThat(template.getRequestFactory()) assertThat(template.getRequestFactory())
.isInstanceOf(BufferingClientHttpRequestFactory.class); .isInstanceOf(BufferingClientHttpRequestFactory.class);