From 5009933788f5f8c687719de6a697074ff80b1b69 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 4 Mar 2016 10:49:17 +0000 Subject: [PATCH] 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 --- .../HealthIndicatorAutoConfiguration.java | 8 +++-- .../JolokiaAutoConfiguration.java | 8 +++-- .../MetricFilterAutoConfiguration.java | 15 ++++---- .../MetricRepositoryAutoConfiguration.java | 11 +++--- .../AutoConfigurationReportEndpointTests.java | 8 +++-- .../actuate/endpoint/FlywayEndpointTests.java | 8 ++--- .../endpoint/LiquibaseEndpointTests.java | 8 +++-- .../batch/BatchAutoConfiguration.java | 9 +++-- .../cache/EhCacheCacheConfiguration.java | 13 ++++--- .../cache/GenericCacheConfiguration.java | 8 +++-- .../cache/HazelcastInstanceConfiguration.java | 23 +++++++----- .../cache/RedisCacheConfiguration.java | 13 ++++--- .../cache/SimpleCacheConfiguration.java | 13 ++++--- .../cassandra/CassandraAutoConfiguration.java | 10 +++--- .../couchbase/CouchbaseAutoConfiguration.java | 8 +++-- .../CassandraDataAutoConfiguration.java | 15 ++++---- .../ElasticsearchAutoConfiguration.java | 8 +++-- .../mongo/MongoDataAutoConfiguration.java | 19 +++++----- ...ingBootRepositoryRestMvcConfiguration.java | 10 +++--- .../FreeMarkerAutoConfiguration.java | 12 ++++--- .../GroovyTemplateAutoConfiguration.java | 9 +++-- .../h2/H2ConsoleAutoConfiguration.java | 9 +++-- .../hazelcast/HazelcastAutoConfiguration.java | 10 +++--- .../jackson/JacksonAutoConfiguration.java | 20 +++++++---- .../jdbc/EmbeddedDataSourceConfiguration.java | 10 +++--- .../jdbc/JndiDataSourceAutoConfiguration.java | 8 +++-- ...ndiConnectionFactoryAutoConfiguration.java | 10 +++--- .../liquibase/LiquibaseAutoConfiguration.java | 20 ++++++----- .../mail/JndiSessionConfiguration.java | 10 +++--- .../MailSenderValidatorAutoConfiguration.java | 10 +++--- ...legatingViewResolverAutoConfiguration.java | 18 +++++++--- .../DeviceResolverAutoConfiguration.java | 33 ++++++++++------- .../SitePreferenceAutoConfiguration.java | 35 +++++++++++-------- .../mustache/MustacheAutoConfiguration.java | 26 ++++++++------ .../jpa/HibernateJpaAutoConfiguration.java | 15 ++++---- .../SpringBootWebSecurityConfiguration.java | 7 ++-- .../oauth2/OAuth2AutoConfiguration.java | 10 +++--- ...Auth2AuthorizationServerConfiguration.java | 14 +++++--- .../client/OAuth2SsoDefaultConfiguration.java | 15 ++++---- .../OAuth2ResourceServerConfiguration.java | 8 +++-- ...ourceServerTokenServicesConfiguration.java | 9 +++-- .../sendgrid/SendGridAutoConfiguration.java | 8 +++-- .../session/SessionAutoConfiguration.java | 21 +++++------ .../social/FacebookAutoConfiguration.java | 10 +++--- .../social/LinkedInAutoConfiguration.java | 10 +++--- .../social/TwitterAutoConfiguration.java | 10 +++--- .../solr/SolrAutoConfiguration.java | 8 +++-- .../thymeleaf/ThymeleafAutoConfiguration.java | 12 ++++--- .../TransactionAutoConfiguration.java | 10 +++--- .../jta/AtomikosJtaConfiguration.java | 8 +++-- .../jta/BitronixJtaConfiguration.java | 8 +++-- .../velocity/VelocityAutoConfiguration.java | 14 +++++--- .../web/ErrorMvcAutoConfiguration.java | 10 +++--- .../web/HttpEncodingAutoConfiguration.java | 10 +++--- ...ttpMessageConvertersAutoConfiguration.java | 10 ++++-- .../web/MultipartAutoConfiguration.java | 10 +++--- .../web/WebMvcAutoConfiguration.java | 7 ++-- .../WebSocketMessagingAutoConfiguration.java | 8 +++-- .../couchbase/CouchbaseTestConfiguration.java | 4 +++ .../flyway/FlywayAutoConfigurationTests.java | 8 +++-- .../AbstractJpaAutoConfigurationTests.java | 8 +++-- .../HibernateJpaAutoConfigurationTests.java | 5 ++- .../SecurityAutoConfigurationTests.java | 15 +++++--- ...ringBootWebSecurityConfigurationTests.java | 7 ++-- .../oauth2/OAuth2AutoConfigurationTests.java | 14 +++++--- ...ServerTokenServicesConfigurationTests.java | 6 ++-- .../security/user/SecurityConfig.java | 8 +++-- ...SocketMessagingAutoConfigurationTests.java | 4 +-- .../RemoteDevToolsAutoConfiguration.java | 14 +++++--- .../client/RemoteClientConfiguration.java | 9 +++-- .../ClassPathFileSystemWatcherTests.java | 8 +++-- .../redis/AggregateMetricsConfiguration.java | 13 ++++--- ...edServletContainerMvcIntegrationTests.java | 8 +++-- .../boot/orm/jpa/EntityScanTests.java | 8 +++-- 74 files changed, 525 insertions(+), 321 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java index a7b080f022..0762335b98 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfiguration.java @@ -103,8 +103,12 @@ import org.springframework.mail.javamail.JavaMailSenderImpl; @EnableConfigurationProperties({ HealthIndicatorProperties.class }) public class HealthIndicatorAutoConfiguration { - @Autowired - private HealthIndicatorProperties properties = new HealthIndicatorProperties(); + private final HealthIndicatorProperties properties; + + public HealthIndicatorAutoConfiguration( + HealthIndicatorProperties properties) { + this.properties = properties; + } @Bean @ConditionalOnMissingBean(HealthAggregator.class) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfiguration.java index 4bb51f0aee..4abe23a18d 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/JolokiaAutoConfiguration.java @@ -20,7 +20,6 @@ import java.util.Properties; import org.jolokia.http.AgentServlet; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.JolokiaAutoConfiguration.JolokiaCondition; import org.springframework.boot.actuate.endpoint.mvc.JolokiaMvcEndpoint; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -69,8 +68,11 @@ import org.springframework.web.servlet.mvc.ServletWrappingController; @EnableConfigurationProperties(JolokiaProperties.class) public class JolokiaAutoConfiguration { - @Autowired - JolokiaProperties properties = new JolokiaProperties(); + private final JolokiaProperties properties; + + public JolokiaAutoConfiguration(JolokiaProperties properties) { + this.properties = properties; + } @Bean @ConditionalOnMissingBean diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java index 20d0453e1c..ddc8453112 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java @@ -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. @@ -19,7 +19,6 @@ package org.springframework.boot.actuate.autoconfigure; import javax.servlet.Servlet; import javax.servlet.ServletRegistration; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.metrics.CounterService; import org.springframework.boot.actuate.metrics.GaugeService; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -48,11 +47,15 @@ import org.springframework.web.servlet.HandlerMapping; @ConditionalOnProperty(name = "endpoints.metrics.filter.enabled", matchIfMissing = true) public class MetricFilterAutoConfiguration { - @Autowired - private CounterService counterService; + private final CounterService counterService; - @Autowired - private GaugeService gaugeService; + private final GaugeService gaugeService; + + public MetricFilterAutoConfiguration(CounterService counterService, + GaugeService gaugeService) { + this.counterService = counterService; + this.gaugeService = gaugeService; + } @Bean public MetricsFilter metricFilter() { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java index ee8dacfb6d..1d15d8ecbe 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricRepositoryAutoConfiguration.java @@ -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. @@ -18,7 +18,6 @@ package org.springframework.boot.actuate.autoconfigure; import com.codahale.metrics.MetricRegistry; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.metrics.CounterService; import org.springframework.boot.actuate.metrics.GaugeService; import org.springframework.boot.actuate.metrics.buffer.BufferCounterService; @@ -86,9 +85,11 @@ public class MetricRepositoryAutoConfiguration { @ConditionalOnMissingBean(GaugeService.class) static class LegacyMetricServicesConfiguration { - @Autowired - @ActuatorMetricWriter - private MetricWriter writer; + private final MetricWriter writer; + + LegacyMetricServicesConfiguration(@ActuatorMetricWriter MetricWriter writer) { + this.writer = writer; + } @Bean @ConditionalOnMissingBean(CounterService.class) diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java index 5889f3cada..375d184ea6 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/AutoConfigurationReportEndpointTests.java @@ -22,7 +22,6 @@ import javax.annotation.PostConstruct; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.AutoConfigurationReportEndpoint.Report; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; @@ -66,8 +65,11 @@ public class AutoConfigurationReportEndpointTests @EnableConfigurationProperties public static class Config { - @Autowired - private ConfigurableApplicationContext context; + private final ConfigurableApplicationContext context; + + public Config(ConfigurableApplicationContext context) { + this.context = context; + } @PostConstruct public void setupAutoConfigurationReport() { diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/FlywayEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/FlywayEndpointTests.java index dec8bf933b..ffbfa5e5cd 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/FlywayEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/FlywayEndpointTests.java @@ -19,7 +19,6 @@ package org.springframework.boot.actuate.endpoint; import org.flywaydb.core.Flyway; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.context.annotation.Bean; @@ -48,12 +47,9 @@ public class FlywayEndpointTests extends AbstractEndpointTests { @Import({ EmbeddedDataSourceConfiguration.class, FlywayAutoConfiguration.class }) public static class Config { - @Autowired - private Flyway flyway; - @Bean - public FlywayEndpoint endpoint() { - return new FlywayEndpoint(this.flyway); + public FlywayEndpoint endpoint(Flyway flyway) { + return new FlywayEndpoint(flyway); } } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java index c39c159fd4..2acabaca03 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/LiquibaseEndpointTests.java @@ -19,7 +19,6 @@ package org.springframework.boot.actuate.endpoint; import liquibase.integration.spring.SpringLiquibase; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; import org.springframework.context.annotation.Bean; @@ -49,8 +48,11 @@ public class LiquibaseEndpointTests extends AbstractEndpointTests caches) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/HazelcastInstanceConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/HazelcastInstanceConfiguration.java index 84a018c73e..bc528d1aa3 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/HazelcastInstanceConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/HazelcastInstanceConfiguration.java @@ -23,7 +23,6 @@ import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.spring.cache.HazelcastCacheManager; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; import org.springframework.boot.autoconfigure.hazelcast.HazelcastConfigResourceCondition; @@ -45,11 +44,14 @@ abstract class HazelcastInstanceConfiguration { @ConditionalOnSingleCandidate(HazelcastInstance.class) static class Existing { - @Autowired - private CacheProperties cacheProperties; + private final CacheProperties cacheProperties; - @Autowired - private CacheManagerCustomizers customizers; + private final CacheManagerCustomizers customizers; + + Existing(CacheProperties cacheProperties, CacheManagerCustomizers customizers) { + this.cacheProperties = cacheProperties; + this.customizers = customizers; + } @Bean public HazelcastCacheManager cacheManager( @@ -72,11 +74,14 @@ abstract class HazelcastInstanceConfiguration { @Conditional(ConfigAvailableCondition.class) static class Specific { - @Autowired - private CacheProperties cacheProperties; + private final CacheProperties cacheProperties; - @Autowired - private CacheManagerCustomizers customizers; + private final CacheManagerCustomizers customizers; + + Specific(CacheProperties cacheProperties, CacheManagerCustomizers customizers) { + this.cacheProperties = cacheProperties; + this.customizers = customizers; + } @Bean public HazelcastInstance hazelcastInstance() throws IOException { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java index 4a052e5576..1132fac50a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java @@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.cache; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -43,11 +42,15 @@ import org.springframework.data.redis.core.RedisTemplate; @Conditional(CacheCondition.class) class RedisCacheConfiguration { - @Autowired - private CacheProperties cacheProperties; + private final CacheProperties cacheProperties; - @Autowired - private CacheManagerCustomizers customizerInvoker; + private final CacheManagerCustomizers customizerInvoker; + + RedisCacheConfiguration(CacheProperties cacheProperties, + CacheManagerCustomizers customizerInvoker) { + this.cacheProperties = cacheProperties; + this.customizerInvoker = customizerInvoker; + } @Bean public RedisCacheManager cacheManager(RedisTemplate redisTemplate) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/SimpleCacheConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/SimpleCacheConfiguration.java index d8c657170a..7f9554fdd3 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/SimpleCacheConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/SimpleCacheConfiguration.java @@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.cache; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.cache.CacheManager; import org.springframework.cache.concurrent.ConcurrentMapCacheManager; @@ -37,11 +36,15 @@ import org.springframework.context.annotation.Configuration; @Conditional(CacheCondition.class) class SimpleCacheConfiguration { - @Autowired - private CacheProperties cacheProperties; + private final CacheProperties cacheProperties; - @Autowired - private CacheManagerCustomizers customizerInvoker; + private final CacheManagerCustomizers customizerInvoker; + + SimpleCacheConfiguration(CacheProperties cacheProperties, + CacheManagerCustomizers customizerInvoker) { + this.cacheProperties = cacheProperties; + this.customizerInvoker = customizerInvoker; + } @Bean public ConcurrentMapCacheManager cacheManager() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java index 68b62ca5e2..00a13a7305 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java @@ -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. @@ -24,7 +24,6 @@ import com.datastax.driver.core.policies.ReconnectionPolicy; import com.datastax.driver.core.policies.RetryPolicy; import org.springframework.beans.BeanUtils; -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; @@ -45,8 +44,11 @@ import org.springframework.util.StringUtils; @EnableConfigurationProperties(CassandraProperties.class) public class CassandraAutoConfiguration { - @Autowired - private CassandraProperties properties; + private final CassandraProperties properties; + + public CassandraAutoConfiguration(CassandraProperties properties) { + this.properties = properties; + } @Bean @ConditionalOnMissingBean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java index e135dede73..be7c151173 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfiguration.java @@ -22,7 +22,6 @@ import javax.validation.Validator; import com.couchbase.client.java.CouchbaseBucket; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -62,8 +61,11 @@ public class CouchbaseAutoConfiguration { @ConditionalOnMissingBean(AbstractCouchbaseConfiguration.class) public static class CouchbaseConfiguration extends AbstractCouchbaseConfiguration { - @Autowired - private CouchbaseProperties properties; + private final CouchbaseProperties properties; + + public CouchbaseConfiguration(CouchbaseProperties properties) { + this.properties = properties; + } @Override protected List getBootstrapHosts() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java index de5ce3782d..65594fb3e2 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java @@ -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. @@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.data.cassandra; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Session; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; @@ -51,11 +50,15 @@ import org.springframework.data.cassandra.mapping.CassandraMappingContext; @AutoConfigureAfter(CassandraAutoConfiguration.class) public class CassandraDataAutoConfiguration { - @Autowired - private CassandraProperties properties; + private final CassandraProperties properties; - @Autowired - private Cluster cluster; + private final Cluster cluster; + + public CassandraDataAutoConfiguration(CassandraProperties properties, + Cluster cluster) { + this.properties = properties; + this.cluster = cluster; + } @Bean @ConditionalOnMissingBean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java index 17f4f35cc9..2e286cdd4b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ElasticsearchAutoConfiguration.java @@ -31,7 +31,6 @@ import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -69,11 +68,14 @@ public class ElasticsearchAutoConfiguration implements DisposableBean { private static final Log logger = LogFactory .getLog(ElasticsearchAutoConfiguration.class); - @Autowired - private ElasticsearchProperties properties; + private final ElasticsearchProperties properties; private Releasable releasable; + public ElasticsearchAutoConfiguration(ElasticsearchProperties properties) { + this.properties = properties; + } + @Bean @ConditionalOnMissingBean public Client elasticsearchClient() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.java index 77a5eccefa..44fcc070a2 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.java @@ -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. @@ -30,7 +30,6 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.boot.autoconfigure.AutoConfigurationPackages; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -87,17 +86,21 @@ import org.springframework.util.StringUtils; @AutoConfigureAfter(MongoAutoConfiguration.class) public class MongoDataAutoConfiguration implements BeanClassLoaderAware { - @Autowired - private MongoProperties properties; + private final MongoProperties properties; - @Autowired - private Environment environment; + private final Environment environment; - @Autowired - private ResourceLoader resourceLoader; + private final ResourceLoader resourceLoader; private ClassLoader classLoader; + public MongoDataAutoConfiguration(MongoProperties properties, Environment environment, + ResourceLoader resourceLoader) { + this.properties = properties; + this.environment = environment; + this.resourceLoader = resourceLoader; + } + @Override public void setBeanClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.java index 8fc5ba99bc..a14fe2a5f1 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.java @@ -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. @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.data.rest; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; @@ -33,8 +32,11 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguratio @Configuration class SpringBootRepositoryRestMvcConfiguration extends RepositoryRestMvcConfiguration { - @Autowired - private RepositoryRestProperties properties; + private final RepositoryRestProperties properties; + + SpringBootRepositoryRestMvcConfiguration(RepositoryRestProperties properties) { + this.properties = properties; + } @Bean @Override diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java index 825a683584..6022fd3441 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java @@ -66,11 +66,15 @@ public class FreeMarkerAutoConfiguration { private static final Log logger = LogFactory .getLog(FreeMarkerAutoConfiguration.class); - @Autowired - private ApplicationContext applicationContext; + private final ApplicationContext applicationContext; - @Autowired - private FreeMarkerProperties properties; + private final FreeMarkerProperties properties; + + public FreeMarkerAutoConfiguration(ApplicationContext applicationContext, + FreeMarkerProperties properties) { + this.applicationContext = applicationContext; + this.properties = properties; + } @PostConstruct public void checkTemplateLocationExists() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java index fa1e90db63..db1df79b67 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java @@ -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. @@ -137,8 +137,11 @@ public class GroovyTemplateAutoConfiguration { @ConditionalOnProperty(name = "spring.groovy.template.enabled", matchIfMissing = true) public static class GroovyWebConfiguration { - @Autowired - private GroovyTemplateProperties properties; + private final GroovyTemplateProperties properties; + + public GroovyWebConfiguration(GroovyTemplateProperties properties) { + this.properties = properties; + } @Bean @ConditionalOnMissingBean(name = "groovyMarkupViewResolver") diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java index 79f515d382..f96b8ebd2c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java @@ -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. @@ -51,8 +51,11 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur @AutoConfigureAfter(SecurityAutoConfiguration.class) public class H2ConsoleAutoConfiguration { - @Autowired - private H2ConsoleProperties properties; + private final H2ConsoleProperties properties; + + public H2ConsoleAutoConfiguration(H2ConsoleProperties properties) { + this.properties = properties; + } @Bean public ServletRegistrationBean h2Console() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfiguration.java index 8b1c9e8e74..0f94847239 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfiguration.java @@ -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. @@ -22,7 +22,6 @@ import com.hazelcast.config.Config; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; -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; @@ -53,8 +52,11 @@ public class HazelcastAutoConfiguration { @Conditional(ConfigAvailableCondition.class) static class HazelcastConfigFileConfiguration { - @Autowired - private HazelcastProperties hazelcastProperties; + private final HazelcastProperties hazelcastProperties; + + HazelcastConfigFileConfiguration(HazelcastProperties hazelcastProperties) { + this.hazelcastProperties = hazelcastProperties; + } @Bean public HazelcastInstance hazelcastInstance() throws IOException { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java index 95c8fe5141..346cc48a4c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java @@ -41,7 +41,6 @@ import org.joda.time.format.DateTimeFormat; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.ListableBeanFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnJava; import org.springframework.boot.autoconfigure.condition.ConditionalOnJava.JavaVersion; @@ -97,8 +96,11 @@ public class JacksonAutoConfiguration { private static final Log logger = LogFactory .getLog(JodaDateTimeJacksonConfiguration.class); - @Autowired - private JacksonProperties jacksonProperties; + private final JacksonProperties jacksonProperties; + + JodaDateTimeJacksonConfiguration(JacksonProperties jacksonProperties) { + this.jacksonProperties = jacksonProperties; + } @Bean public SimpleModule jodaDateTimeSerializationModule() { @@ -155,11 +157,15 @@ public class JacksonAutoConfiguration { @EnableConfigurationProperties(JacksonProperties.class) static class JacksonObjectMapperBuilderConfiguration { - @Autowired - private ApplicationContext applicationContext; + private final ApplicationContext applicationContext; - @Autowired - private JacksonProperties jacksonProperties; + private final JacksonProperties jacksonProperties; + + JacksonObjectMapperBuilderConfiguration(ApplicationContext applicationContext, + JacksonProperties jacksonProperties) { + this.applicationContext = applicationContext; + this.jacksonProperties = jacksonProperties; + } @Bean @ConditionalOnMissingBean(Jackson2ObjectMapperBuilder.class) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java index ac21ed129f..60bd9f2c6c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java @@ -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. @@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.jdbc; import javax.annotation.PreDestroy; import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -41,8 +40,11 @@ public class EmbeddedDataSourceConfiguration implements BeanClassLoaderAware { private ClassLoader classLoader; - @Autowired - private DataSourceProperties properties; + private final DataSourceProperties properties; + + public EmbeddedDataSourceConfiguration(DataSourceProperties properties) { + this.properties = properties; + } @Override public void setBeanClassLoader(ClassLoader classLoader) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfiguration.java index a46406dac8..871d156182 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfiguration.java @@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.jdbc; import javax.sql.DataSource; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -50,8 +49,11 @@ import org.springframework.jmx.support.JmxUtils; @EnableConfigurationProperties(DataSourceProperties.class) public class JndiDataSourceAutoConfiguration { - @Autowired - private ApplicationContext context; + private final ApplicationContext context; + + public JndiDataSourceAutoConfiguration(ApplicationContext context) { + this.context = context; + } @Bean(destroyMethod = "") @ConditionalOnMissingBean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java index de4640eb2a..9e5b32fb10 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 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. @@ -21,7 +21,6 @@ import java.util.Arrays; import javax.jms.ConnectionFactory; import javax.naming.NamingException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; @@ -56,8 +55,11 @@ public class JndiConnectionFactoryAutoConfiguration { private static String[] JNDI_LOCATIONS = { "java:/JmsXA", "java:/XAConnectionFactory" }; - @Autowired - private JmsProperties properties; + private final JmsProperties properties; + + public JndiConnectionFactoryAutoConfiguration(JmsProperties properties) { + this.properties = properties; + } @Bean public ConnectionFactory connectionFactory() throws NamingException { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java index a55e3110de..2096b8b4da 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java @@ -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. @@ -23,7 +23,6 @@ import javax.sql.DataSource; import liquibase.integration.spring.SpringLiquibase; import liquibase.servicelocator.ServiceLocator; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -39,7 +38,6 @@ import org.springframework.boot.liquibase.CommonsLoggingLiquibaseLogger; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; @@ -68,14 +66,18 @@ public class LiquibaseAutoConfiguration { @Import(LiquibaseJpaDependencyConfiguration.class) public static class LiquibaseConfiguration { - @Autowired - private LiquibaseProperties properties = new LiquibaseProperties(); + private final LiquibaseProperties properties; - @Autowired - private ResourceLoader resourceLoader = new DefaultResourceLoader(); + private final ResourceLoader resourceLoader; - @Autowired - private DataSource dataSource; + private final DataSource dataSource; + + public LiquibaseConfiguration(LiquibaseProperties properties, + ResourceLoader resourceLoader, DataSource dataSource) { + this.properties = properties; + this.resourceLoader = resourceLoader; + this.dataSource = dataSource; + } @PostConstruct public void checkChangelogExists() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/JndiSessionConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/JndiSessionConfiguration.java index dcd38e038c..366f01c253 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/JndiSessionConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/JndiSessionConfiguration.java @@ -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. @@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.mail; import javax.mail.Session; import javax.naming.NamingException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnJndi; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -40,8 +39,11 @@ import org.springframework.jndi.JndiLocatorDelegate; @ConditionalOnJndi class JndiSessionConfiguration { - @Autowired - private MailProperties properties; + private final MailProperties properties; + + JndiSessionConfiguration(MailProperties properties) { + this.properties = properties; + } @Bean @ConditionalOnMissingBean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderValidatorAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderValidatorAutoConfiguration.java index 77ad84abe8..1aecef7819 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderValidatorAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderValidatorAutoConfiguration.java @@ -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. @@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.mail; import javax.annotation.PostConstruct; import javax.mail.MessagingException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -41,8 +40,11 @@ import org.springframework.mail.javamail.JavaMailSenderImpl; @ConditionalOnSingleCandidate(JavaMailSenderImpl.class) public class MailSenderValidatorAutoConfiguration { - @Autowired - private JavaMailSenderImpl mailSender; + private final JavaMailSenderImpl mailSender; + + public MailSenderValidatorAutoConfiguration(JavaMailSenderImpl mailSender) { + this.mailSender = mailSender; + } @PostConstruct public void validateConnection() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverAutoConfiguration.java index 599405703d..12615b7576 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceDelegatingViewResolverAutoConfiguration.java @@ -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. @@ -98,8 +98,12 @@ public class DeviceDelegatingViewResolverAutoConfiguration { protected static class ThymeleafViewResolverViewResolverDelegateConfiguration extends AbstractDelegateConfiguration { - @Autowired - private ThymeleafViewResolver viewResolver; + private final ThymeleafViewResolver viewResolver; + + protected ThymeleafViewResolverViewResolverDelegateConfiguration( + ThymeleafViewResolver viewResolver) { + this.viewResolver = viewResolver; + } @Bean public LiteDeviceDelegatingViewResolver deviceDelegatingViewResolver() { @@ -120,8 +124,12 @@ public class DeviceDelegatingViewResolverAutoConfiguration { protected static class InternalResourceViewResolverDelegateConfiguration extends AbstractDelegateConfiguration { - @Autowired - private InternalResourceViewResolver viewResolver; + private final InternalResourceViewResolver viewResolver; + + protected InternalResourceViewResolverDelegateConfiguration( + InternalResourceViewResolver viewResolver) { + this.viewResolver = viewResolver; + } @Bean public LiteDeviceDelegatingViewResolver deviceDelegatingViewResolver() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceResolverAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceResolverAutoConfiguration.java index 8e7da6bcb4..a3cde4bc8b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceResolverAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/DeviceResolverAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 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. @@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.mobile; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -45,26 +44,34 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @ConditionalOnClass({ DeviceResolverHandlerInterceptor.class, DeviceHandlerMethodArgumentResolver.class }) @AutoConfigureAfter(WebMvcAutoConfiguration.class) +@ConditionalOnWebApplication public class DeviceResolverAutoConfiguration { + @Bean + @ConditionalOnMissingBean(DeviceResolverHandlerInterceptor.class) + public DeviceResolverHandlerInterceptor deviceResolverHandlerInterceptor() { + return new DeviceResolverHandlerInterceptor(); + } + + @Bean + public DeviceHandlerMethodArgumentResolver deviceHandlerMethodArgumentResolver() { + return new DeviceHandlerMethodArgumentResolver(); + } + @Configuration - @ConditionalOnWebApplication @Order(0) protected static class DeviceResolverMvcConfiguration extends WebMvcConfigurerAdapter { - @Autowired private DeviceResolverHandlerInterceptor deviceResolverHandlerInterceptor; - @Bean - @ConditionalOnMissingBean(DeviceResolverHandlerInterceptor.class) - public DeviceResolverHandlerInterceptor deviceResolverHandlerInterceptor() { - return new DeviceResolverHandlerInterceptor(); - } + private DeviceHandlerMethodArgumentResolver deviceHandlerMethodArgumentResolver; - @Bean - public DeviceHandlerMethodArgumentResolver deviceHandlerMethodArgumentResolver() { - return new DeviceHandlerMethodArgumentResolver(); + protected DeviceResolverMvcConfiguration( + DeviceResolverHandlerInterceptor deviceResolverHandlerInterceptor, + DeviceHandlerMethodArgumentResolver deviceHandlerMethodArgumentResolver) { + this.deviceResolverHandlerInterceptor = deviceResolverHandlerInterceptor; + this.deviceHandlerMethodArgumentResolver = deviceHandlerMethodArgumentResolver; } @Override @@ -75,7 +82,7 @@ public class DeviceResolverAutoConfiguration { @Override public void addArgumentResolvers( List argumentResolvers) { - argumentResolvers.add(deviceHandlerMethodArgumentResolver()); + argumentResolvers.add(this.deviceHandlerMethodArgumentResolver); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/SitePreferenceAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/SitePreferenceAutoConfiguration.java index 9d307082b3..23d61a01c9 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/SitePreferenceAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mobile/SitePreferenceAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 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. @@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.mobile; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -48,25 +47,33 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter SitePreferenceHandlerMethodArgumentResolver.class }) @AutoConfigureAfter(DeviceResolverAutoConfiguration.class) @ConditionalOnProperty(prefix = "spring.mobile.sitepreference", name = "enabled", havingValue = "true", matchIfMissing = true) +@ConditionalOnWebApplication public class SitePreferenceAutoConfiguration { + @Bean + @ConditionalOnMissingBean(SitePreferenceHandlerInterceptor.class) + public SitePreferenceHandlerInterceptor sitePreferenceHandlerInterceptor() { + return new SitePreferenceHandlerInterceptor(); + } + + @Bean + public SitePreferenceHandlerMethodArgumentResolver sitePreferenceHandlerMethodArgumentResolver() { + return new SitePreferenceHandlerMethodArgumentResolver(); + } + @Configuration - @ConditionalOnWebApplication protected static class SitePreferenceMvcConfiguration extends WebMvcConfigurerAdapter { - @Autowired - private SitePreferenceHandlerInterceptor sitePreferenceHandlerInterceptor; + private final SitePreferenceHandlerInterceptor sitePreferenceHandlerInterceptor; - @Bean - @ConditionalOnMissingBean(SitePreferenceHandlerInterceptor.class) - public SitePreferenceHandlerInterceptor sitePreferenceHandlerInterceptor() { - return new SitePreferenceHandlerInterceptor(); - } + private final SitePreferenceHandlerMethodArgumentResolver sitePreferenceHandlerMethodArgumentResolver; - @Bean - public SitePreferenceHandlerMethodArgumentResolver sitePreferenceHandlerMethodArgumentResolver() { - return new SitePreferenceHandlerMethodArgumentResolver(); + protected SitePreferenceMvcConfiguration( + SitePreferenceHandlerInterceptor sitePreferenceHandlerInterceptor, + org.springframework.mobile.device.site.SitePreferenceHandlerMethodArgumentResolver sitePreferenceHandlerMethodArgumentResolver) { + this.sitePreferenceHandlerInterceptor = sitePreferenceHandlerInterceptor; + this.sitePreferenceHandlerMethodArgumentResolver = sitePreferenceHandlerMethodArgumentResolver; } @Override @@ -77,7 +84,7 @@ public class SitePreferenceAutoConfiguration { @Override public void addArgumentResolvers( List argumentResolvers) { - argumentResolvers.add(sitePreferenceHandlerMethodArgumentResolver()); + argumentResolvers.add(this.sitePreferenceHandlerMethodArgumentResolver); } } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java index d80ea90c6a..d5ca090278 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java @@ -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. @@ -25,7 +25,6 @@ import com.samskivert.mustache.Mustache.TemplateLoader; 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; @@ -52,14 +51,18 @@ public class MustacheAutoConfiguration { private static final Log logger = LogFactory.getLog(MustacheAutoConfiguration.class); - @Autowired - private MustacheProperties mustache; + private final MustacheProperties mustache; - @Autowired - private Environment environment; + private final Environment environment; - @Autowired - private ApplicationContext applicationContext; + private final ApplicationContext applicationContext; + + public MustacheAutoConfiguration(MustacheProperties mustache, Environment environment, + ApplicationContext applicationContext) { + this.mustache = mustache; + this.environment = environment; + this.applicationContext = applicationContext; + } @PostConstruct public void checkTemplateLocationExists() { @@ -100,8 +103,11 @@ public class MustacheAutoConfiguration { @ConditionalOnWebApplication protected static class MustacheWebConfiguration { - @Autowired - private MustacheProperties mustache; + private final MustacheProperties mustache; + + protected MustacheWebConfiguration(MustacheProperties mustache) { + this.mustache = mustache; + } @Bean @ConditionalOnMissingBean(MustacheViewResolver.class) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java index c95df96277..10a1700583 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java @@ -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. @@ -25,7 +25,6 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; @@ -82,11 +81,15 @@ public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration { "org.hibernate.engine.transaction.jta.platform.internal.WebSphereExtendedJtaPlatform", "org.hibernate.service.jta.platform.internal.WebSphereExtendedJtaPlatform", }; - @Autowired - private JpaProperties properties; + private final JpaProperties properties; - @Autowired - private DataSource dataSource; + private final DataSource dataSource; + + public HibernateJpaAutoConfiguration(JpaProperties properties, + DataSource dataSource) { + this.properties = properties; + this.dataSource = dataSource; + } @Override protected AbstractJpaVendorAdapter createJpaVendorAdapter() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfiguration.java index fedfa3274a..4a6e853692 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfiguration.java @@ -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. @@ -191,9 +191,12 @@ public class SpringBootWebSecurityConfiguration { protected static class ApplicationWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter { - @Autowired private SecurityProperties security; + protected ApplicationWebSecurityConfigurerAdapter(SecurityProperties security) { + this.security = security; + } + @Override protected void configure(HttpSecurity http) throws Exception { if (this.security.isRequireSsl()) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfiguration.java index 8d5cbca47d..17a3f3b01d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfiguration.java @@ -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. @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.security.oauth2; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -49,8 +48,11 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @EnableConfigurationProperties(OAuth2ClientProperties.class) public class OAuth2AutoConfiguration { - @Autowired - private OAuth2ClientProperties credentials; + private final OAuth2ClientProperties credentials; + + public OAuth2AutoConfiguration(OAuth2ClientProperties credentials) { + this.credentials = credentials; + } @Bean public ResourceServerProperties resourceServerProperties() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java index 6ccd57ee88..32f492ec89 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/authserver/OAuth2AuthorizationServerConfiguration.java @@ -139,8 +139,11 @@ public class OAuth2AuthorizationServerConfiguration @Configuration protected static class ClientDetailsLogger { - @Autowired - private OAuth2ClientProperties credentials; + private final OAuth2ClientProperties credentials; + + protected ClientDetailsLogger(OAuth2ClientProperties credentials) { + this.credentials = credentials; + } @PostConstruct public void init() { @@ -158,8 +161,11 @@ public class OAuth2AuthorizationServerConfiguration @ConditionalOnMissingBean(BaseClientDetails.class) protected static class BaseClientDetailsConfiguration { - @Autowired - private OAuth2ClientProperties client; + private final OAuth2ClientProperties client; + + protected BaseClientDetailsConfiguration(OAuth2ClientProperties client) { + this.client = client; + } @Bean @ConfigurationProperties("security.oauth2.client") diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java index 6c67e5af76..bae44d9f45 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/OAuth2SsoDefaultConfiguration.java @@ -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. @@ -17,7 +17,6 @@ package org.springframework.boot.autoconfigure.security.oauth2.client; import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.security.SecurityProperties; @@ -45,11 +44,15 @@ import org.springframework.util.ClassUtils; public class OAuth2SsoDefaultConfiguration extends WebSecurityConfigurerAdapter implements Ordered { - @Autowired - BeanFactory beanFactory; + private final BeanFactory beanFactory; - @Autowired - OAuth2SsoProperties sso; + private final OAuth2SsoProperties sso; + + public OAuth2SsoDefaultConfiguration(BeanFactory beanFactory, + OAuth2SsoProperties sso) { + this.beanFactory = beanFactory; + this.sso = sso; + } @Override protected void configure(HttpSecurity http) throws Exception { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java index 9278530700..948f00a382 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/OAuth2ResourceServerConfiguration.java @@ -17,7 +17,6 @@ package org.springframework.boot.autoconfigure.security.oauth2.resource; import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionOutcome; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -64,8 +63,11 @@ import org.springframework.util.StringUtils; @Import(ResourceServerTokenServicesConfiguration.class) public class OAuth2ResourceServerConfiguration { - @Autowired - private ResourceServerProperties resource; + private final ResourceServerProperties resource; + + public OAuth2ResourceServerConfiguration(ResourceServerProperties resource) { + this.resource = resource; + } @Bean @ConditionalOnMissingBean(ResourceServerConfigurer.class) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java index 67c63bf307..19fd39cc81 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration.java @@ -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. @@ -142,8 +142,11 @@ public class ResourceServerTokenServicesConfiguration { @Conditional(TokenInfoCondition.class) protected static class TokenInfoServicesConfiguration { - @Autowired - private ResourceServerProperties resource; + private final ResourceServerProperties resource; + + protected TokenInfoServicesConfiguration(ResourceServerProperties resource) { + this.resource = resource; + } @Bean public RemoteTokenServices remoteTokenServices() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java index d3f91cfb48..9b8ab21e9c 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java @@ -20,7 +20,6 @@ import com.sendgrid.SendGrid; import org.apache.http.HttpHost; import org.apache.http.impl.client.HttpClientBuilder; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -44,8 +43,11 @@ import org.springframework.context.annotation.Configuration; @EnableConfigurationProperties(SendGridProperties.class) public class SendGridAutoConfiguration { - @Autowired - private SendGridProperties properties; + private final SendGridProperties properties; + + public SendGridAutoConfiguration(SendGridProperties properties) { + this.properties = properties; + } @Bean @ConditionalOnMissingBean(SendGrid.class) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java index 1e62c1a4c5..b26de37a33 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java @@ -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. @@ -16,9 +16,6 @@ package org.springframework.boot.autoconfigure.session; -import javax.annotation.PostConstruct; - -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -55,14 +52,18 @@ public class SessionAutoConfiguration { @Configuration public static class SessionRedisHttpConfiguration { - @Autowired - private ServerProperties serverProperties; + private final ServerProperties serverProperties; + + private final RedisOperationsSessionRepository sessionRepository; - @Autowired - private RedisOperationsSessionRepository sessionRepository; + public SessionRedisHttpConfiguration(ServerProperties serverProperties, + RedisOperationsSessionRepository sessionRepository) { + this.serverProperties = serverProperties; + this.sessionRepository = sessionRepository; + applyConfigurationProperties(); + } - @PostConstruct - public void applyConfigurationProperties() { + private void applyConfigurationProperties() { Integer timeout = this.serverProperties.getSession().getTimeout(); if (timeout != null) { this.sessionRepository.setDefaultMaxInactiveInterval(timeout); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/FacebookAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/FacebookAutoConfiguration.java index b888386cd4..f3c363e97e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/FacebookAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/FacebookAutoConfiguration.java @@ -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. @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.social; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -59,8 +58,11 @@ public class FacebookAutoConfiguration { @ConditionalOnWebApplication protected static class FacebookConfigurerAdapter extends SocialAutoConfigurerAdapter { - @Autowired - private FacebookProperties properties; + private final FacebookProperties properties; + + protected FacebookConfigurerAdapter(FacebookProperties properties) { + this.properties = properties; + } @Bean @ConditionalOnMissingBean(Facebook.class) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/LinkedInAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/LinkedInAutoConfiguration.java index e78d118c73..ef447937a2 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/LinkedInAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/LinkedInAutoConfiguration.java @@ -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. @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.social; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -59,8 +58,11 @@ public class LinkedInAutoConfiguration { @ConditionalOnWebApplication protected static class LinkedInConfigurerAdapter extends SocialAutoConfigurerAdapter { - @Autowired - private LinkedInProperties properties; + private final LinkedInProperties properties; + + protected LinkedInConfigurerAdapter(LinkedInProperties properties) { + this.properties = properties; + } @Bean @ConditionalOnMissingBean(LinkedIn.class) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/TwitterAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/TwitterAutoConfiguration.java index 9ba34139e4..ddd441fdca 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/TwitterAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/social/TwitterAutoConfiguration.java @@ -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. @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.social; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -60,8 +59,11 @@ public class TwitterAutoConfiguration { @ConditionalOnWebApplication protected static class TwitterConfigurerAdapter extends SocialAutoConfigurerAdapter { - @Autowired - private TwitterProperties properties; + private final TwitterProperties properties; + + protected TwitterConfigurerAdapter(TwitterProperties properties) { + this.properties = properties; + } @Bean @ConditionalOnMissingBean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java index 9ca7a6346d..03b6ff5dda 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java @@ -24,7 +24,6 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.CloudSolrClient; import org.apache.solr.client.solrj.impl.HttpSolrClient; -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; @@ -44,11 +43,14 @@ import org.springframework.util.StringUtils; @EnableConfigurationProperties(SolrProperties.class) public class SolrAutoConfiguration { - @Autowired - private SolrProperties properties; + private final SolrProperties properties; private SolrClient solrClient; + public SolrAutoConfiguration(SolrProperties properties) { + this.properties = properties; + } + @PreDestroy public void close() throws IOException { if (this.solrClient != null) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index 2189332b98..a564434d3a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -212,11 +212,15 @@ public class ThymeleafAutoConfiguration { @ConditionalOnWebApplication protected static class ThymeleafViewResolverConfiguration { - @Autowired - private ThymeleafProperties properties; + private final ThymeleafProperties properties; - @Autowired - private SpringTemplateEngine templateEngine; + private final SpringTemplateEngine templateEngine; + + protected ThymeleafViewResolverConfiguration(ThymeleafProperties properties, + SpringTemplateEngine templateEngine) { + this.properties = properties; + this.templateEngine = templateEngine; + } @Bean @ConditionalOnMissingBean(name = "thymeleafViewResolver") diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java index bfa9c29e97..58b05bb687 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java @@ -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. @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.transaction; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -43,8 +42,11 @@ import org.springframework.transaction.support.TransactionTemplate; DataSourceTransactionManagerAutoConfiguration.class }) public class TransactionAutoConfiguration { - @Autowired - private PlatformTransactionManager transactionManager; + private final PlatformTransactionManager transactionManager; + + public TransactionAutoConfiguration(PlatformTransactionManager transactionManager) { + this.transactionManager = transactionManager; + } @Bean @ConditionalOnMissingBean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java index 52926fdbff..bde242ed0b 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java @@ -27,7 +27,6 @@ import com.atomikos.icatch.config.UserTransactionService; import com.atomikos.icatch.config.UserTransactionServiceImp; import com.atomikos.icatch.jta.UserTransactionManager; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationHome; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -59,8 +58,11 @@ import org.springframework.util.StringUtils; @ConditionalOnMissingBean(PlatformTransactionManager.class) class AtomikosJtaConfiguration { - @Autowired - private JtaProperties jtaProperties; + private final JtaProperties jtaProperties; + + AtomikosJtaConfiguration(JtaProperties jtaProperties) { + this.jtaProperties = jtaProperties; + } @Bean(initMethod = "init", destroyMethod = "shutdownForce") @ConditionalOnMissingBean(UserTransactionService.class) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java index f7c6c89130..7d4580fc37 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java @@ -25,7 +25,6 @@ import bitronix.tm.BitronixTransactionManager; import bitronix.tm.TransactionManagerServices; import bitronix.tm.jndi.BitronixContext; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationHome; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -54,8 +53,11 @@ import org.springframework.util.StringUtils; @ConditionalOnMissingBean(PlatformTransactionManager.class) class BitronixJtaConfiguration { - @Autowired - private JtaProperties jtaProperties; + private final JtaProperties jtaProperties; + + BitronixJtaConfiguration(JtaProperties jtaProperties) { + this.jtaProperties = jtaProperties; + } @Bean @ConditionalOnMissingBean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration.java index 70a96a7e1e..da80f9eab0 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/velocity/VelocityAutoConfiguration.java @@ -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. @@ -64,11 +64,15 @@ public class VelocityAutoConfiguration { private static final Log logger = LogFactory.getLog(VelocityAutoConfiguration.class); - @Autowired - private ApplicationContext applicationContext; + private final ApplicationContext applicationContext; - @Autowired - private VelocityProperties properties; + private final VelocityProperties properties; + + public VelocityAutoConfiguration(ApplicationContext applicationContext, + VelocityProperties properties) { + this.applicationContext = applicationContext; + this.properties = properties; + } @PostConstruct public void checkTemplateLocationExists() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java index af29af485a..33be2ae800 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration.java @@ -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. @@ -27,7 +27,6 @@ import javax.servlet.http.HttpServletResponse; import org.springframework.aop.framework.autoproxy.AutoProxyUtils; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.autoconfigure.AutoConfigureBefore; @@ -77,8 +76,11 @@ import org.springframework.web.util.HtmlUtils; @Configuration public class ErrorMvcAutoConfiguration { - @Autowired - private ServerProperties properties; + private final ServerProperties properties; + + public ErrorMvcAutoConfiguration(ServerProperties properties) { + this.properties = properties; + } @Bean @ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfiguration.java index 06576e5ae2..f9076f0e17 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpEncodingAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 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. @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.web; -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; @@ -40,8 +39,11 @@ import org.springframework.web.filter.CharacterEncodingFilter; @ConditionalOnProperty(prefix = "spring.http.encoding", value = "enabled", matchIfMissing = true) public class HttpEncodingAutoConfiguration { - @Autowired - private HttpEncodingProperties httpEncodingProperties; + private final HttpEncodingProperties httpEncodingProperties; + + public HttpEncodingAutoConfiguration(HttpEncodingProperties httpEncodingProperties) { + this.httpEncodingProperties = httpEncodingProperties; + } @Bean @ConditionalOnMissingBean(CharacterEncodingFilter.class) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java index 8af0694779..4a9f70d690 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/HttpMessageConvertersAutoConfiguration.java @@ -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. @@ -68,8 +68,12 @@ public class HttpMessageConvertersAutoConfiguration { @EnableConfigurationProperties(HttpEncodingProperties.class) protected static class StringHttpMessageConverterConfiguration { - @Autowired - private HttpEncodingProperties encodingProperties; + private final HttpEncodingProperties encodingProperties; + + protected StringHttpMessageConverterConfiguration( + HttpEncodingProperties encodingProperties) { + this.encodingProperties = encodingProperties; + } @Bean @ConditionalOnMissingBean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java index 44f2eaee10..a54aa5aaf2 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java @@ -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. @@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.web; import javax.servlet.MultipartConfigElement; import javax.servlet.Servlet; -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; @@ -52,8 +51,11 @@ import org.springframework.web.servlet.DispatcherServlet; @EnableConfigurationProperties(MultipartProperties.class) public class MultipartAutoConfiguration { - @Autowired - private MultipartProperties multipartProperties = new MultipartProperties(); + private final MultipartProperties multipartProperties; + + public MultipartAutoConfiguration(MultipartProperties multipartProperties) { + this.multipartProperties = multipartProperties; + } @Bean @ConditionalOnMissingBean diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java index 133a01d98b..0fbaea52be 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java @@ -296,8 +296,11 @@ public class WebMvcAutoConfiguration { @ConditionalOnProperty(value = "spring.mvc.favicon.enabled", matchIfMissing = true) public static class FaviconConfiguration { - @Autowired - private ResourceProperties resourceProperties = new ResourceProperties(); + private final ResourceProperties resourceProperties; + + public FaviconConfiguration(ResourceProperties resourceProperties) { + this.resourceProperties = resourceProperties; + } @Bean public SimpleUrlHandlerMapping faviconHandlerMapping() { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfiguration.java index 3dbbda14f9..0dcdd8d289 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfiguration.java @@ -20,7 +20,6 @@ import java.util.List; import com.fasterxml.jackson.databind.ObjectMapper; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -58,8 +57,11 @@ public class WebSocketMessagingAutoConfiguration { static class WebSocketMessageConverterConfiguration extends AbstractWebSocketMessageBrokerConfigurer { - @Autowired - private ObjectMapper objectMapper; + private final ObjectMapper objectMapper; + + WebSocketMessageConverterConfiguration(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } @Override public void registerStompEndpoints(StompEndpointRegistry registry) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseTestConfiguration.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseTestConfiguration.java index 1e64a63d80..7291c9f8b5 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseTestConfiguration.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseTestConfiguration.java @@ -36,6 +36,10 @@ import static org.mockito.Mockito.mock; public class CouchbaseTestConfiguration extends CouchbaseAutoConfiguration.CouchbaseConfiguration { + public CouchbaseTestConfiguration(CouchbaseProperties properties) { + super(properties); + } + @Override public Cluster couchbaseCluster() throws Exception { return mock(CouchbaseCluster.class); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index 85e4a1bf72..af0ec689bc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -33,7 +33,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; @@ -266,8 +265,11 @@ public class FlywayAutoConfigurationTests { @Configuration protected static class CustomFlywayWithJpaConfiguration { - @Autowired - private DataSource dataSource; + private final DataSource dataSource; + + protected CustomFlywayWithJpaConfiguration(DataSource dataSource) { + this.dataSource = dataSource; + } @Bean public Flyway flyway() { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java index 2a9bbf5f18..1dced1f941 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java @@ -30,7 +30,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; @@ -291,8 +290,11 @@ public abstract class AbstractJpaAutoConfigurationTests { @TestAutoConfigurationPackage(AbstractJpaAutoConfigurationTests.class) public static class TestConfigurationWithCustomPersistenceUnitManager { - @Autowired - private DataSource dataSource; + private final DataSource dataSource; + + public TestConfigurationWithCustomPersistenceUnitManager(DataSource dataSource) { + this.dataSource = dataSource; + } @Bean public PersistenceUnitManager persistenceUnitManager() { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java index e5c9eaeb51..9b20775476 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java @@ -32,7 +32,6 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; import org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration; -import org.springframework.boot.autoconfigure.transaction.jta.JtaProperties; import org.springframework.boot.orm.jpa.hibernate.SpringJtaPlatform; import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.jdbc.core.JdbcTemplate; @@ -133,7 +132,7 @@ public class HibernateJpaAutoConfigurationTests @Test public void defaultJtaPlatform() throws Exception { - this.context.register(JtaProperties.class, JtaAutoConfiguration.class); + this.context.register(JtaAutoConfiguration.class); setupTestConfiguration(); this.context.refresh(); Map jpaPropertyMap = this.context @@ -148,7 +147,7 @@ public class HibernateJpaAutoConfigurationTests EnvironmentTestUtils.addEnvironment(this.context, "spring.jpa.properties.hibernate.transaction.jta.platform:" + TestJtaPlatform.class.getName()); - this.context.register(JtaProperties.class, JtaAutoConfiguration.class); + this.context.register(JtaAutoConfiguration.class); setupTestConfiguration(); this.context.refresh(); Map jpaPropertyMap = this.context diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java index 64115e8fa9..930a4c8b0b 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SecurityAutoConfigurationTests.java @@ -23,7 +23,6 @@ import javax.servlet.DispatcherType; import org.junit.After; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; @@ -442,8 +441,11 @@ public class SecurityAutoConfigurationTests { @Configuration protected static class SecurityCustomizer extends WebSecurityConfigurerAdapter { - @Autowired - AuthenticationManager authenticationManager; + final AuthenticationManager authenticationManager; + + protected SecurityCustomizer(AuthenticationManager authenticationManager) { + this.authenticationManager = authenticationManager; + } } @@ -451,12 +453,15 @@ public class SecurityAutoConfigurationTests { protected static class WorkaroundSecurityCustomizer extends WebSecurityConfigurerAdapter { - @Autowired - private AuthenticationManagerBuilder builder; + private final AuthenticationManagerBuilder builder; @SuppressWarnings("unused") private AuthenticationManager authenticationManager; + protected WorkaroundSecurityCustomizer(AuthenticationManagerBuilder builder) { + this.builder = builder; + } + @Override protected void configure(HttpSecurity http) throws Exception { this.authenticationManager = new AuthenticationManager() { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java index 7153cc8ae0..0719d65504 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/SpringBootWebSecurityConfigurationTests.java @@ -245,6 +245,8 @@ public class SpringBootWebSecurityConfigurationTests { protected static class TestInjectWebConfiguration extends WebSecurityConfigurerAdapter { + private final AuthenticationManagerBuilder auth; + // It's a bad idea to inject an AuthenticationManager into a // WebSecurityConfigurerAdapter because it can cascade early instantiation, // unless you explicitly want the Boot default AuthenticationManager. It's @@ -252,8 +254,9 @@ public class SpringBootWebSecurityConfigurationTests { // might even be necessary to wrap the builder in a lazy AuthenticationManager // (that calls getOrBuild() only when the AuthenticationManager is actually // called). - @Autowired - private AuthenticationManagerBuilder auth; + protected TestInjectWebConfiguration(AuthenticationManagerBuilder auth) { + this.auth = auth; + } @Override public void init(WebSecurity web) throws Exception { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java index d7efe38ac2..973cc48521 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/OAuth2AutoConfigurationTests.java @@ -469,8 +469,11 @@ public class OAuth2AutoConfigurationTests { @EnableResourceServer protected static class CustomResourceServer extends ResourceServerConfigurerAdapter { - @Autowired - private ResourceServerProperties config; + private final ResourceServerProperties config; + + protected CustomResourceServer(ResourceServerProperties config) { + this.config = config; + } @Override public void configure(ResourceServerSecurityConfigurer resources) @@ -493,8 +496,11 @@ public class OAuth2AutoConfigurationTests { protected static class CustomAuthorizationServer extends AuthorizationServerConfigurerAdapter { - @Autowired - private AuthenticationManager authenticationManager; + private final AuthenticationManager authenticationManager; + + protected CustomAuthorizationServer(AuthenticationManager authenticationManager) { + this.authenticationManager = authenticationManager; + } @Bean public TokenStore tokenStore() { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java index 128a38b9d0..6339f3b45e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfigurationTests.java @@ -23,7 +23,6 @@ import java.util.Map; import org.junit.After; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; @@ -242,9 +241,12 @@ public class ResourceServerTokenServicesConfigurationTests { @Configuration protected static class ResourceServerPropertiesConfiguration { - @Autowired private OAuth2ClientProperties credentials; + public ResourceServerPropertiesConfiguration(OAuth2ClientProperties credentials) { + this.credentials = credentials; + } + @Bean public ResourceServerProperties resourceServerProperties() { return new ResourceServerProperties(this.credentials.getClientId(), diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/user/SecurityConfig.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/user/SecurityConfig.java index d0642deb3c..d4379f6652 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/user/SecurityConfig.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/user/SecurityConfig.java @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.security.user; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.orm.jpa.EntityScan; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @@ -30,8 +29,11 @@ import org.springframework.security.config.annotation.method.configuration.Enabl @EnableJpaRepositories(basePackageClasses = User.class) public class SecurityConfig extends GlobalAuthenticationConfigurerAdapter { - @Autowired - protected UserRepository userRepository; + protected final UserRepository userRepository; + + public SecurityConfig(UserRepository userRepository) { + this.userRepository = userRepository; + } @Override public void init(AuthenticationManagerBuilder auth) throws Exception { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfigurationTests.java index 01cf4416a4..0378990fd2 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketMessagingAutoConfigurationTests.java @@ -124,8 +124,8 @@ public class WebSocketMessagingAutoConfigurationTests { private List getCustomizedConverters() { List customizedConverters = new ArrayList(); - WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration(); - ReflectionTestUtils.setField(configuration, "objectMapper", new ObjectMapper()); + WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration.WebSocketMessageConverterConfiguration( + new ObjectMapper()); configuration.configureMessageConverters(customizedConverters); return customizedConverters; } diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java index d97d76e218..c6e17e5a91 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java @@ -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 diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java index b694830832..ad7ae524bd 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/remote/client/RemoteClientConfiguration.java @@ -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(); diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileSystemWatcherTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileSystemWatcherTests.java index ee2685201b..645b269ca8 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileSystemWatcherTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileSystemWatcherTests.java @@ -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() { diff --git a/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/AggregateMetricsConfiguration.java b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/AggregateMetricsConfiguration.java index 2972cfb80f..ee78647461 100644 --- a/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/AggregateMetricsConfiguration.java +++ b/spring-boot-samples/spring-boot-sample-metrics-redis/src/main/java/sample/metrics/redis/AggregateMetricsConfiguration.java @@ -16,7 +16,6 @@ package sample.metrics.redis; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics; import org.springframework.boot.actuate.endpoint.PublicMetrics; import org.springframework.boot.actuate.metrics.aggregate.AggregateMetricReader; @@ -30,11 +29,15 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; @Configuration public class AggregateMetricsConfiguration { - @Autowired - private MetricExportProperties export; + private final MetricExportProperties export; - @Autowired - private RedisConnectionFactory connectionFactory; + private final RedisConnectionFactory connectionFactory; + + public AggregateMetricsConfiguration(MetricExportProperties export, + RedisConnectionFactory connectionFactory) { + this.export = export; + this.connectionFactory = connectionFactory; + } @Bean public PublicMetrics metricsAggregate() { diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java index a72a73de6f..6977807607 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java @@ -22,7 +22,6 @@ import java.nio.charset.Charset; import org.junit.After; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; @@ -168,8 +167,11 @@ public class EmbeddedServletContainerMvcIntegrationTests { @PropertySource("classpath:/org/springframework/boot/context/embedded/conf.properties") public static class AdvancedConfig { - @Autowired - private Environment env; + private final Environment env; + + public AdvancedConfig(Environment env) { + this.env = env; + } @Bean public EmbeddedServletContainerFactory containerFactory() { diff --git a/spring-boot/src/test/java/org/springframework/boot/orm/jpa/EntityScanTests.java b/spring-boot/src/test/java/org/springframework/boot/orm/jpa/EntityScanTests.java index 4cc595e6e8..01cdcfdb39 100644 --- a/spring-boot/src/test/java/org/springframework/boot/orm/jpa/EntityScanTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/orm/jpa/EntityScanTests.java @@ -24,7 +24,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.beans.BeansException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -170,8 +169,11 @@ public class EntityScanTests { @EntityScan("com.mycorp.entity") static class BeanPostProcessorConfiguration { - @Autowired - protected EntityManagerFactory entityManagerFactory; + protected final EntityManagerFactory entityManagerFactory; + + BeanPostProcessorConfiguration(EntityManagerFactory entityManagerFactory) { + this.entityManagerFactory = entityManagerFactory; + } @Bean public BeanPostProcessor beanPostProcessor() {