Move to constructor injection in simple configuration classes

This commit updates "simple" configuration classes to use constructor
injection. Simple means that there are no optional dependencies
(@Autowired(required=false) is not used), and none of the dependencies
use generics.

Configuration classes that are not simple will be updated in a second
pass once https://jira.spring.io/browse/SPR-14015 has been fixed.

See gh-5306
This commit is contained in:
Andy Wilkinson
2016-03-04 10:49:17 +00:00
parent 398aed7fdb
commit 5009933788
74 changed files with 525 additions and 321 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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.
@@ -74,11 +74,15 @@ public class RemoteDevToolsAutoConfiguration {
private static final Log logger = LogFactory
.getLog(RemoteDevToolsAutoConfiguration.class);
@Autowired
private DevToolsProperties properties;
private final DevToolsProperties properties;
@Autowired
private ServerProperties serverProperties;
private final ServerProperties serverProperties;
public RemoteDevToolsAutoConfiguration(DevToolsProperties properties,
ServerProperties serverProperties) {
this.properties = properties;
this.serverProperties = serverProperties;
}
@Bean
@ConditionalOnMissingBean

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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.
@@ -80,12 +80,15 @@ public class RemoteClientConfiguration {
private static final Log logger = LogFactory.getLog(RemoteClientConfiguration.class);
@Autowired
private DevToolsProperties properties;
private final DevToolsProperties properties;
@Value("${remoteUrl}")
private String remoteUrl;
public RemoteClientConfiguration(DevToolsProperties properties) {
this.properties = properties;
}
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();

View File

@@ -28,7 +28,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.devtools.filewatch.ChangedFile;
import org.springframework.boot.devtools.filewatch.FileSystemWatcher;
import org.springframework.boot.devtools.filewatch.FileSystemWatcherFactory;
@@ -92,8 +91,11 @@ public class ClassPathFileSystemWatcherTests {
@Configuration
public static class Config {
@Autowired
public Environment environment;
public final Environment environment;
public Config(Environment environment) {
this.environment = environment;
}
@Bean
public ClassPathFileSystemWatcher watcher() {