Skip to content

Commit f3fa20b

Browse files
committed
Polish
1 parent ac9c003 commit f3fa20b

File tree

24 files changed

+281
-79
lines changed

24 files changed

+281
-79
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jersey/JerseyServerMetricsAutoConfiguration.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ public DefaultJerseyTagsProvider jerseyTagsProvider() {
7878
public ResourceConfigCustomizer jerseyServerMetricsResourceConfigCustomizer(
7979
MeterRegistry meterRegistry, JerseyTagsProvider tagsProvider) {
8080
Server server = this.properties.getWeb().getServer();
81-
return (config) -> {
82-
config.register(new MetricsApplicationEventListener(meterRegistry,
83-
tagsProvider, server.getRequestsMetricName(),
84-
server.isAutoTimeRequests(), new AnnotationUtilsAnnotationFinder()));
85-
};
81+
return (config) -> config.register(new MetricsApplicationEventListener(
82+
meterRegistry, tagsProvider, server.getRequestsMetricName(),
83+
server.isAutoTimeRequests(), new AnnotationUtilsAnnotationFinder()));
8684
}
8785

8886
@Bean

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/properties/StepRegistryPropertiesTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929
public abstract class StepRegistryPropertiesTests {
3030

31+
@SuppressWarnings("deprecation")
3132
protected void assertStepRegistryDefaultValues(StepRegistryProperties properties,
3233
StepRegistryConfig config) {
3334
assertThat(properties.getStep()).isEqualTo(config.step());

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/web/tomcat/TomcatMetricsAutoConfigurationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ public void autoConfiguresTomcatMetricsWithStandaloneTomcat() {
102102
.withConfiguration(
103103
AutoConfigurations.of(TomcatMetricsAutoConfiguration.class))
104104
.withUserConfiguration(MeterRegistryConfiguration.class)
105-
.run((context) -> {
106-
assertThat(context).hasSingleBean(TomcatMetricsBinder.class);
107-
});
105+
.run((context) -> assertThat(context)
106+
.hasSingleBean(TomcatMetricsBinder.class));
108107
}
109108

110109
@Test

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* {@link ApplicationListener} to trigger early initialization in a background thread of
4141
* time consuming tasks.
4242
* <p>
43-
* Set the {@value IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME} system property to
43+
* Set the {@link #IGNORE_BACKGROUNDPREINITIALIZER_PROPERTY_NAME} system property to
4444
* {@code true} to disable this mechanism and let such initialization happen in the
4545
* foreground.
4646
*

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public PersistenceExceptionTranslator getExceptionTranslator() {
168168
}
169169

170170
@Override
171+
@Deprecated
171172
public DB getLegacyDb() {
172173
return this.mongoDbFactory.getLegacyDb();
173174
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Internal {@link org.springframework.boot.diagnostics.FailureAnalyzer} implementations
19+
* related to auto-configuration.
20+
*/
21+
package org.springframework.boot.autoconfigure.diagnostics.analyzer;

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbOkHttpClientBuilderProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import org.influxdb.InfluxDB;
2323

2424
/**
25-
* Provide the {@link OkHttpClient.Builder} to use to customize the auto-configured
26-
* {@link InfluxDB} instance.
25+
* Provide the {@link okhttp3.OkHttpClient.Builder OkHttpClient.Builder} to use to
26+
* customize the auto-configured {@link InfluxDB} instance.
2727
*
2828
* @author Stephane Nicoll
2929
* @since 2.1.0

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import org.springframework.beans.BeanUtils;
2424
import org.springframework.beans.factory.BeanClassLoaderAware;
25-
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.beans.factory.ObjectProvider;
2626
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
2727
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2828
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@@ -61,17 +61,21 @@
6161
@ConditionalOnMissingBean(DataSource.class)
6262
public class XADataSourceAutoConfiguration implements BeanClassLoaderAware {
6363

64-
@Autowired
65-
private XADataSourceWrapper wrapper;
64+
private final XADataSourceWrapper wrapper;
6665

67-
@Autowired
68-
private DataSourceProperties properties;
66+
private final DataSourceProperties properties;
6967

70-
@Autowired(required = false)
71-
private XADataSource xaDataSource;
68+
private final XADataSource xaDataSource;
7269

7370
private ClassLoader classLoader;
7471

72+
public XADataSourceAutoConfiguration(XADataSourceWrapper wrapper,
73+
DataSourceProperties properties, ObjectProvider<XADataSource> xaDataSource) {
74+
this.wrapper = wrapper;
75+
this.properties = properties;
76+
this.xaDataSource = xaDataSource.getIfAvailable();
77+
}
78+
7579
@Bean
7680
public DataSource dataSource() throws Exception {
7781
XADataSource xaDataSource = this.xaDataSource;

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929

3030
import org.springframework.boot.autoconfigure.AutoConfigurations;
3131
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
32+
import org.springframework.context.ApplicationContext;
3233
import org.springframework.context.annotation.Bean;
3334
import org.springframework.context.annotation.Configuration;
35+
import org.springframework.test.util.ReflectionTestUtils;
3436

3537
import static org.assertj.core.api.Assertions.assertThat;
3638
import static org.mockito.ArgumentMatchers.any;
@@ -59,20 +61,17 @@ public void clientExists() {
5961
public void optionsAdded() {
6062
this.contextRunner.withPropertyValues("spring.data.mongodb.host:localhost")
6163
.withUserConfiguration(OptionsConfig.class)
62-
.run((context) -> assertThat(
63-
context.getBean(MongoClient.class).getSettings()
64-
.getSocketSettings().getReadTimeout(TimeUnit.SECONDS))
65-
.isEqualTo(300));
64+
.run((context) -> assertThat(getSettings(context).getSocketSettings()
65+
.getReadTimeout(TimeUnit.SECONDS)).isEqualTo(300));
6666
}
6767

6868
@Test
6969
public void optionsAddedButNoHost() {
7070
this.contextRunner
7171
.withPropertyValues("spring.data.mongodb.uri:mongodb://localhost/test")
7272
.withUserConfiguration(OptionsConfig.class)
73-
.run((context) -> assertThat(context.getBean(MongoClient.class)
74-
.getSettings().getReadPreference())
75-
.isEqualTo(ReadPreference.nearest()));
73+
.run((context) -> assertThat(getSettings(context).getReadPreference())
74+
.isEqualTo(ReadPreference.nearest()));
7675
}
7776

7877
@Test
@@ -81,9 +80,7 @@ public void optionsSslConfig() {
8180
.withPropertyValues("spring.data.mongodb.uri:mongodb://localhost/test")
8281
.withUserConfiguration(SslOptionsConfig.class).run((context) -> {
8382
assertThat(context).hasSingleBean(MongoClient.class);
84-
MongoClient mongo = context.getBean(MongoClient.class);
85-
com.mongodb.async.client.MongoClientSettings settings = mongo
86-
.getSettings();
83+
MongoClientSettings settings = getSettings(context);
8784
assertThat(settings.getApplicationName()).isEqualTo("test-config");
8885
assertThat(settings.getStreamFactoryFactory())
8986
.isSameAs(context.getBean("myStreamFactoryFactory"));
@@ -94,9 +91,8 @@ public void optionsSslConfig() {
9491
public void nettyStreamFactoryFactoryIsConfiguredAutomatically() {
9592
this.contextRunner.run((context) -> {
9693
assertThat(context).hasSingleBean(MongoClient.class);
97-
assertThat(context.getBean(MongoClient.class).getSettings()
98-
.getStreamFactoryFactory())
99-
.isInstanceOf(NettyStreamFactoryFactory.class);
94+
assertThat(getSettings(context).getStreamFactoryFactory())
95+
.isInstanceOf(NettyStreamFactoryFactory.class);
10096
});
10197
}
10298

@@ -106,14 +102,21 @@ public void customizerOverridesAutoConfig() {
106102
"spring.data.mongodb.uri:mongodb://localhost/test?appname=auto-config")
107103
.withUserConfiguration(SimpleCustomizerConfig.class).run((context) -> {
108104
assertThat(context).hasSingleBean(MongoClient.class);
109-
MongoClient client = context.getBean(MongoClient.class);
110-
assertThat(client.getSettings().getApplicationName())
105+
MongoClientSettings settings = getSettings(context);
106+
assertThat(settings.getApplicationName())
111107
.isEqualTo("overridden-name");
112-
assertThat(client.getSettings().getStreamFactoryFactory())
108+
assertThat(settings.getStreamFactoryFactory())
113109
.isEqualTo(SimpleCustomizerConfig.streamFactoryFactory);
114110
});
115111
}
116112

113+
@SuppressWarnings("deprecation")
114+
private MongoClientSettings getSettings(ApplicationContext context) {
115+
MongoClient client = context.getBean(MongoClient.class);
116+
return (MongoClientSettings) ReflectionTestUtils.getField(client.getSettings(),
117+
"wrapped");
118+
}
119+
117120
@Configuration
118121
static class OptionsConfig {
119122

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/ReactiveMongoClientFactoryTests.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.springframework.core.env.Environment;
3030
import org.springframework.mock.env.MockEnvironment;
31+
import org.springframework.test.util.ReflectionTestUtils;
3132

3233
import static org.assertj.core.api.Assertions.assertThat;
3334
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
@@ -113,7 +114,7 @@ public void retryWritesIsPropagatedFromUri() {
113114
MongoProperties properties = new MongoProperties();
114115
properties.setUri("mongodb://localhost/test?retryWrites=true");
115116
MongoClient client = createMongoClient(properties);
116-
assertThat(client.getSettings().getRetryWrites()).isTrue();
117+
assertThat(getSettings(client).getRetryWrites()).isTrue();
117118
}
118119

119120
@Test
@@ -190,14 +191,19 @@ private MongoClient createMongoClient(MongoProperties properties,
190191
}
191192

192193
private List<ServerAddress> extractServerAddresses(MongoClient client) {
193-
com.mongodb.async.client.MongoClientSettings settings = client.getSettings();
194+
MongoClientSettings settings = getSettings(client);
194195
ClusterSettings clusterSettings = settings.getClusterSettings();
195196
return clusterSettings.getHosts();
196197
}
197198

198199
private MongoCredential extractMongoCredentials(MongoClient client) {
199-
com.mongodb.async.client.MongoClientSettings settings = client.getSettings();
200-
return settings.getCredential();
200+
return getSettings(client).getCredential();
201+
}
202+
203+
@SuppressWarnings("deprecation")
204+
private MongoClientSettings getSettings(MongoClient client) {
205+
return (MongoClientSettings) ReflectionTestUtils.getField(client.getSettings(),
206+
"wrapped");
201207
}
202208

203209
private void assertServerAddress(ServerAddress serverAddress, String expectedHost,

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,11 @@ public void asyncTaskExecutorWithMvcConfigurerCanOverrideExecutor() {
512512
this.contextRunner.withUserConfiguration(CustomAsyncTaskExecutorConfigurer.class)
513513
.withConfiguration(
514514
AutoConfigurations.of(TaskExecutionAutoConfiguration.class))
515-
.run((context) -> {
516-
assertThat(ReflectionTestUtils.getField(
517-
context.getBean(RequestMappingHandlerAdapter.class),
518-
"taskExecutor"))
519-
.isSameAs(context.getBean(
520-
CustomAsyncTaskExecutorConfigurer.class).taskExecutor);
521-
});
515+
.run((context) -> assertThat(ReflectionTestUtils.getField(
516+
context.getBean(RequestMappingHandlerAdapter.class),
517+
"taskExecutor"))
518+
.isSameAs(context.getBean(
519+
CustomAsyncTaskExecutorConfigurer.class).taskExecutor));
522520
}
523521

524522
@Test

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
2525

26-
import org.springframework.beans.factory.annotation.Autowired;
2726
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2827
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2928
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
@@ -108,11 +107,15 @@ public DispatcherFilter remoteDevToolsDispatcherFilter(AccessManager accessManag
108107
@ConditionalOnProperty(prefix = "spring.devtools.remote.restart", name = "enabled", matchIfMissing = true)
109108
static class RemoteRestartConfiguration {
110109

111-
@Autowired
112-
private DevToolsProperties properties;
110+
private final DevToolsProperties properties;
113111

114-
@Autowired
115-
private ServerProperties serverProperties;
112+
private final ServerProperties serverProperties;
113+
114+
RemoteRestartConfiguration(DevToolsProperties devToolsProperties,
115+
ServerProperties serverProperties) {
116+
this.properties = devToolsProperties;
117+
this.serverProperties = serverProperties;
118+
}
116119

117120
@Bean
118121
@ConditionalOnMissingBean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Devtools specific logging concerns.
19+
*/
20+
package org.springframework.boot.devtools.logger;

spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.apache.commons.logging.LogFactory;
2929

3030
import org.springframework.beans.factory.InitializingBean;
31-
import org.springframework.beans.factory.annotation.Autowired;
31+
import org.springframework.beans.factory.ObjectProvider;
3232
import org.springframework.beans.factory.annotation.Value;
3333
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3434
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -75,11 +75,12 @@ public class RemoteClientConfiguration implements InitializingBean {
7575

7676
private final DevToolsProperties properties;
7777

78-
@Value("${remoteUrl}")
79-
private String remoteUrl;
78+
private final String remoteUrl;
8079

81-
public RemoteClientConfiguration(DevToolsProperties properties) {
80+
public RemoteClientConfiguration(DevToolsProperties properties,
81+
@Value("${remoteUrl}") String remoteUrl) {
8282
this.properties = properties;
83+
this.remoteUrl = remoteUrl;
8384
}
8485

8586
@Bean
@@ -134,20 +135,25 @@ private void logWarnings() {
134135
static class LiveReloadConfiguration
135136
implements ApplicationListener<ClassPathChangedEvent> {
136137

137-
@Autowired
138-
private DevToolsProperties properties;
138+
private final DevToolsProperties properties;
139139

140-
@Autowired(required = false)
141-
private LiveReloadServer liveReloadServer;
140+
private final LiveReloadServer liveReloadServer;
142141

143-
@Autowired
144-
private ClientHttpRequestFactory clientHttpRequestFactory;
142+
private final ClientHttpRequestFactory clientHttpRequestFactory;
145143

146144
@Value("${remoteUrl}")
147145
private String remoteUrl;
148146

149147
private ExecutorService executor = Executors.newSingleThreadExecutor();
150148

149+
LiveReloadConfiguration(DevToolsProperties properties,
150+
ObjectProvider<LiveReloadServer> liveReloadServer,
151+
ClientHttpRequestFactory clientHttpRequestFactory) {
152+
this.properties = properties;
153+
this.liveReloadServer = liveReloadServer.getIfAvailable();
154+
this.clientHttpRequestFactory = clientHttpRequestFactory;
155+
}
156+
151157
@Bean
152158
@RestartScope
153159
@ConditionalOnMissingBean
@@ -181,11 +187,15 @@ final ExecutorService getExecutor() {
181187
@ConditionalOnProperty(prefix = "spring.devtools.remote.restart", name = "enabled", matchIfMissing = true)
182188
static class RemoteRestartClientConfiguration {
183189

184-
@Autowired
185-
private DevToolsProperties properties;
190+
private final DevToolsProperties properties;
186191

187-
@Value("${remoteUrl}")
188-
private String remoteUrl;
192+
private final String remoteUrl;
193+
194+
RemoteRestartClientConfiguration(DevToolsProperties properties,
195+
@Value("${remoteUrl}") String remoteUrl) {
196+
this.properties = properties;
197+
this.remoteUrl = remoteUrl;
198+
}
189199

190200
@Bean
191201
public ClassPathFileSystemWatcher classPathFileSystemWatcher() {

0 commit comments

Comments
 (0)