This commit is contained in:
Phillip Webb
2018-10-29 14:23:35 -07:00
parent ac9c003a65
commit f3fa20b2d1
24 changed files with 281 additions and 79 deletions

View File

@@ -40,7 +40,7 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage
* {@link ApplicationListener} to trigger early initialization in a background thread of
* time consuming tasks.
* <p>
* Set the {@value IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME} system property to
* Set the {@link #IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME} system property to
* {@code true} to disable this mechanism and let such initialization happen in the
* foreground.
*

View File

@@ -168,6 +168,7 @@ public class MongoDataAutoConfiguration {
}
@Override
@Deprecated
public DB getLegacyDb() {
return this.mongoDbFactory.getLegacyDb();
}

View File

@@ -0,0 +1,21 @@
/*
* Copyright 2012-2018 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
*
* http://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.
*/
/**
* Internal {@link org.springframework.boot.diagnostics.FailureAnalyzer} implementations
* related to auto-configuration.
*/
package org.springframework.boot.autoconfigure.diagnostics.analyzer;

View File

@@ -22,8 +22,8 @@ import okhttp3.OkHttpClient;
import org.influxdb.InfluxDB;
/**
* Provide the {@link OkHttpClient.Builder} to use to customize the auto-configured
* {@link InfluxDB} instance.
* Provide the {@link okhttp3.OkHttpClient.Builder OkHttpClient.Builder} to use to
* customize the auto-configured {@link InfluxDB} instance.
*
* @author Stephane Nicoll
* @since 2.1.0

View File

@@ -22,7 +22,7 @@ import javax.transaction.TransactionManager;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -61,17 +61,21 @@ import org.springframework.util.StringUtils;
@ConditionalOnMissingBean(DataSource.class)
public class XADataSourceAutoConfiguration implements BeanClassLoaderAware {
@Autowired
private XADataSourceWrapper wrapper;
private final XADataSourceWrapper wrapper;
@Autowired
private DataSourceProperties properties;
private final DataSourceProperties properties;
@Autowired(required = false)
private XADataSource xaDataSource;
private final XADataSource xaDataSource;
private ClassLoader classLoader;
public XADataSourceAutoConfiguration(XADataSourceWrapper wrapper,
DataSourceProperties properties, ObjectProvider<XADataSource> xaDataSource) {
this.wrapper = wrapper;
this.properties = properties;
this.xaDataSource = xaDataSource.getIfAvailable();
}
@Bean
public DataSource dataSource() throws Exception {
XADataSource xaDataSource = this.xaDataSource;

View File

@@ -29,8 +29,10 @@ import org.junit.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -59,10 +61,8 @@ public class MongoReactiveAutoConfigurationTests {
public void optionsAdded() {
this.contextRunner.withPropertyValues("spring.data.mongodb.host:localhost")
.withUserConfiguration(OptionsConfig.class)
.run((context) -> assertThat(
context.getBean(MongoClient.class).getSettings()
.getSocketSettings().getReadTimeout(TimeUnit.SECONDS))
.isEqualTo(300));
.run((context) -> assertThat(getSettings(context).getSocketSettings()
.getReadTimeout(TimeUnit.SECONDS)).isEqualTo(300));
}
@Test
@@ -70,9 +70,8 @@ public class MongoReactiveAutoConfigurationTests {
this.contextRunner
.withPropertyValues("spring.data.mongodb.uri:mongodb://localhost/test")
.withUserConfiguration(OptionsConfig.class)
.run((context) -> assertThat(context.getBean(MongoClient.class)
.getSettings().getReadPreference())
.isEqualTo(ReadPreference.nearest()));
.run((context) -> assertThat(getSettings(context).getReadPreference())
.isEqualTo(ReadPreference.nearest()));
}
@Test
@@ -81,9 +80,7 @@ public class MongoReactiveAutoConfigurationTests {
.withPropertyValues("spring.data.mongodb.uri:mongodb://localhost/test")
.withUserConfiguration(SslOptionsConfig.class).run((context) -> {
assertThat(context).hasSingleBean(MongoClient.class);
MongoClient mongo = context.getBean(MongoClient.class);
com.mongodb.async.client.MongoClientSettings settings = mongo
.getSettings();
MongoClientSettings settings = getSettings(context);
assertThat(settings.getApplicationName()).isEqualTo("test-config");
assertThat(settings.getStreamFactoryFactory())
.isSameAs(context.getBean("myStreamFactoryFactory"));
@@ -94,9 +91,8 @@ public class MongoReactiveAutoConfigurationTests {
public void nettyStreamFactoryFactoryIsConfiguredAutomatically() {
this.contextRunner.run((context) -> {
assertThat(context).hasSingleBean(MongoClient.class);
assertThat(context.getBean(MongoClient.class).getSettings()
.getStreamFactoryFactory())
.isInstanceOf(NettyStreamFactoryFactory.class);
assertThat(getSettings(context).getStreamFactoryFactory())
.isInstanceOf(NettyStreamFactoryFactory.class);
});
}
@@ -106,14 +102,21 @@ public class MongoReactiveAutoConfigurationTests {
"spring.data.mongodb.uri:mongodb://localhost/test?appname=auto-config")
.withUserConfiguration(SimpleCustomizerConfig.class).run((context) -> {
assertThat(context).hasSingleBean(MongoClient.class);
MongoClient client = context.getBean(MongoClient.class);
assertThat(client.getSettings().getApplicationName())
MongoClientSettings settings = getSettings(context);
assertThat(settings.getApplicationName())
.isEqualTo("overridden-name");
assertThat(client.getSettings().getStreamFactoryFactory())
assertThat(settings.getStreamFactoryFactory())
.isEqualTo(SimpleCustomizerConfig.streamFactoryFactory);
});
}
@SuppressWarnings("deprecation")
private MongoClientSettings getSettings(ApplicationContext context) {
MongoClient client = context.getBean(MongoClient.class);
return (MongoClientSettings) ReflectionTestUtils.getField(client.getSettings(),
"wrapped");
}
@Configuration
static class OptionsConfig {

View File

@@ -28,6 +28,7 @@ import org.junit.Test;
import org.springframework.core.env.Environment;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
@@ -113,7 +114,7 @@ public class ReactiveMongoClientFactoryTests {
MongoProperties properties = new MongoProperties();
properties.setUri("mongodb://localhost/test?retryWrites=true");
MongoClient client = createMongoClient(properties);
assertThat(client.getSettings().getRetryWrites()).isTrue();
assertThat(getSettings(client).getRetryWrites()).isTrue();
}
@Test
@@ -190,14 +191,19 @@ public class ReactiveMongoClientFactoryTests {
}
private List<ServerAddress> extractServerAddresses(MongoClient client) {
com.mongodb.async.client.MongoClientSettings settings = client.getSettings();
MongoClientSettings settings = getSettings(client);
ClusterSettings clusterSettings = settings.getClusterSettings();
return clusterSettings.getHosts();
}
private MongoCredential extractMongoCredentials(MongoClient client) {
com.mongodb.async.client.MongoClientSettings settings = client.getSettings();
return settings.getCredential();
return getSettings(client).getCredential();
}
@SuppressWarnings("deprecation")
private MongoClientSettings getSettings(MongoClient client) {
return (MongoClientSettings) ReflectionTestUtils.getField(client.getSettings(),
"wrapped");
}
private void assertServerAddress(ServerAddress serverAddress, String expectedHost,

View File

@@ -512,13 +512,11 @@ public class WebMvcAutoConfigurationTests {
this.contextRunner.withUserConfiguration(CustomAsyncTaskExecutorConfigurer.class)
.withConfiguration(
AutoConfigurations.of(TaskExecutionAutoConfiguration.class))
.run((context) -> {
assertThat(ReflectionTestUtils.getField(
context.getBean(RequestMappingHandlerAdapter.class),
"taskExecutor"))
.isSameAs(context.getBean(
CustomAsyncTaskExecutorConfigurer.class).taskExecutor);
});
.run((context) -> assertThat(ReflectionTestUtils.getField(
context.getBean(RequestMappingHandlerAdapter.class),
"taskExecutor"))
.isSameAs(context.getBean(
CustomAsyncTaskExecutorConfigurer.class).taskExecutor));
}
@Test