This commit is contained in:
Phillip Webb
2017-06-02 16:00:24 -07:00
parent 8f7004738b
commit 2c7dd9f519
45 changed files with 200 additions and 166 deletions

View File

@@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
import org.springframework.boot.autoconfigure.data.web.SpringDataWebProperties.Pageable;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -62,20 +63,19 @@ public class SpringDataWebAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public PageableHandlerMethodArgumentResolverCustomizer pageableCustomizer() {
return pageableResolver -> {
pageableResolver.setFallbackPageable(PageRequest.of(0,
this.properties.getPageable().getDefaultPageSize()));
pageableResolver.setPageParameterName(
this.properties.getPageable().getPageParameter());
pageableResolver.setSizeParameterName(
this.properties.getPageable().getSizeParameter());
return (resolver) -> {
Pageable pageable = this.properties.getPageable();
resolver.setFallbackPageable(
PageRequest.of(0, pageable.getDefaultPageSize()));
resolver.setPageParameterName(pageable.getPageParameter());
resolver.setSizeParameterName(pageable.getSizeParameter());
};
}
@Bean
@ConditionalOnMissingBean
public SortHandlerMethodArgumentResolverCustomizer sortCustomizer() {
return sortResolver -> sortResolver
return (resolver) -> resolver
.setSortParameter(this.properties.getSort().getSortParameter());
}

View File

@@ -54,10 +54,8 @@ public class InfluxDbAutoConfiguration {
if (Strings.isNullOrEmpty(client.getUser())) {
return InfluxDBFactory.connect(client.getUrl());
}
else {
return InfluxDBFactory.connect(client.getUrl(), client.getUser(),
client.getPassword());
}
return InfluxDBFactory.connect(client.getUrl(), client.getUser(),
client.getPassword());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -84,7 +84,8 @@ public class JdbcTemplateAutoConfiguration {
@Primary
@ConditionalOnSingleCandidate(JdbcTemplate.class)
@ConditionalOnMissingBean(NamedParameterJdbcOperations.class)
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(JdbcTemplate jdbcTemplate) {
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(
JdbcTemplate jdbcTemplate) {
return new NamedParameterJdbcTemplate(jdbcTemplate);
}

View File

@@ -33,7 +33,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class JooqProperties {
/**
* Sql dialect to use, auto-detected by default.
* SQL dialect to use, auto-detected by default.
*/
private SQLDialect sqlDialect;

View File

@@ -34,6 +34,7 @@ import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoClients;
import org.springframework.core.env.Environment;
import org.springframework.util.Assert;
/**
* A factory for a reactive {@link MongoClient} that applies {@link MongoProperties}.
@@ -96,67 +97,88 @@ public class ReactiveMongoClientFactory {
private MongoClient createNetworkMongoClient(MongoClientSettings settings) {
if (hasCustomAddress() || hasCustomCredentials()) {
if (this.properties.getUri() != null) {
throw new IllegalStateException("Invalid mongo configuration, "
+ "either uri or host/port/credentials must be specified");
}
Builder builder = builder(settings);
if (hasCustomCredentials()) {
List<MongoCredential> credentials = new ArrayList<>();
String database = this.properties.getAuthenticationDatabase() == null
? this.properties.getMongoClientDatabase()
: this.properties.getAuthenticationDatabase();
credentials.add(
MongoCredential.createCredential(this.properties.getUsername(),
database, this.properties.getPassword()));
builder.credentialList(credentials);
}
String host = this.properties.getHost() == null ? "localhost"
: this.properties.getHost();
int port = this.properties.getPort() != null ? this.properties.getPort()
: MongoProperties.DEFAULT_PORT;
ClusterSettings clusterSettings = ClusterSettings.builder()
.hosts(Collections.singletonList(new ServerAddress(host, port)))
.build();
builder.clusterSettings(clusterSettings);
return MongoClients.create(builder.build());
return createCredentialNetworkMongoClient(settings);
}
ConnectionString connectionString = new ConnectionString(
this.properties.determineUri());
return MongoClients.create(createBuilder(settings, connectionString).build());
}
private MongoClient createCredentialNetworkMongoClient(MongoClientSettings settings) {
Assert.state(this.properties.getUri() == null, "Invalid mongo configuration, "
+ "either uri or host/port/credentials must be specified");
Builder builder = builder(settings);
if (hasCustomCredentials()) {
applyCredentials(builder);
}
String host = getOrDefault(this.properties.getHost(), "localhost");
int port = getOrDefault(this.properties.getPort(), MongoProperties.DEFAULT_PORT);
ServerAddress serverAddress = new ServerAddress(host, port);
builder.clusterSettings(ClusterSettings.builder()
.hosts(Collections.singletonList(serverAddress)).build());
return MongoClients.create(builder.build());
}
private void applyCredentials(Builder builder) {
List<MongoCredential> credentials = new ArrayList<>();
String database = this.properties.getAuthenticationDatabase() == null
? this.properties.getMongoClientDatabase()
: this.properties.getAuthenticationDatabase();
credentials.add(MongoCredential.createCredential(this.properties.getUsername(),
database, this.properties.getPassword()));
builder.credentialList(credentials);
}
private <T> T getOrDefault(T value, T defaultValue) {
return (value == null ? defaultValue : value);
}
private Builder createBuilder(MongoClientSettings settings,
ConnectionString connectionString) {
Builder builder = builder(settings)
.clusterSettings(ClusterSettings.builder()
.applyConnectionString(connectionString).build())
.connectionPoolSettings(ConnectionPoolSettings.builder()
.applyConnectionString(connectionString).build())
.serverSettings(ServerSettings.builder()
.applyConnectionString(connectionString).build())
.credentialList(connectionString.getCredentialList())
.sslSettings(SslSettings.builder().applyConnectionString(connectionString)
.build())
.socketSettings(SocketSettings.builder()
.applyConnectionString(connectionString).build());
if (connectionString.getReadPreference() != null) {
builder.readPreference(connectionString.getReadPreference());
ConnectionString connection) {
Builder builder = builder(settings);
builder.clusterSettings(getClusterSettings(connection));
builder.connectionPoolSettings(getConnectionPoolSettings(connection));
builder.serverSettings(getServerSettings(connection));
builder.credentialList(connection.getCredentialList());
builder.sslSettings(getSslSettings(connection));
builder.socketSettings(getSocketSettings(connection));
if (connection.getReadPreference() != null) {
builder.readPreference(connection.getReadPreference());
}
if (connectionString.getReadConcern() != null) {
builder.readConcern(connectionString.getReadConcern());
if (connection.getReadConcern() != null) {
builder.readConcern(connection.getReadConcern());
}
if (connectionString.getWriteConcern() != null) {
builder.writeConcern(connectionString.getWriteConcern());
if (connection.getWriteConcern() != null) {
builder.writeConcern(connection.getWriteConcern());
}
if (connectionString.getApplicationName() != null) {
builder.applicationName(connectionString.getApplicationName());
if (connection.getApplicationName() != null) {
builder.applicationName(connection.getApplicationName());
}
customize(builder);
return builder;
}
private ClusterSettings getClusterSettings(ConnectionString connection) {
return ClusterSettings.builder().applyConnectionString(connection).build();
}
private ConnectionPoolSettings getConnectionPoolSettings(
ConnectionString connection) {
return ConnectionPoolSettings.builder().applyConnectionString(connection).build();
}
private ServerSettings getServerSettings(ConnectionString connection) {
return ServerSettings.builder().applyConnectionString(connection).build();
}
private SslSettings getSslSettings(ConnectionString connection) {
return SslSettings.builder().applyConnectionString(connection).build();
}
private SocketSettings getSocketSettings(ConnectionString connection) {
return SocketSettings.builder().applyConnectionString(connection).build();
}
private void customize(MongoClientSettings.Builder builder) {
for (MongoClientSettingsBuilderCustomizer customizer : this.builderCustomizers) {
customizer.customize(builder);
@@ -176,7 +198,6 @@ public class ReactiveMongoClientFactory {
if (settings == null) {
return MongoClientSettings.builder();
}
return MongoClientSettings.builder(settings);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -56,8 +56,7 @@ public class ElasticsearchDataAutoConfigurationTests {
ElasticsearchAutoConfiguration.class,
ElasticsearchDataAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBeanNamesForType(ElasticsearchTemplate.class))
.hasSize(1);
asssertHasSingleBean(ElasticsearchTemplate.class);
}
@Test
@@ -71,9 +70,7 @@ public class ElasticsearchDataAutoConfigurationTests {
ElasticsearchAutoConfiguration.class,
ElasticsearchDataAutoConfiguration.class);
this.context.refresh();
assertThat(
this.context.getBeanNamesForType(SimpleElasticsearchMappingContext.class))
.hasSize(1);
asssertHasSingleBean(SimpleElasticsearchMappingContext.class);
}
@Test
@@ -87,8 +84,11 @@ public class ElasticsearchDataAutoConfigurationTests {
ElasticsearchAutoConfiguration.class,
ElasticsearchDataAutoConfiguration.class);
this.context.refresh();
assertThat(this.context.getBeanNamesForType(ElasticsearchConverter.class))
.hasSize(1);
asssertHasSingleBean(ElasticsearchConverter.class);
}
private void asssertHasSingleBean(Class<?> type) {
assertThat(this.context.getBeanNamesForType(type)).hasSize(1);
}
}

View File

@@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Sergey Kuptsov
* @author Stephane Nicoll
*/
public class InfluxDbAutoConfigurationTest {
public class InfluxDbAutoConfigurationTests {
private AnnotationConfigApplicationContext context;

View File

@@ -60,8 +60,8 @@ public class JdbcTemplateAutoConfigurationTests {
load();
assertThat(this.context.getBeansOfType(JdbcOperations.class)).hasSize(1);
JdbcTemplate jdbcTemplate = this.context.getBean(JdbcTemplate.class);
assertThat(jdbcTemplate.getDataSource()).isEqualTo(
this.context.getBean(DataSource.class));
assertThat(jdbcTemplate.getDataSource())
.isEqualTo(this.context.getBean(DataSource.class));
assertThat(jdbcTemplate.getFetchSize()).isEqualTo(-1);
assertThat(jdbcTemplate.getQueryTimeout()).isEqualTo(-1);
assertThat(jdbcTemplate.getMaxRows()).isEqualTo(-1);
@@ -86,8 +86,8 @@ public class JdbcTemplateAutoConfigurationTests {
assertThat(this.context.getBeansOfType(JdbcOperations.class)).hasSize(1);
JdbcTemplate jdbcTemplate = this.context.getBean(JdbcTemplate.class);
assertThat(jdbcTemplate).isNotNull();
assertThat(jdbcTemplate.getDataSource()).isEqualTo(
this.context.getBean("customDataSource"));
assertThat(jdbcTemplate.getDataSource())
.isEqualTo(this.context.getBean("customDataSource"));
}
@Test
@@ -95,10 +95,10 @@ public class JdbcTemplateAutoConfigurationTests {
load();
assertThat(this.context.getBeansOfType(NamedParameterJdbcOperations.class))
.hasSize(1);
NamedParameterJdbcTemplate namedParameterJdbcTemplate = this.context.getBean(
NamedParameterJdbcTemplate.class);
assertThat(namedParameterJdbcTemplate.getJdbcOperations()).isEqualTo(
this.context.getBean(JdbcOperations.class));
NamedParameterJdbcTemplate namedParameterJdbcTemplate = this.context
.getBean(NamedParameterJdbcTemplate.class);
assertThat(namedParameterJdbcTemplate.getJdbcOperations())
.isEqualTo(this.context.getBean(JdbcOperations.class));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@@ -157,8 +157,8 @@ public class MongoReactiveAutoConfigurationTests {
@Bean
public MongoClientSettingsBuilderCustomizer customizer() {
return clientSettingsBuilder ->
clientSettingsBuilder.applicationName("overridden-name");
return clientSettingsBuilder -> clientSettingsBuilder
.applicationName("overridden-name");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.