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

@ -78,11 +78,9 @@ public class JerseyServerMetricsAutoConfiguration {
public ResourceConfigCustomizer jerseyServerMetricsResourceConfigCustomizer(
MeterRegistry meterRegistry, JerseyTagsProvider tagsProvider) {
Server server = this.properties.getWeb().getServer();
return (config) -> {
config.register(new MetricsApplicationEventListener(meterRegistry,
tagsProvider, server.getRequestsMetricName(),
server.isAutoTimeRequests(), new AnnotationUtilsAnnotationFinder()));
};
return (config) -> config.register(new MetricsApplicationEventListener(
meterRegistry, tagsProvider, server.getRequestsMetricName(),
server.isAutoTimeRequests(), new AnnotationUtilsAnnotationFinder()));
}
@Bean

View File

@ -28,6 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public abstract class StepRegistryPropertiesTests {
@SuppressWarnings("deprecation")
protected void assertStepRegistryDefaultValues(StepRegistryProperties properties,
StepRegistryConfig config) {
assertThat(properties.getStep()).isEqualTo(config.step());

View File

@ -102,9 +102,8 @@ public class TomcatMetricsAutoConfigurationTests {
.withConfiguration(
AutoConfigurations.of(TomcatMetricsAutoConfiguration.class))
.withUserConfiguration(MeterRegistryConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(TomcatMetricsBinder.class);
});
.run((context) -> assertThat(context)
.hasSingleBean(TomcatMetricsBinder.class));
}
@Test

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

View File

@ -23,7 +23,6 @@ import javax.servlet.Filter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@ -108,11 +107,15 @@ public class RemoteDevToolsAutoConfiguration {
@ConditionalOnProperty(prefix = "spring.devtools.remote.restart", name = "enabled", matchIfMissing = true)
static class RemoteRestartConfiguration {
@Autowired
private DevToolsProperties properties;
private final DevToolsProperties properties;
@Autowired
private ServerProperties serverProperties;
private final ServerProperties serverProperties;
RemoteRestartConfiguration(DevToolsProperties devToolsProperties,
ServerProperties serverProperties) {
this.properties = devToolsProperties;
this.serverProperties = serverProperties;
}
@Bean
@ConditionalOnMissingBean

View File

@ -0,0 +1,20 @@
/*
* 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.
*/
/**
* Devtools specific logging concerns.
*/
package org.springframework.boot.devtools.logger;

View File

@ -28,7 +28,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -75,11 +75,12 @@ public class RemoteClientConfiguration implements InitializingBean {
private final DevToolsProperties properties;
@Value("${remoteUrl}")
private String remoteUrl;
private final String remoteUrl;
public RemoteClientConfiguration(DevToolsProperties properties) {
public RemoteClientConfiguration(DevToolsProperties properties,
@Value("${remoteUrl}") String remoteUrl) {
this.properties = properties;
this.remoteUrl = remoteUrl;
}
@Bean
@ -134,20 +135,25 @@ public class RemoteClientConfiguration implements InitializingBean {
static class LiveReloadConfiguration
implements ApplicationListener<ClassPathChangedEvent> {
@Autowired
private DevToolsProperties properties;
private final DevToolsProperties properties;
@Autowired(required = false)
private LiveReloadServer liveReloadServer;
private final LiveReloadServer liveReloadServer;
@Autowired
private ClientHttpRequestFactory clientHttpRequestFactory;
private final ClientHttpRequestFactory clientHttpRequestFactory;
@Value("${remoteUrl}")
private String remoteUrl;
private ExecutorService executor = Executors.newSingleThreadExecutor();
LiveReloadConfiguration(DevToolsProperties properties,
ObjectProvider<LiveReloadServer> liveReloadServer,
ClientHttpRequestFactory clientHttpRequestFactory) {
this.properties = properties;
this.liveReloadServer = liveReloadServer.getIfAvailable();
this.clientHttpRequestFactory = clientHttpRequestFactory;
}
@Bean
@RestartScope
@ConditionalOnMissingBean
@ -181,11 +187,15 @@ public class RemoteClientConfiguration implements InitializingBean {
@ConditionalOnProperty(prefix = "spring.devtools.remote.restart", name = "enabled", matchIfMissing = true)
static class RemoteRestartClientConfiguration {
@Autowired
private DevToolsProperties properties;
private final DevToolsProperties properties;
@Value("${remoteUrl}")
private String remoteUrl;
private final String remoteUrl;
RemoteRestartClientConfiguration(DevToolsProperties properties,
@Value("${remoteUrl}") String remoteUrl) {
this.properties = properties;
this.remoteUrl = remoteUrl;
}
@Bean
public ClassPathFileSystemWatcher classPathFileSystemWatcher() {

View File

@ -111,12 +111,13 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi
FilterRegistrationBeans registrations = new FilterRegistrationBeans(this.context);
registrations.stream().map(AbstractFilterRegistrationBean.class::cast)
.filter(AbstractFilterRegistrationBean::isEnabled)
.forEach((registration) -> addFilter(builder, registration.getFilter(),
registration.getUrlPatterns()));
.forEach((registration) -> addFilter(builder, registration));
}
private void addFilter(ConfigurableMockMvcBuilder<?> builder, Filter filter,
Collection<String> urls) {
private void addFilter(ConfigurableMockMvcBuilder<?> builder,
AbstractFilterRegistrationBean<?> registration) {
Filter filter = registration.getFilter();
Collection<String> urls = registration.getUrlPatterns();
if (urls.isEmpty()) {
builder.addFilters(filter);
}

View File

@ -0,0 +1,20 @@
/*
* 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.
*/
/**
* Web test utilities and support classes.
*/
package org.springframework.boot.test.web;

View File

@ -0,0 +1,20 @@
/*
* 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.
*/
/**
* Field value parsing for the standard Java compiler.
*/
package org.springframework.boot.configurationprocessor.fieldvalues.javac;

View File

@ -0,0 +1,20 @@
/*
* 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.
*/
/**
* Abstraction for field value parsing.
*/
package org.springframework.boot.configurationprocessor.fieldvalues;

View File

@ -0,0 +1,20 @@
/*
* 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.
*/
/**
* The configuration properties meta-data model and JSON writing support.
*/
package org.springframework.boot.configurationprocessor.metadata;

View File

@ -0,0 +1,20 @@
/*
* 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.
*/
/**
* Annotation processor to create {@code @ConfigurationProperties} meta-data files.
*/
package org.springframework.boot.configurationprocessor;

View File

@ -35,10 +35,6 @@ class ZipInflaterInputStream extends InflaterInputStream {
private boolean extraBytesWritten;
ZipInflaterInputStream(InputStream inputStream, int size) {
this(inputStream, new Inflater(true), size);
}
private ZipInflaterInputStream(InputStream inputStream, Inflater inflater, int size) {
super(inputStream, new Inflater(true), getInflaterBufferSize(size));
this.available = size;
}

View File

@ -0,0 +1,20 @@
/*
* 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.
*/
/**
* Maven plugin for Spring Boot.
*/
package org.springframework.boot.maven;

View File

@ -136,7 +136,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
SslContextBuilder builder = SslContextBuilder.forClient()
.sslProvider(SslProvider.JDK)
.trustManager(InsecureTrustManagerFactory.INSTANCE);
HttpClient client = HttpClient.create().wiretap()
HttpClient client = HttpClient.create().wiretap(true)
.secure((sslContextSpec) -> sslContextSpec.sslContext(builder));
return new ReactorClientHttpConnector(client);
}
@ -174,7 +174,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
.sslProvider(SslProvider.JDK)
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.keyManager(clientKeyManagerFactory);
HttpClient client = HttpClient.create().wiretap()
HttpClient client = HttpClient.create().wiretap(true)
.secure((sslContextSpec) -> sslContextSpec.sslContext(builder));
return new ReactorClientHttpConnector(client);
}
@ -232,7 +232,7 @@ public abstract class AbstractReactiveWebServerFactoryTests {
}
protected WebClient.Builder getWebClient() {
return getWebClient(HttpClient.create().wiretap());
return getWebClient(HttpClient.create().wiretap(true));
}
protected WebClient.Builder getWebClient(HttpClient client) {
@ -304,10 +304,11 @@ public abstract class AbstractReactiveWebServerFactoryTests {
.getWebServer(new CharsHandler(3000, MediaType.TEXT_PLAIN));
this.webServer.start();
HttpClient client = HttpClient.create().wiretap().compress(true).tcpConfiguration(
(tcpClient) -> tcpClient.doOnConnected((connection) -> connection
.channel().pipeline().addBefore(NettyPipeline.HttpDecompressor,
"CompressionTest", new CompressionDetectionHandler())));
HttpClient client = HttpClient.create().wiretap(true).compress(true)
.tcpConfiguration((tcpClient) -> tcpClient.doOnConnected(
(connection) -> connection.channel().pipeline().addBefore(
NettyPipeline.HttpDecompressor, "CompressionTest",
new CompressionDetectionHandler())));
return getWebClient(client).build();
}

View File

@ -0,0 +1,20 @@
/*
* 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.
*/
/**
* Sample used for testing.
*/
package sample;