diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/amqp/RabbitHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/amqp/RabbitHealthIndicatorAutoConfiguration.java index 3c98818941b8..a2b0ccc49b04 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/amqp/RabbitHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/amqp/RabbitHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -49,17 +49,11 @@ public class RabbitHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map rabbitTemplates; - - public RabbitHealthIndicatorAutoConfiguration( - Map rabbitTemplates) { - this.rabbitTemplates = rabbitTemplates; - } - @Bean @ConditionalOnMissingBean(name = "rabbitHealthIndicator") - public HealthIndicator rabbitHealthIndicator() { - return createHealthIndicator(this.rabbitTemplates); + public HealthIndicator rabbitHealthIndicator( + Map rabbitTemplates) { + return createHealthIndicator(rabbitTemplates); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/audit/AuditAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/audit/AuditAutoConfiguration.java index a61eb01db5c9..d65aad3624b3 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/audit/AuditAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/audit/AuditAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -42,17 +42,11 @@ @Configuration public class AuditAutoConfiguration { - private final AuditEventRepository auditEventRepository; - - public AuditAutoConfiguration( - ObjectProvider auditEventRepository) { - this.auditEventRepository = auditEventRepository.getIfAvailable(); - } - @Bean @ConditionalOnMissingBean(AbstractAuditListener.class) - public AuditListener auditListener() throws Exception { - return new AuditListener(this.auditEventRepository); + public AuditListener auditListener( + ObjectProvider auditEventRepository) throws Exception { + return new AuditListener(auditEventRepository.getIfAvailable()); } @Bean diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthIndicatorAutoConfiguration.java index b104b1035ee1..c22c0c686a55 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -56,17 +56,11 @@ public class CassandraHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map cassandraOperations; - - public CassandraHealthIndicatorAutoConfiguration( - Map cassandraOperations) { - this.cassandraOperations = cassandraOperations; - } - @Bean @ConditionalOnMissingBean(name = "cassandraHealthIndicator") - public HealthIndicator cassandraHealthIndicator() { - return createHealthIndicator(this.cassandraOperations); + public HealthIndicator cassandraHealthIndicator( + Map cassandraOperations) { + return createHealthIndicator(cassandraOperations); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthIndicatorAutoConfiguration.java index 2cc7feca179f..68fdb29f917b 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cassandra/CassandraReactiveHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -53,17 +53,11 @@ public class CassandraReactiveHealthIndicatorAutoConfiguration extends CompositeReactiveHealthIndicatorConfiguration { - private final Map reactiveCassandraOperations; - - public CassandraReactiveHealthIndicatorAutoConfiguration( - Map reactiveCassandraOperations) { - this.reactiveCassandraOperations = reactiveCassandraOperations; - } - @Bean @ConditionalOnMissingBean(name = "cassandraReactiveHealthIndicator") - public ReactiveHealthIndicator cassandraHealthIndicator() { - return createHealthIndicator(this.reactiveCassandraOperations); + public ReactiveHealthIndicator cassandraHealthIndicator( + Map reactiveCassandraOperations) { + return createHealthIndicator(reactiveCassandraOperations); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfiguration.java index a604470c3acc..d8671c3c4771 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -72,12 +72,6 @@ @ConditionalOnCloudPlatform(CloudPlatform.CLOUD_FOUNDRY) public class ReactiveCloudFoundryActuatorAutoConfiguration { - private final ApplicationContext applicationContext; - - ReactiveCloudFoundryActuatorAutoConfiguration(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; - } - @Bean @ConditionalOnMissingBean @ConditionalOnEnabledEndpoint @@ -92,12 +86,13 @@ public CloudFoundryReactiveHealthEndpointWebExtension cloudFoundryReactiveHealth public CloudFoundryWebFluxEndpointHandlerMapping cloudFoundryWebFluxEndpointHandlerMapping( ParameterValueMapper parameterMapper, EndpointMediaTypes endpointMediaTypes, WebClient.Builder webClientBuilder, - ControllerEndpointsSupplier controllerEndpointsSupplier) { + ControllerEndpointsSupplier controllerEndpointsSupplier, + ApplicationContext applicationContext) { CloudFoundryWebEndpointDiscoverer endpointDiscoverer = new CloudFoundryWebEndpointDiscoverer( - this.applicationContext, parameterMapper, endpointMediaTypes, null, + applicationContext, parameterMapper, endpointMediaTypes, null, Collections.emptyList(), Collections.emptyList()); CloudFoundrySecurityInterceptor securityInterceptor = getSecurityInterceptor( - webClientBuilder, this.applicationContext.getEnvironment()); + webClientBuilder, applicationContext.getEnvironment()); Collection webEndpoints = endpointDiscoverer.getEndpoints(); List> allEndpoints = new ArrayList<>(); allEndpoints.addAll(webEndpoints); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java index e9467bf8bdf9..ad12b24ba8a2 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryActuatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -76,12 +76,6 @@ @ConditionalOnCloudPlatform(CloudPlatform.CLOUD_FOUNDRY) public class CloudFoundryActuatorAutoConfiguration { - private final ApplicationContext applicationContext; - - CloudFoundryActuatorAutoConfiguration(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; - } - @Bean @ConditionalOnMissingBean @ConditionalOnEnabledEndpoint @@ -96,12 +90,13 @@ public CloudFoundryWebEndpointServletHandlerMapping cloudFoundryWebEndpointServl ParameterValueMapper parameterMapper, EndpointMediaTypes endpointMediaTypes, RestTemplateBuilder restTemplateBuilder, ServletEndpointsSupplier servletEndpointsSupplier, - ControllerEndpointsSupplier controllerEndpointsSupplier) { + ControllerEndpointsSupplier controllerEndpointsSupplier, + ApplicationContext applicationContext) { CloudFoundryWebEndpointDiscoverer discoverer = new CloudFoundryWebEndpointDiscoverer( - this.applicationContext, parameterMapper, endpointMediaTypes, null, + applicationContext, parameterMapper, endpointMediaTypes, null, Collections.emptyList(), Collections.emptyList()); CloudFoundrySecurityInterceptor securityInterceptor = getSecurityInterceptor( - restTemplateBuilder, this.applicationContext.getEnvironment()); + restTemplateBuilder, applicationContext.getEnvironment()); Collection webEndpoints = discoverer.getEndpoints(); List> allEndpoints = new ArrayList<>(); allEndpoints.addAll(webEndpoints); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java index d157b4720f50..688dd1b6b642 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/context/properties/ConfigurationPropertiesReportEndpointAutoConfiguration.java @@ -37,18 +37,12 @@ @EnableConfigurationProperties(ConfigurationPropertiesReportEndpointProperties.class) public class ConfigurationPropertiesReportEndpointAutoConfiguration { - private final ConfigurationPropertiesReportEndpointProperties properties; - - public ConfigurationPropertiesReportEndpointAutoConfiguration( - ConfigurationPropertiesReportEndpointProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean - public ConfigurationPropertiesReportEndpoint configurationPropertiesReportEndpoint() { + public ConfigurationPropertiesReportEndpoint configurationPropertiesReportEndpoint( + ConfigurationPropertiesReportEndpointProperties properties) { ConfigurationPropertiesReportEndpoint endpoint = new ConfigurationPropertiesReportEndpoint(); - String[] keysToSanitize = this.properties.getKeysToSanitize(); + String[] keysToSanitize = properties.getKeysToSanitize(); if (keysToSanitize != null) { endpoint.setKeysToSanitize(keysToSanitize); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfiguration.java index cc1c2b839b4a..ca2a690c3f27 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -52,16 +52,10 @@ public class CouchbaseHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map clusters; - - public CouchbaseHealthIndicatorAutoConfiguration(Map clusters) { - this.clusters = clusters; - } - @Bean @ConditionalOnMissingBean(name = "couchbaseHealthIndicator") - public HealthIndicator couchbaseHealthIndicator() { - return createHealthIndicator(this.clusters); + public HealthIndicator couchbaseHealthIndicator(Map clusters) { + return createHealthIndicator(clusters); } @Override diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfiguration.java index 28d953ffdef8..59d890a366ee 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/couchbase/CouchbaseReactiveHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -52,17 +52,11 @@ public class CouchbaseReactiveHealthIndicatorAutoConfiguration extends CompositeReactiveHealthIndicatorConfiguration { - private final Map clusters; - - public CouchbaseReactiveHealthIndicatorAutoConfiguration( - Map clusters) { - this.clusters = clusters; - } - @Bean @ConditionalOnMissingBean(name = "couchbaseReactiveHealthIndicator") - public ReactiveHealthIndicator couchbaseReactiveHealthIndicator() { - return createHealthIndicator(this.clusters); + public ReactiveHealthIndicator couchbaseReactiveHealthIndicator( + Map clusters) { + return createHealthIndicator(clusters); } @Override diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchClientHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchClientHealthIndicatorAutoConfiguration.java index 146132fbf472..da3642e65c0d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchClientHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchClientHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -54,21 +54,17 @@ public class ElasticSearchClientHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map clients; - private final ElasticsearchHealthIndicatorProperties properties; public ElasticSearchClientHealthIndicatorAutoConfiguration( - Map clients, ElasticsearchHealthIndicatorProperties properties) { - this.clients = clients; this.properties = properties; } @Bean @ConditionalOnMissingBean(name = "elasticsearchHealthIndicator") - public HealthIndicator elasticsearchHealthIndicator() { - return createHealthIndicator(this.clients); + public HealthIndicator elasticsearchHealthIndicator(Map clients) { + return createHealthIndicator(clients); } @Override diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchJestHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchJestHealthIndicatorAutoConfiguration.java index 77324a5828f0..27717ce674ef 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchJestHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchJestHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -53,17 +53,10 @@ public class ElasticSearchJestHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map clients; - - public ElasticSearchJestHealthIndicatorAutoConfiguration( - Map clients) { - this.clients = clients; - } - @Bean @ConditionalOnMissingBean(name = "elasticsearchHealthIndicator") - public HealthIndicator elasticsearchHealthIndicator() { - return createHealthIndicator(this.clients); + public HealthIndicator elasticsearchHealthIndicator(Map clients) { + return createHealthIndicator(clients); } @Override diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchRestHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchRestHealthIndicatorAutoConfiguration.java index edfee5e5ed4c..409c3666683c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchRestHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchRestHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -53,17 +53,11 @@ public class ElasticSearchRestHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map clients; - - public ElasticSearchRestHealthIndicatorAutoConfiguration( - Map clients) { - this.clients = clients; - } - @Bean @ConditionalOnMissingBean(name = "elasticsearchRestHealthIndicator") - public HealthIndicator elasticsearchRestHealthIndicator() { - return createHealthIndicator(this.clients); + public HealthIndicator elasticsearchRestHealthIndicator( + Map clients) { + return createHealthIndicator(clients); } @Override diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java index b4ba124b1432..29350857df09 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -29,7 +29,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath; import org.springframework.boot.autoconfigure.web.servlet.JerseyApplicationPath; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.DispatcherServlet; @@ -58,19 +57,11 @@ public ExposeExcludePropertyEndpointFilter servletExpo @ConditionalOnClass(DispatcherServlet.class) public static class WebMvcServletEndpointManagementContextConfiguration { - private final ApplicationContext context; - - public WebMvcServletEndpointManagementContextConfiguration( - ApplicationContext context) { - this.context = context; - } - @Bean public ServletEndpointRegistrar servletEndpointRegistrar( WebEndpointProperties properties, - ServletEndpointsSupplier servletEndpointsSupplier) { - DispatcherServletPath dispatcherServletPath = this.context - .getBean(DispatcherServletPath.class); + ServletEndpointsSupplier servletEndpointsSupplier, + DispatcherServletPath dispatcherServletPath) { return new ServletEndpointRegistrar( dispatcherServletPath.getRelativePath(properties.getBasePath()), servletEndpointsSupplier.getEndpoints()); @@ -83,19 +74,11 @@ public ServletEndpointRegistrar servletEndpointRegistrar( @ConditionalOnMissingClass("org.springframework.web.servlet.DispatcherServlet") public static class JerseyServletEndpointManagementContextConfiguration { - private final ApplicationContext context; - - public JerseyServletEndpointManagementContextConfiguration( - ApplicationContext context) { - this.context = context; - } - @Bean public ServletEndpointRegistrar servletEndpointRegistrar( WebEndpointProperties properties, - ServletEndpointsSupplier servletEndpointsSupplier) { - JerseyApplicationPath jerseyApplicationPath = this.context - .getBean(JerseyApplicationPath.class); + ServletEndpointsSupplier servletEndpointsSupplier, + JerseyApplicationPath jerseyApplicationPath) { return new ServletEndpointRegistrar( jerseyApplicationPath.getRelativePath(properties.getBasePath()), servletEndpointsSupplier.getEndpoints()); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java index b6634c403e07..c01ee64577ca 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/env/EnvironmentEndpointAutoConfiguration.java @@ -39,18 +39,12 @@ @EnableConfigurationProperties(EnvironmentEndpointProperties.class) public class EnvironmentEndpointAutoConfiguration { - private final EnvironmentEndpointProperties properties; - - public EnvironmentEndpointAutoConfiguration( - EnvironmentEndpointProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean - public EnvironmentEndpoint environmentEndpoint(Environment environment) { + public EnvironmentEndpoint environmentEndpoint(Environment environment, + EnvironmentEndpointProperties properties) { EnvironmentEndpoint endpoint = new EnvironmentEndpoint(environment); - String[] keysToSanitize = this.properties.getKeysToSanitize(); + String[] keysToSanitize = properties.getKeysToSanitize(); if (keysToSanitize != null) { endpoint.setKeysToSanitize(keysToSanitize); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionConfiguration.java index 1c9d625d8343..3bd683bfe587 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionConfiguration.java @@ -26,7 +26,6 @@ import org.springframework.boot.actuate.health.HealthWebEndpointResponseMapper; import org.springframework.boot.actuate.health.OrderedHealthAggregator; import org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension; -import org.springframework.boot.actuate.health.ReactiveHealthIndicator; import org.springframework.boot.actuate.health.ReactiveHealthIndicatorRegistry; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -72,21 +71,17 @@ public HealthWebEndpointResponseMapper healthWebEndpointResponseMapper( @ConditionalOnEnabledEndpoint(endpoint = HealthEndpoint.class) static class ReactiveWebHealthConfiguration { - private final ReactiveHealthIndicator reactiveHealthIndicator; - - ReactiveWebHealthConfiguration(ObjectProvider healthAggregator, - ReactiveHealthIndicatorRegistry registry) { - this.reactiveHealthIndicator = new CompositeReactiveHealthIndicator( - healthAggregator.getIfAvailable(OrderedHealthAggregator::new), - registry); - } - @Bean @ConditionalOnMissingBean @ConditionalOnBean(HealthEndpoint.class) public ReactiveHealthEndpointWebExtension reactiveHealthEndpointWebExtension( + ObjectProvider healthAggregator, + ReactiveHealthIndicatorRegistry registry, HealthWebEndpointResponseMapper responseMapper) { - return new ReactiveHealthEndpointWebExtension(this.reactiveHealthIndicator, + return new ReactiveHealthEndpointWebExtension( + new CompositeReactiveHealthIndicator( + healthAggregator.getIfAvailable(OrderedHealthAggregator::new), + registry), responseMapper); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java index 7d1388400427..a8687d4c6014 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.java @@ -49,12 +49,6 @@ @EnableConfigurationProperties({ HealthIndicatorProperties.class }) public class HealthIndicatorAutoConfiguration { - private final HealthIndicatorProperties properties; - - public HealthIndicatorAutoConfiguration(HealthIndicatorProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean({ HealthIndicator.class, ReactiveHealthIndicator.class }) public ApplicationHealthIndicator applicationHealthIndicator() { @@ -63,10 +57,11 @@ public ApplicationHealthIndicator applicationHealthIndicator() { @Bean @ConditionalOnMissingBean(HealthAggregator.class) - public OrderedHealthAggregator healthAggregator() { + public OrderedHealthAggregator healthAggregator( + HealthIndicatorProperties properties) { OrderedHealthAggregator healthAggregator = new OrderedHealthAggregator(); - if (this.properties.getOrder() != null) { - healthAggregator.setStatusOrder(this.properties.getOrder()); + if (properties.getOrder() != null) { + healthAggregator.setStatusOrder(properties.getOrder()); } return healthAggregator; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/influx/InfluxDbHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/influx/InfluxDbHealthIndicatorAutoConfiguration.java index a122ce3f628b..8ffdffeaf29d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/influx/InfluxDbHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/influx/InfluxDbHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -50,16 +50,10 @@ public class InfluxDbHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map influxDbs; - - public InfluxDbHealthIndicatorAutoConfiguration(Map influxDbs) { - this.influxDbs = influxDbs; - } - @Bean @ConditionalOnMissingBean(name = "influxDbHealthIndicator") - public HealthIndicator influxDbHealthIndicator() { - return createHealthIndicator(this.influxDbs); + public HealthIndicator influxDbHealthIndicator(Map influxDbs) { + return createHealthIndicator(influxDbs); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java index 412f9d5853e3..5c038d233fa8 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthIndicatorAutoConfiguration.java @@ -66,19 +66,28 @@ public class DataSourceHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration implements InitializingBean { - private final Map dataSources; - private final Collection metadataProviders; private DataSourcePoolMetadataProvider poolMetadataProvider; public DataSourceHealthIndicatorAutoConfiguration(Map dataSources, ObjectProvider metadataProviders) { - this.dataSources = filterDataSources(dataSources); this.metadataProviders = metadataProviders.orderedStream() .collect(Collectors.toList()); } + @Override + public void afterPropertiesSet() throws Exception { + this.poolMetadataProvider = new CompositeDataSourcePoolMetadataProvider( + this.metadataProviders); + } + + @Bean + @ConditionalOnMissingBean(name = "dbHealthIndicator") + public HealthIndicator dbHealthIndicator(Map dataSources) { + return createHealthIndicator(filterDataSources(dataSources)); + } + private Map filterDataSources( Map candidates) { if (candidates == null) { @@ -93,18 +102,6 @@ private Map filterDataSources( return dataSources; } - @Override - public void afterPropertiesSet() throws Exception { - this.poolMetadataProvider = new CompositeDataSourcePoolMetadataProvider( - this.metadataProviders); - } - - @Bean - @ConditionalOnMissingBean(name = "dbHealthIndicator") - public HealthIndicator dbHealthIndicator() { - return createHealthIndicator(this.dataSources); - } - @Override protected DataSourceHealthIndicator createHealthIndicator(DataSource source) { return new DataSourceHealthIndicator(source, getValidationQuery(source)); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jms/JmsHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jms/JmsHealthIndicatorAutoConfiguration.java index bee662480baf..3af7007ee4dc 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jms/JmsHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jms/JmsHealthIndicatorAutoConfiguration.java @@ -51,17 +51,11 @@ public class JmsHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map connectionFactories; - - public JmsHealthIndicatorAutoConfiguration( - Map connectionFactories) { - this.connectionFactories = connectionFactories; - } - @Bean @ConditionalOnMissingBean(name = "jmsHealthIndicator") - public HealthIndicator jmsHealthIndicator() { - return createHealthIndicator(this.connectionFactories); + public HealthIndicator jmsHealthIndicator( + Map connectionFactories) { + return createHealthIndicator(connectionFactories); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/ldap/LdapHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/ldap/LdapHealthIndicatorAutoConfiguration.java index 2a53cf98cd18..a6551f684e14 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/ldap/LdapHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/ldap/LdapHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -50,17 +50,11 @@ public class LdapHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map ldapOperations; - - public LdapHealthIndicatorAutoConfiguration( - Map ldapOperations) { - this.ldapOperations = ldapOperations; - } - @Bean @ConditionalOnMissingBean(name = "ldapHealthIndicator") - public HealthIndicator ldapHealthIndicator() { - return createHealthIndicator(this.ldapOperations); + public HealthIndicator ldapHealthIndicator( + Map ldapOperations) { + return createHealthIndicator(ldapOperations); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java index 54b0226bf35d..0ad9493e4bda 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -43,17 +43,12 @@ @EnableConfigurationProperties(LogFileWebEndpointProperties.class) public class LogFileWebEndpointAutoConfiguration { - private final LogFileWebEndpointProperties properties; - - public LogFileWebEndpointAutoConfiguration(LogFileWebEndpointProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean @Conditional(LogFileCondition.class) - public LogFileWebEndpoint logFileWebEndpoint(Environment environment) { - return new LogFileWebEndpoint(environment, this.properties.getExternalFile()); + public LogFileWebEndpoint logFileWebEndpoint(Environment environment, + LogFileWebEndpointProperties properties) { + return new LogFileWebEndpoint(environment, properties.getExternalFile()); } private static class LogFileCondition extends SpringBootCondition { diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mail/MailHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mail/MailHealthIndicatorAutoConfiguration.java index 564ddf082b76..4c18df9667da 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mail/MailHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mail/MailHealthIndicatorAutoConfiguration.java @@ -49,17 +49,11 @@ public class MailHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map mailSenders; - - public MailHealthIndicatorAutoConfiguration( - Map mailSenders) { - this.mailSenders = mailSenders; - } - @Bean @ConditionalOnMissingBean(name = "mailHealthIndicator") - public HealthIndicator mailHealthIndicator() { - return createHealthIndicator(this.mailSenders); + public HealthIndicator mailHealthIndicator( + Map mailSenders) { + return createHealthIndicator(mailSenders); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java index f0ca9fbaf593..e38a4ba1ca79 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/jdbc/DataSourcePoolMetricsAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,9 @@ import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.sql.DataSource; @@ -28,6 +30,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; @@ -62,25 +65,22 @@ static class DataSourcePoolMetadataMetricsConfiguration { private static final String DATASOURCE_SUFFIX = "dataSource"; - private final MeterRegistry registry; - - private final Collection metadataProviders; - - DataSourcePoolMetadataMetricsConfiguration(MeterRegistry registry, - Collection metadataProviders) { - this.registry = registry; - this.metadataProviders = metadataProviders; - } - @Autowired - public void bindDataSourcesToRegistry(Map dataSources) { - dataSources.forEach(this::bindDataSourceToRegistry); + public void bindDataSourcesToRegistry(Map dataSources, + MeterRegistry registry, + ObjectProvider metadataProviders) { + List metadataProvidersList = metadataProviders + .stream().collect(Collectors.toList()); + dataSources.forEach((name, dataSource) -> bindDataSourceToRegistry(name, + dataSource, metadataProvidersList, registry)); } - private void bindDataSourceToRegistry(String beanName, DataSource dataSource) { + private void bindDataSourceToRegistry(String beanName, DataSource dataSource, + Collection metadataProviders, + MeterRegistry registry) { String dataSourceName = getDataSourceName(beanName); - new DataSourcePoolMetrics(dataSource, this.metadataProviders, dataSourceName, - Collections.emptyList()).bindTo(this.registry); + new DataSourcePoolMetrics(dataSource, metadataProviders, dataSourceName, + Collections.emptyList()).bindTo(registry); } /** diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/orm/jpa/HibernateMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/orm/jpa/HibernateMetricsAutoConfiguration.java index 68c6c5122da5..d40bb226602f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/orm/jpa/HibernateMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/orm/jpa/HibernateMetricsAutoConfiguration.java @@ -54,23 +54,19 @@ public class HibernateMetricsAutoConfiguration { private static final String ENTITY_MANAGER_FACTORY_SUFFIX = "entityManagerFactory"; - private final MeterRegistry registry; - - public HibernateMetricsAutoConfiguration(MeterRegistry registry) { - this.registry = registry; - } - @Autowired public void bindEntityManagerFactoriesToRegistry( - Map entityManagerFactories) { - entityManagerFactories.forEach(this::bindEntityManagerFactoryToRegistry); + Map entityManagerFactories, + MeterRegistry registry) { + entityManagerFactories.forEach((name, + factory) -> bindEntityManagerFactoryToRegistry(name, factory, registry)); } private void bindEntityManagerFactoryToRegistry(String beanName, - EntityManagerFactory entityManagerFactory) { + EntityManagerFactory entityManagerFactory, MeterRegistry registry) { String entityManagerFactoryName = getEntityManagerFactoryName(beanName); new HibernateMetrics(entityManagerFactory, entityManagerFactoryName, - Collections.emptyList()).bindTo(this.registry); + Collections.emptyList()).bindTo(registry); } /** diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/HttpClientMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/HttpClientMetricsAutoConfiguration.java index b536805b0e2b..9fbf39b69062 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/HttpClientMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/HttpClientMetricsAutoConfiguration.java @@ -50,21 +50,15 @@ @Import({ RestTemplateMetricsConfiguration.class, WebClientMetricsConfiguration.class }) public class HttpClientMetricsAutoConfiguration { - private final MetricsProperties properties; - - public HttpClientMetricsAutoConfiguration(MetricsProperties properties) { - this.properties = properties; - } - @Bean @Order(0) - public MeterFilter metricsHttpClientUriTagFilter() { - String metricName = this.properties.getWeb().getClient().getRequestsMetricName(); + public MeterFilter metricsHttpClientUriTagFilter(MetricsProperties properties) { + String metricName = properties.getWeb().getClient().getRequestsMetricName(); MeterFilter denyFilter = new OnlyOnceLoggingDenyMeterFilter(() -> String .format("Reached the maximum number of URI tags for '%s'. Are you using " + "'uriVariables'?", metricName)); return MeterFilter.maximumAllowableTags(metricName, "uri", - this.properties.getWeb().getClient().getMaxUriTags(), denyFilter); + properties.getWeb().getClient().getMaxUriTags(), denyFilter); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfiguration.java index 1ae7929704a7..d97102ac15b2 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/web/client/RestTemplateMetricsConfiguration.java @@ -42,12 +42,6 @@ @ConditionalOnBean(RestTemplateBuilder.class) class RestTemplateMetricsConfiguration { - private final MetricsProperties properties; - - RestTemplateMetricsConfiguration(MetricsProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean(RestTemplateExchangeTagsProvider.class) public DefaultRestTemplateExchangeTagsProvider restTemplateExchangeTagsProvider() { @@ -57,10 +51,11 @@ public DefaultRestTemplateExchangeTagsProvider restTemplateExchangeTagsProvider( @Bean public MetricsRestTemplateCustomizer metricsRestTemplateCustomizer( MeterRegistry meterRegistry, - RestTemplateExchangeTagsProvider restTemplateExchangeTagsProvider) { + RestTemplateExchangeTagsProvider restTemplateExchangeTagsProvider, + MetricsProperties properties) { return new MetricsRestTemplateCustomizer(meterRegistry, restTemplateExchangeTagsProvider, - this.properties.getWeb().getClient().getRequestsMetricName()); + properties.getWeb().getClient().getRequestsMetricName()); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mongo/MongoHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mongo/MongoHealthIndicatorAutoConfiguration.java index 4c136167f36c..7921fff29aca 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mongo/MongoHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mongo/MongoHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,16 +51,11 @@ public class MongoHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map mongoTemplates; - - MongoHealthIndicatorAutoConfiguration(Map mongoTemplates) { - this.mongoTemplates = mongoTemplates; - } - @Bean @ConditionalOnMissingBean(name = "mongoHealthIndicator") - public HealthIndicator mongoHealthIndicator() { - return createHealthIndicator(this.mongoTemplates); + public HealthIndicator mongoHealthIndicator( + Map mongoTemplates) { + return createHealthIndicator(mongoTemplates); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mongo/MongoReactiveHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mongo/MongoReactiveHealthIndicatorAutoConfiguration.java index f70f10c7cde0..b9ba5f58ecec 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mongo/MongoReactiveHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/mongo/MongoReactiveHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -52,17 +52,11 @@ public class MongoReactiveHealthIndicatorAutoConfiguration extends CompositeReactiveHealthIndicatorConfiguration { - private final Map reactiveMongoTemplate; - - MongoReactiveHealthIndicatorAutoConfiguration( - Map reactiveMongoTemplate) { - this.reactiveMongoTemplate = reactiveMongoTemplate; - } - @Bean @ConditionalOnMissingBean(name = "mongoHealthIndicator") - public ReactiveHealthIndicator mongoHealthIndicator() { - return createHealthIndicator(this.reactiveMongoTemplate); + public ReactiveHealthIndicator mongoHealthIndicator( + Map reactiveMongoTemplates) { + return createHealthIndicator(reactiveMongoTemplates); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/neo4j/Neo4jHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/neo4j/Neo4jHealthIndicatorAutoConfiguration.java index 9962fb5779d2..bb9459da318e 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/neo4j/Neo4jHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/neo4j/Neo4jHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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,17 +51,11 @@ public class Neo4jHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map sessionFactories; - - public Neo4jHealthIndicatorAutoConfiguration( - Map sessionFactories) { - this.sessionFactories = sessionFactories; - } - @Bean @ConditionalOnMissingBean(name = "neo4jHealthIndicator") - public HealthIndicator neo4jHealthIndicator() { - return createHealthIndicator(this.sessionFactories); + public HealthIndicator neo4jHealthIndicator( + Map sessionFactories) { + return createHealthIndicator(sessionFactories); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/redis/RedisHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/redis/RedisHealthIndicatorAutoConfiguration.java index 4c188792b043..72370028dd4d 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/redis/RedisHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/redis/RedisHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -53,17 +53,11 @@ public class RedisHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map redisConnectionFactories; - - public RedisHealthIndicatorAutoConfiguration( - Map redisConnectionFactories) { - this.redisConnectionFactories = redisConnectionFactories; - } - @Bean @ConditionalOnMissingBean(name = "redisHealthIndicator") - public HealthIndicator redisHealthIndicator() { - return createHealthIndicator(this.redisConnectionFactories); + public HealthIndicator redisHealthIndicator( + Map redisConnectionFactories) { + return createHealthIndicator(redisConnectionFactories); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/solr/SolrHealthIndicatorAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/solr/SolrHealthIndicatorAutoConfiguration.java index 90ee7ba25eec..24b66e839fd6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/solr/SolrHealthIndicatorAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/solr/SolrHealthIndicatorAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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,16 +51,10 @@ public class SolrHealthIndicatorAutoConfiguration extends CompositeHealthIndicatorConfiguration { - private final Map solrClients; - - public SolrHealthIndicatorAutoConfiguration(Map solrClients) { - this.solrClients = solrClients; - } - @Bean @ConditionalOnMissingBean(name = "solrHealthIndicator") - public HealthIndicator solrHealthIndicator() { - return createHealthIndicator(this.solrClients); + public HealthIndicator solrHealthIndicator(Map solrClients) { + return createHealthIndicator(solrClients); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java index 0ad49cd7412b..64d988075085 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -55,24 +55,14 @@ public class SpringApplicationAdminJmxAutoConfiguration { */ private static final String DEFAULT_JMX_NAME = "org.springframework.boot:type=Admin,name=SpringApplication"; - private final Iterable mbeanExporters; - - private final Environment environment; - - public SpringApplicationAdminJmxAutoConfiguration( - ObjectProvider mbeanExporters, Environment environment) { - this.mbeanExporters = mbeanExporters; - this.environment = environment; - } - @Bean @ConditionalOnMissingBean - public SpringApplicationAdminMXBeanRegistrar springApplicationAdminRegistrar() + public SpringApplicationAdminMXBeanRegistrar springApplicationAdminRegistrar( + ObjectProvider mbeanExporters, Environment environment) throws MalformedObjectNameException { - String jmxName = this.environment.getProperty(JMX_NAME_PROPERTY, - DEFAULT_JMX_NAME); - if (this.mbeanExporters != null) { // Make sure to not register that MBean twice - for (MBeanExporter mbeanExporter : this.mbeanExporters) { + String jmxName = environment.getProperty(JMX_NAME_PROPERTY, DEFAULT_JMX_NAME); + if (mbeanExporters != null) { // Make sure to not register that MBean twice + for (MBeanExporter mbeanExporter : mbeanExporters) { mbeanExporter.addExcludedBean(jmxName); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java index 204c2ab6b8b7..ca7d39cb20d9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -157,53 +157,39 @@ private RabbitConnectionFactoryBean getRabbitConnectionFactoryBean( @Import(RabbitConnectionFactoryCreator.class) protected static class RabbitTemplateConfiguration { - private final RabbitProperties properties; - - private final ObjectProvider messageConverter; - - private final ObjectProvider retryTemplateCustomizers; - - public RabbitTemplateConfiguration(RabbitProperties properties, - ObjectProvider messageConverter, - ObjectProvider retryTemplateCustomizers) { - this.properties = properties; - this.messageConverter = messageConverter; - this.retryTemplateCustomizers = retryTemplateCustomizers; - } - @Bean @ConditionalOnSingleCandidate(ConnectionFactory.class) @ConditionalOnMissingBean - public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) { + public RabbitTemplate rabbitTemplate(RabbitProperties properties, + ObjectProvider messageConverter, + ObjectProvider retryTemplateCustomizers, + ConnectionFactory connectionFactory) { PropertyMapper map = PropertyMapper.get(); RabbitTemplate template = new RabbitTemplate(connectionFactory); - MessageConverter messageConverter = this.messageConverter.getIfUnique(); - if (messageConverter != null) { - template.setMessageConverter(messageConverter); - } - template.setMandatory(determineMandatoryFlag()); - RabbitProperties.Template properties = this.properties.getTemplate(); - if (properties.getRetry().isEnabled()) { - template.setRetryTemplate(new RetryTemplateFactory( - this.retryTemplateCustomizers.orderedStream() + messageConverter.ifUnique(template::setMessageConverter); + template.setMandatory(determineMandatoryFlag(properties)); + RabbitProperties.Template templateProperties = properties.getTemplate(); + if (templateProperties.getRetry().isEnabled()) { + template.setRetryTemplate( + new RetryTemplateFactory(retryTemplateCustomizers.orderedStream() .collect(Collectors.toList())).createRetryTemplate( - properties.getRetry(), + templateProperties.getRetry(), RabbitRetryTemplateCustomizer.Target.SENDER)); } - map.from(properties::getReceiveTimeout).whenNonNull().as(Duration::toMillis) - .to(template::setReceiveTimeout); - map.from(properties::getReplyTimeout).whenNonNull().as(Duration::toMillis) - .to(template::setReplyTimeout); - map.from(properties::getExchange).to(template::setExchange); - map.from(properties::getRoutingKey).to(template::setRoutingKey); - map.from(properties::getDefaultReceiveQueue).whenNonNull() + map.from(templateProperties::getReceiveTimeout).whenNonNull() + .as(Duration::toMillis).to(template::setReceiveTimeout); + map.from(templateProperties::getReplyTimeout).whenNonNull() + .as(Duration::toMillis).to(template::setReplyTimeout); + map.from(templateProperties::getExchange).to(template::setExchange); + map.from(templateProperties::getRoutingKey).to(template::setRoutingKey); + map.from(templateProperties::getDefaultReceiveQueue).whenNonNull() .to(template::setDefaultReceiveQueue); return template; } - private boolean determineMandatoryFlag() { - Boolean mandatory = this.properties.getTemplate().getMandatory(); - return (mandatory != null) ? mandatory : this.properties.isPublisherReturns(); + private boolean determineMandatoryFlag(RabbitProperties properties) { + Boolean mandatory = properties.getTemplate().getMandatory(); + return (mandatory != null) ? mandatory : properties.isPublisherReturns(); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java index 92708cedc75d..68c23e66a809 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,12 +68,8 @@ public class BatchAutoConfiguration { private final BatchProperties properties; - private final JobParametersConverter jobParametersConverter; - - public BatchAutoConfiguration(BatchProperties properties, - ObjectProvider jobParametersConverter) { + public BatchAutoConfiguration(BatchProperties properties) { this.properties = properties; - this.jobParametersConverter = jobParametersConverter.getIfAvailable(); } @Bean @@ -108,7 +104,9 @@ public JobExecutionExitCodeGenerator jobExecutionExitCodeGenerator() { @Bean @ConditionalOnMissingBean(JobOperator.class) - public SimpleJobOperator jobOperator(JobExplorer jobExplorer, JobLauncher jobLauncher, + public SimpleJobOperator jobOperator( + ObjectProvider jobParametersConverter, + JobExplorer jobExplorer, JobLauncher jobLauncher, ListableJobLocator jobRegistry, JobRepository jobRepository) throws Exception { SimpleJobOperator factory = new SimpleJobOperator(); @@ -116,9 +114,7 @@ public SimpleJobOperator jobOperator(JobExplorer jobExplorer, JobLauncher jobLau factory.setJobLauncher(jobLauncher); factory.setJobRegistry(jobRegistry); factory.setJobRepository(jobRepository); - if (this.jobParametersConverter != null) { - factory.setJobParametersConverter(this.jobParametersConverter); - } + jobParametersConverter.ifAvailable(factory::setJobParametersConverter); return factory; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CaffeineCacheConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CaffeineCacheConfiguration.java index fa3235a1c165..d0b123d4835b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CaffeineCacheConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CaffeineCacheConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -45,57 +45,44 @@ @Conditional({ CacheCondition.class }) class CaffeineCacheConfiguration { - private final CacheProperties cacheProperties; - - private final CacheManagerCustomizers customizers; - - private final Caffeine caffeine; - - private final CaffeineSpec caffeineSpec; - - private final CacheLoader cacheLoader; - - CaffeineCacheConfiguration(CacheProperties cacheProperties, + @Bean + public CaffeineCacheManager cacheManager(CacheProperties cacheProperties, CacheManagerCustomizers customizers, ObjectProvider> caffeine, ObjectProvider caffeineSpec, ObjectProvider> cacheLoader) { - this.cacheProperties = cacheProperties; - this.customizers = customizers; - this.caffeine = caffeine.getIfAvailable(); - this.caffeineSpec = caffeineSpec.getIfAvailable(); - this.cacheLoader = cacheLoader.getIfAvailable(); - } - - @Bean - public CaffeineCacheManager cacheManager() { - CaffeineCacheManager cacheManager = createCacheManager(); - List cacheNames = this.cacheProperties.getCacheNames(); + CaffeineCacheManager cacheManager = createCacheManager(cacheProperties, caffeine, + caffeineSpec, cacheLoader); + List cacheNames = cacheProperties.getCacheNames(); if (!CollectionUtils.isEmpty(cacheNames)) { cacheManager.setCacheNames(cacheNames); } - return this.customizers.customize(cacheManager); + return customizers.customize(cacheManager); } - private CaffeineCacheManager createCacheManager() { + private CaffeineCacheManager createCacheManager(CacheProperties cacheProperties, + ObjectProvider> caffeine, + ObjectProvider caffeineSpec, + ObjectProvider> cacheLoader) { CaffeineCacheManager cacheManager = new CaffeineCacheManager(); - setCacheBuilder(cacheManager); - if (this.cacheLoader != null) { - cacheManager.setCacheLoader(this.cacheLoader); - } + setCacheBuilder(cacheProperties, caffeineSpec.getIfAvailable(), + caffeine.getIfAvailable(), cacheManager); + cacheLoader.ifAvailable(cacheManager::setCacheLoader); return cacheManager; } - private void setCacheBuilder(CaffeineCacheManager cacheManager) { - String specification = this.cacheProperties.getCaffeine().getSpec(); + private void setCacheBuilder(CacheProperties cacheProperties, + CaffeineSpec caffeineSpec, Caffeine caffeine, + CaffeineCacheManager cacheManager) { + String specification = cacheProperties.getCaffeine().getSpec(); if (StringUtils.hasText(specification)) { cacheManager.setCacheSpecification(specification); } - else if (this.caffeineSpec != null) { - cacheManager.setCaffeineSpec(this.caffeineSpec); + else if (caffeineSpec != null) { + cacheManager.setCaffeineSpec(caffeineSpec); } - else if (this.caffeine != null) { - cacheManager.setCaffeine(this.caffeine); + else if (caffeine != null) { + cacheManager.setCaffeine(caffeine); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CouchbaseCacheConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CouchbaseCacheConfiguration.java index d8fa3fcd4d1a..d84def6b8d0b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CouchbaseCacheConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/CouchbaseCacheConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -47,29 +47,17 @@ @Conditional(CacheCondition.class) public class CouchbaseCacheConfiguration { - private final CacheProperties cacheProperties; - - private final CacheManagerCustomizers customizers; - - private final Bucket bucket; - - public CouchbaseCacheConfiguration(CacheProperties cacheProperties, - CacheManagerCustomizers customizers, Bucket bucket) { - this.cacheProperties = cacheProperties; - this.customizers = customizers; - this.bucket = bucket; - } - @Bean - public CouchbaseCacheManager cacheManager() { - List cacheNames = this.cacheProperties.getCacheNames(); - CacheBuilder builder = CacheBuilder.newInstance(this.bucket); - Couchbase couchbase = this.cacheProperties.getCouchbase(); + public CouchbaseCacheManager cacheManager(CacheProperties cacheProperties, + CacheManagerCustomizers customizers, Bucket bucket) { + List cacheNames = cacheProperties.getCacheNames(); + CacheBuilder builder = CacheBuilder.newInstance(bucket); + Couchbase couchbase = cacheProperties.getCouchbase(); PropertyMapper.get().from(couchbase::getExpiration).whenNonNull() .asInt(Duration::getSeconds).to(builder::withExpiration); String[] names = StringUtils.toStringArray(cacheNames); CouchbaseCacheManager cacheManager = new CouchbaseCacheManager(builder, names); - return this.customizers.customize(cacheManager); + return customizers.customize(cacheManager); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/EhCacheCacheConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/EhCacheCacheConfiguration.java index 0c287c935367..6037f7d5ed73 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/EhCacheCacheConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/EhCacheCacheConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -45,26 +45,17 @@ EhCacheCacheConfiguration.ConfigAvailableCondition.class }) class EhCacheCacheConfiguration { - private final CacheProperties cacheProperties; - - private final CacheManagerCustomizers customizers; - - EhCacheCacheConfiguration(CacheProperties cacheProperties, - CacheManagerCustomizers customizers) { - this.cacheProperties = cacheProperties; - this.customizers = customizers; - } - @Bean - public EhCacheCacheManager cacheManager(CacheManager ehCacheCacheManager) { - return this.customizers.customize(new EhCacheCacheManager(ehCacheCacheManager)); + public EhCacheCacheManager cacheManager(CacheManagerCustomizers customizers, + CacheManager ehCacheCacheManager) { + return customizers.customize(new EhCacheCacheManager(ehCacheCacheManager)); } @Bean @ConditionalOnMissingBean - public CacheManager ehCacheCacheManager() { - Resource location = this.cacheProperties - .resolveConfigLocation(this.cacheProperties.getEhcache().getConfig()); + public CacheManager ehCacheCacheManager(CacheProperties cacheProperties) { + Resource location = cacheProperties + .resolveConfigLocation(cacheProperties.getEhcache().getConfig()); if (location != null) { return EhCacheManagerUtils.buildCacheManager(location); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/GenericCacheConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/GenericCacheConfiguration.java index c5955967fd38..6af9862fc3ce 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/GenericCacheConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/GenericCacheConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -40,17 +40,12 @@ @Conditional(CacheCondition.class) class GenericCacheConfiguration { - private final CacheManagerCustomizers customizers; - - GenericCacheConfiguration(CacheManagerCustomizers customizers) { - this.customizers = customizers; - } - @Bean - public SimpleCacheManager cacheManager(Collection caches) { + public SimpleCacheManager cacheManager(CacheManagerCustomizers customizers, + Collection caches) { SimpleCacheManager cacheManager = new SimpleCacheManager(); cacheManager.setCaches(caches); - return this.customizers.customize(cacheManager); + return customizers.customize(cacheManager); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/HazelcastCacheConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/HazelcastCacheConfiguration.java index 2910b49b622b..ed1200a61d47 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/HazelcastCacheConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/HazelcastCacheConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -50,18 +50,12 @@ @ConditionalOnSingleCandidate(HazelcastInstance.class) class HazelcastCacheConfiguration { - private final CacheManagerCustomizers customizers; - - HazelcastCacheConfiguration(CacheManagerCustomizers customizers) { - this.customizers = customizers; - } - @Bean - public HazelcastCacheManager cacheManager(HazelcastInstance existingHazelcastInstance) - throws IOException { + public HazelcastCacheManager cacheManager(CacheManagerCustomizers customizers, + HazelcastInstance existingHazelcastInstance) throws IOException { HazelcastCacheManager cacheManager = new HazelcastCacheManager( existingHazelcastInstance); - return this.customizers.customize(cacheManager); + return customizers.customize(cacheManager); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/InfinispanCacheConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/InfinispanCacheConfiguration.java index 76bc8da2cfaa..25093bc99509 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/InfinispanCacheConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/InfinispanCacheConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -49,43 +49,33 @@ @Conditional(CacheCondition.class) public class InfinispanCacheConfiguration { - private final CacheProperties cacheProperties; - - private final CacheManagerCustomizers customizers; - - private final ConfigurationBuilder defaultConfigurationBuilder; - - public InfinispanCacheConfiguration(CacheProperties cacheProperties, - CacheManagerCustomizers customizers, - ObjectProvider defaultConfigurationBuilder) { - this.cacheProperties = cacheProperties; - this.customizers = customizers; - this.defaultConfigurationBuilder = defaultConfigurationBuilder.getIfAvailable(); - } - @Bean - public SpringEmbeddedCacheManager cacheManager( + public SpringEmbeddedCacheManager cacheManager(CacheManagerCustomizers customizers, EmbeddedCacheManager embeddedCacheManager) { SpringEmbeddedCacheManager cacheManager = new SpringEmbeddedCacheManager( embeddedCacheManager); - return this.customizers.customize(cacheManager); + return customizers.customize(cacheManager); } @Bean(destroyMethod = "stop") @ConditionalOnMissingBean - public EmbeddedCacheManager infinispanCacheManager() throws IOException { - EmbeddedCacheManager cacheManager = createEmbeddedCacheManager(); - List cacheNames = this.cacheProperties.getCacheNames(); + public EmbeddedCacheManager infinispanCacheManager(CacheProperties cacheProperties, + ObjectProvider defaultConfigurationBuilder) + throws IOException { + EmbeddedCacheManager cacheManager = createEmbeddedCacheManager(cacheProperties); + List cacheNames = cacheProperties.getCacheNames(); if (!CollectionUtils.isEmpty(cacheNames)) { cacheNames.forEach((cacheName) -> cacheManager.defineConfiguration(cacheName, - getDefaultCacheConfiguration())); + getDefaultCacheConfiguration( + defaultConfigurationBuilder.getIfAvailable()))); } return cacheManager; } - private EmbeddedCacheManager createEmbeddedCacheManager() throws IOException { - Resource location = this.cacheProperties - .resolveConfigLocation(this.cacheProperties.getInfinispan().getConfig()); + private EmbeddedCacheManager createEmbeddedCacheManager( + CacheProperties cacheProperties) throws IOException { + Resource location = cacheProperties + .resolveConfigLocation(cacheProperties.getInfinispan().getConfig()); if (location != null) { try (InputStream in = location.getInputStream()) { return new DefaultCacheManager(in); @@ -94,9 +84,10 @@ private EmbeddedCacheManager createEmbeddedCacheManager() throws IOException { return new DefaultCacheManager(); } - private org.infinispan.configuration.cache.Configuration getDefaultCacheConfiguration() { - if (this.defaultConfigurationBuilder != null) { - return this.defaultConfigurationBuilder.build(); + private org.infinispan.configuration.cache.Configuration getDefaultCacheConfiguration( + ConfigurationBuilder defaultConfigurationBuilder) { + if (defaultConfigurationBuilder != null) { + return defaultConfigurationBuilder.build(); } return new ConfigurationBuilder().build(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java index 737ac55fac9a..832f68cdf4a7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -63,61 +63,50 @@ @Import(HazelcastJCacheCustomizationConfiguration.class) class JCacheCacheConfiguration implements BeanClassLoaderAware { - private final CacheProperties cacheProperties; - - private final CacheManagerCustomizers customizers; - - private final javax.cache.configuration.Configuration defaultCacheConfiguration; - - private final ObjectProvider cacheManagerCustomizers; - - private final ObjectProvider cachePropertiesCustomizers; - private ClassLoader beanClassLoader; - JCacheCacheConfiguration(CacheProperties cacheProperties, - CacheManagerCustomizers customizers, - ObjectProvider> defaultCacheConfiguration, - ObjectProvider cacheManagerCustomizers, - ObjectProvider cachePropertiesCustomizers) { - this.cacheProperties = cacheProperties; - this.customizers = customizers; - this.defaultCacheConfiguration = defaultCacheConfiguration.getIfAvailable(); - this.cacheManagerCustomizers = cacheManagerCustomizers; - this.cachePropertiesCustomizers = cachePropertiesCustomizers; - } - @Override public void setBeanClassLoader(ClassLoader classLoader) { this.beanClassLoader = classLoader; } @Bean - public JCacheCacheManager cacheManager(CacheManager jCacheCacheManager) { + public JCacheCacheManager cacheManager(CacheManagerCustomizers customizers, + CacheManager jCacheCacheManager) { JCacheCacheManager cacheManager = new JCacheCacheManager(jCacheCacheManager); - return this.customizers.customize(cacheManager); + return customizers.customize(cacheManager); } @Bean @ConditionalOnMissingBean - public CacheManager jCacheCacheManager() throws IOException { - CacheManager jCacheCacheManager = createCacheManager(); - List cacheNames = this.cacheProperties.getCacheNames(); + public CacheManager jCacheCacheManager(CacheProperties cacheProperties, + ObjectProvider> defaultCacheConfiguration, + ObjectProvider cacheManagerCustomizers, + ObjectProvider cachePropertiesCustomizers) + throws IOException { + CacheManager jCacheCacheManager = createCacheManager(cacheProperties, + cachePropertiesCustomizers); + List cacheNames = cacheProperties.getCacheNames(); if (!CollectionUtils.isEmpty(cacheNames)) { for (String cacheName : cacheNames) { - jCacheCacheManager.createCache(cacheName, getDefaultCacheConfiguration()); + jCacheCacheManager.createCache(cacheName, defaultCacheConfiguration + .getIfAvailable(MutableConfiguration::new)); } } - customize(jCacheCacheManager); + cacheManagerCustomizers.orderedStream() + .forEach((customizer) -> customizer.customize(jCacheCacheManager)); return jCacheCacheManager; } - private CacheManager createCacheManager() throws IOException { + private CacheManager createCacheManager(CacheProperties cacheProperties, + ObjectProvider cachePropertiesCustomizers) + throws IOException { CachingProvider cachingProvider = getCachingProvider( - this.cacheProperties.getJcache().getProvider()); - Properties properties = createCacheManagerProperties(); - Resource configLocation = this.cacheProperties - .resolveConfigLocation(this.cacheProperties.getJcache().getConfig()); + cacheProperties.getJcache().getProvider()); + Properties properties = createCacheManagerProperties(cachePropertiesCustomizers, + cacheProperties); + Resource configLocation = cacheProperties + .resolveConfigLocation(cacheProperties.getJcache().getConfig()); if (configLocation != null) { return cachingProvider.getCacheManager(configLocation.getURI(), this.beanClassLoader, properties); @@ -132,25 +121,15 @@ private CachingProvider getCachingProvider(String cachingProviderFqn) { return Caching.getCachingProvider(); } - private Properties createCacheManagerProperties() { + private Properties createCacheManagerProperties( + ObjectProvider cachePropertiesCustomizers, + CacheProperties cacheProperties) { Properties properties = new Properties(); - this.cachePropertiesCustomizers.orderedStream().forEach( - (customizer) -> customizer.customize(this.cacheProperties, properties)); + cachePropertiesCustomizers.orderedStream().forEach( + (customizer) -> customizer.customize(cacheProperties, properties)); return properties; } - private javax.cache.configuration.Configuration getDefaultCacheConfiguration() { - if (this.defaultCacheConfiguration != null) { - return this.defaultCacheConfiguration; - } - return new MutableConfiguration<>(); - } - - private void customize(CacheManager cacheManager) { - this.cacheManagerCustomizers.orderedStream() - .forEach((customizer) -> customizer.customize(cacheManager)); - } - /** * Determine if JCache is available. This either kicks in if a provider is available * as defined per {@link JCacheProviderAvailableCondition} or if a diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java index 41258b181fe3..47b2d2437cb5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/RedisCacheConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -53,39 +53,35 @@ @Conditional(CacheCondition.class) class RedisCacheConfiguration { - private final CacheProperties cacheProperties; - - private final CacheManagerCustomizers customizerInvoker; - - private final org.springframework.data.redis.cache.RedisCacheConfiguration redisCacheConfiguration; - - RedisCacheConfiguration(CacheProperties cacheProperties, - CacheManagerCustomizers customizerInvoker, - ObjectProvider redisCacheConfiguration) { - this.cacheProperties = cacheProperties; - this.customizerInvoker = customizerInvoker; - this.redisCacheConfiguration = redisCacheConfiguration.getIfAvailable(); - } - @Bean - public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory, + public RedisCacheManager cacheManager(CacheProperties cacheProperties, + CacheManagerCustomizers cacheManagerCustomizers, + ObjectProvider redisCacheConfiguration, + RedisConnectionFactory redisConnectionFactory, ResourceLoader resourceLoader) { RedisCacheManagerBuilder builder = RedisCacheManager .builder(redisConnectionFactory) - .cacheDefaults(determineConfiguration(resourceLoader.getClassLoader())); - List cacheNames = this.cacheProperties.getCacheNames(); + .cacheDefaults(determineConfiguration(cacheProperties, + redisCacheConfiguration, resourceLoader.getClassLoader())); + List cacheNames = cacheProperties.getCacheNames(); if (!cacheNames.isEmpty()) { builder.initialCacheNames(new LinkedHashSet<>(cacheNames)); } - return this.customizerInvoker.customize(builder.build()); + return cacheManagerCustomizers.customize(builder.build()); } private org.springframework.data.redis.cache.RedisCacheConfiguration determineConfiguration( + CacheProperties cacheProperties, + ObjectProvider redisCacheConfiguration, ClassLoader classLoader) { - if (this.redisCacheConfiguration != null) { - return this.redisCacheConfiguration; - } - Redis redisProperties = this.cacheProperties.getRedis(); + return redisCacheConfiguration + .getIfAvailable(() -> createConfiguration(cacheProperties, classLoader)); + + } + + private org.springframework.data.redis.cache.RedisCacheConfiguration createConfiguration( + CacheProperties cacheProperties, ClassLoader classLoader) { + Redis redisProperties = cacheProperties.getRedis(); org.springframework.data.redis.cache.RedisCacheConfiguration config = org.springframework.data.redis.cache.RedisCacheConfiguration .defaultCacheConfig(); config = config.serializeValuesWith(SerializationPair diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/SimpleCacheConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/SimpleCacheConfiguration.java index 4062a7698473..fd989e022161 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/SimpleCacheConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/SimpleCacheConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -36,24 +36,15 @@ @Conditional(CacheCondition.class) class SimpleCacheConfiguration { - private final CacheProperties cacheProperties; - - private final CacheManagerCustomizers customizerInvoker; - - SimpleCacheConfiguration(CacheProperties cacheProperties, - CacheManagerCustomizers customizerInvoker) { - this.cacheProperties = cacheProperties; - this.customizerInvoker = customizerInvoker; - } - @Bean - public ConcurrentMapCacheManager cacheManager() { + public ConcurrentMapCacheManager cacheManager(CacheProperties cacheProperties, + CacheManagerCustomizers cacheManagerCustomizers) { ConcurrentMapCacheManager cacheManager = new ConcurrentMapCacheManager(); - List cacheNames = this.cacheProperties.getCacheNames(); + List cacheNames = cacheProperties.getCacheNames(); if (!cacheNames.isEmpty()) { cacheManager.setCacheNames(cacheNames); } - return this.customizerInvoker.customize(cacheManager); + return cacheManagerCustomizers.customize(cacheManager); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java index c46c731054c9..6142bcd5a2cc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -48,22 +48,12 @@ @EnableConfigurationProperties(CassandraProperties.class) public class CassandraAutoConfiguration { - private final CassandraProperties properties; - - private final ObjectProvider builderCustomizers; - - public CassandraAutoConfiguration(CassandraProperties properties, - ObjectProvider builderCustomizers) { - this.properties = properties; - this.builderCustomizers = builderCustomizers; - } - @Bean @ConditionalOnMissingBean @SuppressWarnings("deprecation") - public Cluster cassandraCluster() { + public Cluster cassandraCluster(CassandraProperties properties, + ObjectProvider builderCustomizers) { PropertyMapper map = PropertyMapper.get(); - CassandraProperties properties = this.properties; Cluster.Builder builder = Cluster.builder() .withClusterName(properties.getClusterName()) .withPort(properties.getPort()); @@ -72,31 +62,29 @@ public Cluster cassandraCluster() { map.from(properties::getCompression).whenNonNull().to(builder::withCompression); map.from(properties::getLoadBalancingPolicy).whenNonNull() .as(BeanUtils::instantiateClass).to(builder::withLoadBalancingPolicy); - map.from(this::getQueryOptions).to(builder::withQueryOptions); + QueryOptions queryOptions = getQueryOptions(properties); + map.from(queryOptions).to(builder::withQueryOptions); map.from(properties::getReconnectionPolicy).whenNonNull() .as(BeanUtils::instantiateClass).to(builder::withReconnectionPolicy); map.from(properties::getRetryPolicy).whenNonNull().as(BeanUtils::instantiateClass) .to(builder::withRetryPolicy); - map.from(this::getSocketOptions).to(builder::withSocketOptions); + SocketOptions socketOptions = getSocketOptions(properties); + map.from(socketOptions).to(builder::withSocketOptions); map.from(properties::isSsl).whenTrue().toCall(builder::withSSL); - map.from(this::getPoolingOptions).to(builder::withPoolingOptions); + PoolingOptions poolingOptions = getPoolingOptions(properties); + map.from(poolingOptions).to(builder::withPoolingOptions); map.from(properties::getContactPoints).as(StringUtils::toStringArray) .to(builder::addContactPoints); map.from(properties::isJmxEnabled).whenFalse() .toCall(builder::withoutJMXReporting); - customize(builder); - return builder.build(); - } - - private void customize(Cluster.Builder builder) { - this.builderCustomizers.orderedStream() + builderCustomizers.orderedStream() .forEach((customizer) -> customizer.customize(builder)); + return builder.build(); } - private QueryOptions getQueryOptions() { + private QueryOptions getQueryOptions(CassandraProperties properties) { PropertyMapper map = PropertyMapper.get(); QueryOptions options = new QueryOptions(); - CassandraProperties properties = this.properties; map.from(properties::getConsistencyLevel).whenNonNull() .to(options::setConsistencyLevel); map.from(properties::getSerialConsistencyLevel).whenNonNull() @@ -105,27 +93,27 @@ private QueryOptions getQueryOptions() { return options; } - private SocketOptions getSocketOptions() { + private SocketOptions getSocketOptions(CassandraProperties properties) { PropertyMapper map = PropertyMapper.get(); SocketOptions options = new SocketOptions(); - map.from(this.properties::getConnectTimeout).whenNonNull() - .asInt(Duration::toMillis).to(options::setConnectTimeoutMillis); - map.from(this.properties::getReadTimeout).whenNonNull().asInt(Duration::toMillis) + map.from(properties::getConnectTimeout).whenNonNull().asInt(Duration::toMillis) + .to(options::setConnectTimeoutMillis); + map.from(properties::getReadTimeout).whenNonNull().asInt(Duration::toMillis) .to(options::setReadTimeoutMillis); return options; } - private PoolingOptions getPoolingOptions() { + private PoolingOptions getPoolingOptions(CassandraProperties properties) { PropertyMapper map = PropertyMapper.get(); - CassandraProperties.Pool properties = this.properties.getPool(); + CassandraProperties.Pool poolProperties = properties.getPool(); PoolingOptions options = new PoolingOptions(); - map.from(properties::getIdleTimeout).whenNonNull().asInt(Duration::getSeconds) + map.from(poolProperties::getIdleTimeout).whenNonNull().asInt(Duration::getSeconds) .to(options::setIdleTimeoutSeconds); - map.from(properties::getPoolTimeout).whenNonNull().asInt(Duration::toMillis) + map.from(poolProperties::getPoolTimeout).whenNonNull().asInt(Duration::toMillis) .to(options::setPoolTimeoutMillis); - map.from(properties::getHeartbeatInterval).whenNonNull() + map.from(poolProperties::getHeartbeatInterval).whenNonNull() .asInt(Duration::getSeconds).to(options::setHeartbeatIntervalSeconds); - map.from(properties::getMaxQueueSize).to(options::setMaxQueueSize); + map.from(poolProperties::getMaxQueueSize).to(options::setMaxQueueSize); return options; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java index 936443a43311..827d7e8b2800 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -63,31 +63,24 @@ @AutoConfigureAfter(CassandraAutoConfiguration.class) public class CassandraDataAutoConfiguration { - private final BeanFactory beanFactory; - private final CassandraProperties properties; private final Cluster cluster; - private final Environment environment; - public CassandraDataAutoConfiguration(BeanFactory beanFactory, CassandraProperties properties, Cluster cluster, Environment environment) { - this.beanFactory = beanFactory; this.properties = properties; this.cluster = cluster; - this.environment = environment; } @Bean @ConditionalOnMissingBean - public CassandraMappingContext cassandraMapping( + public CassandraMappingContext cassandraMapping(BeanFactory beanFactory, CassandraCustomConversions conversions) throws ClassNotFoundException { CassandraMappingContext context = new CassandraMappingContext(); - List packages = EntityScanPackages.get(this.beanFactory) - .getPackageNames(); - if (packages.isEmpty() && AutoConfigurationPackages.has(this.beanFactory)) { - packages = AutoConfigurationPackages.get(this.beanFactory); + List packages = EntityScanPackages.get(beanFactory).getPackageNames(); + if (packages.isEmpty() && AutoConfigurationPackages.has(beanFactory)) { + packages = AutoConfigurationPackages.get(beanFactory); } if (!packages.isEmpty()) { context.setInitialEntitySet(CassandraEntityClassScanner.scan(packages)); @@ -113,13 +106,13 @@ public CassandraConverter cassandraConverter(CassandraMappingContext mapping, @Bean @ConditionalOnMissingBean(Session.class) - public CassandraSessionFactoryBean cassandraSession(CassandraConverter converter) - throws Exception { + public CassandraSessionFactoryBean cassandraSession(Environment environment, + CassandraConverter converter) throws Exception { CassandraSessionFactoryBean session = new CassandraSessionFactoryBean(); session.setCluster(this.cluster); session.setConverter(converter); session.setKeyspaceName(this.properties.getKeyspaceName()); - Binder binder = Binder.get(this.environment); + Binder binder = Binder.get(environment); binder.bind("spring.data.cassandra.schema-action", SchemaAction.class) .ifBound(session::setSchemaAction); return session; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataConfiguration.java index a10af3a1ab62..1fb93cf1a9d5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -38,24 +38,15 @@ @Configuration class MongoDataConfiguration { - private final ApplicationContext applicationContext; - - private final MongoProperties properties; - - MongoDataConfiguration(ApplicationContext applicationContext, - MongoProperties properties) { - this.applicationContext = applicationContext; - this.properties = properties; - } - @Bean @ConditionalOnMissingBean - public MongoMappingContext mongoMappingContext(MongoCustomConversions conversions) + public MongoMappingContext mongoMappingContext(ApplicationContext applicationContext, + MongoProperties properties, MongoCustomConversions conversions) throws ClassNotFoundException { MongoMappingContext context = new MongoMappingContext(); - context.setInitialEntitySet(new EntityScanner(this.applicationContext) + context.setInitialEntitySet(new EntityScanner(applicationContext) .scan(Document.class, Persistent.class)); - Class strategyClass = this.properties.getFieldNamingStrategy(); + Class strategyClass = properties.getFieldNamingStrategy(); if (strategyClass != null) { context.setFieldNamingStrategy( (FieldNamingStrategy) BeanUtils.instantiateClass(strategyClass)); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.java index 560747eee34b..414eb75a6f99 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -59,17 +59,11 @@ @AutoConfigureAfter(MongoReactiveAutoConfiguration.class) public class MongoReactiveDataAutoConfiguration { - private final MongoProperties properties; - - public MongoReactiveDataAutoConfiguration(MongoProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean(ReactiveMongoDatabaseFactory.class) public SimpleReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory( - MongoClient mongo) { - String database = this.properties.getMongoClientDatabase(); + MongoProperties properties, MongoClient mongo) { + String database = properties.getMongoClientDatabase(); return new SimpleReactiveMongoDatabaseFactory(mongo, database); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisConnectionConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisConnectionConfiguration.java index b98d33e7f40b..b464d688129e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisConnectionConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/JedisConnectionConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -47,27 +47,24 @@ @ConditionalOnClass({ GenericObjectPool.class, JedisConnection.class, Jedis.class }) class JedisConnectionConfiguration extends RedisConnectionConfiguration { - private final RedisProperties properties; - - private final ObjectProvider builderCustomizers; - JedisConnectionConfiguration(RedisProperties properties, ObjectProvider sentinelConfiguration, - ObjectProvider clusterConfiguration, - ObjectProvider builderCustomizers) { + ObjectProvider clusterConfiguration) { super(properties, sentinelConfiguration, clusterConfiguration); - this.properties = properties; - this.builderCustomizers = builderCustomizers; } @Bean @ConditionalOnMissingBean(RedisConnectionFactory.class) - public JedisConnectionFactory redisConnectionFactory() throws UnknownHostException { - return createJedisConnectionFactory(); + public JedisConnectionFactory redisConnectionFactory( + ObjectProvider builderCustomizers) + throws UnknownHostException { + return createJedisConnectionFactory(builderCustomizers); } - private JedisConnectionFactory createJedisConnectionFactory() { - JedisClientConfiguration clientConfiguration = getJedisClientConfiguration(); + private JedisConnectionFactory createJedisConnectionFactory( + ObjectProvider builderCustomizers) { + JedisClientConfiguration clientConfiguration = getJedisClientConfiguration( + builderCustomizers); if (getSentinelConfig() != null) { return new JedisConnectionFactory(getSentinelConfig(), clientConfiguration); } @@ -78,27 +75,29 @@ private JedisConnectionFactory createJedisConnectionFactory() { return new JedisConnectionFactory(getStandaloneConfig(), clientConfiguration); } - private JedisClientConfiguration getJedisClientConfiguration() { + private JedisClientConfiguration getJedisClientConfiguration( + ObjectProvider builderCustomizers) { JedisClientConfigurationBuilder builder = applyProperties( JedisClientConfiguration.builder()); - RedisProperties.Pool pool = this.properties.getJedis().getPool(); + RedisProperties.Pool pool = getProperties().getJedis().getPool(); if (pool != null) { applyPooling(pool, builder); } - if (StringUtils.hasText(this.properties.getUrl())) { + if (StringUtils.hasText(getProperties().getUrl())) { customizeConfigurationFromUrl(builder); } - customize(builder); + builderCustomizers.orderedStream() + .forEach((customizer) -> customizer.customize(builder)); return builder.build(); } private JedisClientConfigurationBuilder applyProperties( JedisClientConfigurationBuilder builder) { - if (this.properties.isSsl()) { + if (getProperties().isSsl()) { builder.useSsl(); } - if (this.properties.getTimeout() != null) { - Duration timeout = this.properties.getTimeout(); + if (getProperties().getTimeout() != null) { + Duration timeout = getProperties().getTimeout(); builder.readTimeout(timeout).connectTimeout(timeout); } return builder; @@ -122,16 +121,10 @@ private JedisPoolConfig jedisPoolConfig(RedisProperties.Pool pool) { private void customizeConfigurationFromUrl( JedisClientConfiguration.JedisClientConfigurationBuilder builder) { - ConnectionInfo connectionInfo = parseUrl(this.properties.getUrl()); + ConnectionInfo connectionInfo = parseUrl(getProperties().getUrl()); if (connectionInfo.isUseSsl()) { builder.useSsl(); } } - private void customize( - JedisClientConfiguration.JedisClientConfigurationBuilder builder) { - this.builderCustomizers.orderedStream() - .forEach((customizer) -> customizer.customize(builder)); - } - } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.java index bbf03afe8476..05f7761abd34 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -48,17 +48,10 @@ @ConditionalOnClass(RedisClient.class) class LettuceConnectionConfiguration extends RedisConnectionConfiguration { - private final RedisProperties properties; - - private final ObjectProvider builderCustomizers; - LettuceConnectionConfiguration(RedisProperties properties, ObjectProvider sentinelConfigurationProvider, - ObjectProvider clusterConfigurationProvider, - ObjectProvider builderCustomizers) { + ObjectProvider clusterConfigurationProvider) { super(properties, sentinelConfigurationProvider, clusterConfigurationProvider); - this.properties = properties; - this.builderCustomizers = builderCustomizers; } @Bean(destroyMethod = "shutdown") @@ -70,9 +63,11 @@ public DefaultClientResources lettuceClientResources() { @Bean @ConditionalOnMissingBean(RedisConnectionFactory.class) public LettuceConnectionFactory redisConnectionFactory( + ObjectProvider builderCustomizers, ClientResources clientResources) throws UnknownHostException { LettuceClientConfiguration clientConfig = getLettuceClientConfiguration( - clientResources, this.properties.getLettuce().getPool()); + builderCustomizers, clientResources, + getProperties().getLettuce().getPool()); return createLettuceConnectionFactory(clientConfig); } @@ -89,14 +84,16 @@ private LettuceConnectionFactory createLettuceConnectionFactory( } private LettuceClientConfiguration getLettuceClientConfiguration( + ObjectProvider builderCustomizers, ClientResources clientResources, Pool pool) { LettuceClientConfigurationBuilder builder = createBuilder(pool); applyProperties(builder); - if (StringUtils.hasText(this.properties.getUrl())) { + if (StringUtils.hasText(getProperties().getUrl())) { customizeConfigurationFromUrl(builder); } builder.clientResources(clientResources); - customize(builder); + builderCustomizers.orderedStream() + .forEach((customizer) -> customizer.customize(builder)); return builder.build(); } @@ -109,18 +106,18 @@ private LettuceClientConfigurationBuilder createBuilder(Pool pool) { private LettuceClientConfigurationBuilder applyProperties( LettuceClientConfiguration.LettuceClientConfigurationBuilder builder) { - if (this.properties.isSsl()) { + if (getProperties().isSsl()) { builder.useSsl(); } - if (this.properties.getTimeout() != null) { - builder.commandTimeout(this.properties.getTimeout()); + if (getProperties().getTimeout() != null) { + builder.commandTimeout(getProperties().getTimeout()); } - if (this.properties.getLettuce() != null) { - RedisProperties.Lettuce lettuce = this.properties.getLettuce(); + if (getProperties().getLettuce() != null) { + RedisProperties.Lettuce lettuce = getProperties().getLettuce(); if (lettuce.getShutdownTimeout() != null && !lettuce.getShutdownTimeout().isZero()) { builder.shutdownTimeout( - this.properties.getLettuce().getShutdownTimeout()); + getProperties().getLettuce().getShutdownTimeout()); } } return builder; @@ -128,18 +125,12 @@ private LettuceClientConfigurationBuilder applyProperties( private void customizeConfigurationFromUrl( LettuceClientConfiguration.LettuceClientConfigurationBuilder builder) { - ConnectionInfo connectionInfo = parseUrl(this.properties.getUrl()); + ConnectionInfo connectionInfo = parseUrl(getProperties().getUrl()); if (connectionInfo.isUseSsl()) { builder.useSsl(); } } - private void customize( - LettuceClientConfiguration.LettuceClientConfigurationBuilder builder) { - this.builderCustomizers.orderedStream() - .forEach((customizer) -> customizer.customize(builder)); - } - /** * Inner class to allow optional commons-pool2 dependency. */ diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisConnectionConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisConnectionConfiguration.java index c922acb20d12..8593c165705e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisConnectionConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisConnectionConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -111,6 +111,10 @@ protected final RedisClusterConfiguration getClusterConfiguration() { return config; } + protected final RedisProperties getProperties() { + return this.properties; + } + private List createSentinels(RedisProperties.Sentinel sentinel) { List nodes = new ArrayList<>(); for (String node : sentinel.getNodes()) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java index eb9a78bc9469..78531af39834 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/jest/JestAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -49,51 +49,38 @@ @AutoConfigureAfter(GsonAutoConfiguration.class) public class JestAutoConfiguration { - private final JestProperties properties; - - private final ObjectProvider gsonProvider; - - private final ObjectProvider builderCustomizers; - - public JestAutoConfiguration(JestProperties properties, ObjectProvider gson, - ObjectProvider builderCustomizers) { - this.properties = properties; - this.gsonProvider = gson; - this.builderCustomizers = builderCustomizers; - } - @Bean(destroyMethod = "shutdownClient") @ConditionalOnMissingBean - public JestClient jestClient() { + public JestClient jestClient(JestProperties properties, ObjectProvider gson, + ObjectProvider builderCustomizers) { JestClientFactory factory = new JestClientFactory(); - factory.setHttpClientConfig(createHttpClientConfig()); + factory.setHttpClientConfig( + createHttpClientConfig(properties, gson, builderCustomizers)); return factory.getObject(); } - protected HttpClientConfig createHttpClientConfig() { + protected HttpClientConfig createHttpClientConfig(JestProperties properties, + ObjectProvider gson, + ObjectProvider builderCustomizers) { HttpClientConfig.Builder builder = new HttpClientConfig.Builder( - this.properties.getUris()); + properties.getUris()); PropertyMapper map = PropertyMapper.get(); - map.from(this.properties::getUsername).whenHasText().to((username) -> builder - .defaultCredentials(username, this.properties.getPassword())); - Proxy proxy = this.properties.getProxy(); + map.from(properties::getUsername).whenHasText().to((username) -> builder + .defaultCredentials(username, properties.getPassword())); + Proxy proxy = properties.getProxy(); map.from(proxy::getHost).whenHasText().to((host) -> { Assert.notNull(proxy.getPort(), "Proxy port must not be null"); builder.proxy(new HttpHost(host, proxy.getPort())); }); - map.from(this.gsonProvider::getIfUnique).whenNonNull().to(builder::gson); - map.from(this.properties::isMultiThreaded).to(builder::multiThreaded); - map.from(this.properties::getConnectionTimeout).whenNonNull() - .asInt(Duration::toMillis).to(builder::connTimeout); - map.from(this.properties::getReadTimeout).whenNonNull().asInt(Duration::toMillis) + map.from(gson::getIfUnique).whenNonNull().to(builder::gson); + map.from(properties::isMultiThreaded).to(builder::multiThreaded); + map.from(properties::getConnectionTimeout).whenNonNull().asInt(Duration::toMillis) + .to(builder::connTimeout); + map.from(properties::getReadTimeout).whenNonNull().asInt(Duration::toMillis) .to(builder::readTimeout); - customize(builder); - return builder.build(); - } - - private void customize(HttpClientConfig.Builder builder) { - this.builderCustomizers.orderedStream() + builderCustomizers.orderedStream() .forEach((customizer) -> customizer.customize(builder)); + return builder.build(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java index 817f59028391..419cb850fcb7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/rest/RestClientAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -46,16 +46,6 @@ @EnableConfigurationProperties(RestClientProperties.class) public class RestClientAutoConfiguration { - private final RestClientProperties properties; - - private final ObjectProvider builderCustomizers; - - public RestClientAutoConfiguration(RestClientProperties properties, - ObjectProvider builderCustomizers) { - this.properties = properties; - this.builderCustomizers = builderCustomizers; - } - @Bean @ConditionalOnMissingBean public RestClient restClient(RestClientBuilder builder) { @@ -64,20 +54,21 @@ public RestClient restClient(RestClientBuilder builder) { @Bean @ConditionalOnMissingBean - public RestClientBuilder restClientBuilder() { - HttpHost[] hosts = this.properties.getUris().stream().map(HttpHost::create) + public RestClientBuilder restClientBuilder(RestClientProperties properties, + ObjectProvider builderCustomizers) { + HttpHost[] hosts = properties.getUris().stream().map(HttpHost::create) .toArray(HttpHost[]::new); RestClientBuilder builder = RestClient.builder(hosts); PropertyMapper map = PropertyMapper.get(); - map.from(this.properties::getUsername).whenHasText().to((username) -> { + map.from(properties::getUsername).whenHasText().to((username) -> { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials( - this.properties.getUsername(), this.properties.getPassword()); + properties.getUsername(), properties.getPassword()); credentialsProvider.setCredentials(AuthScope.ANY, credentials); builder.setHttpClientConfigCallback((httpClientBuilder) -> httpClientBuilder .setDefaultCredentialsProvider(credentialsProvider)); }); - this.builderCustomizers.orderedStream() + builderCustomizers.orderedStream() .forEach((customizer) -> customizer.customize(builder)); return builder; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java index 0a6ba394e7d1..582838f1d36b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -104,25 +104,8 @@ public FlywaySchemaManagementProvider flywayDefaultDdlModeProvider( @EnableConfigurationProperties({ DataSourceProperties.class, FlywayProperties.class }) public static class FlywayConfiguration { - private final FlywayProperties properties; - - private final DataSourceProperties dataSourceProperties; - - private final ResourceLoader resourceLoader; - - private final DataSource dataSource; - - private final DataSource flywayDataSource; - - private final FlywayMigrationStrategy migrationStrategy; - - private final List configurationCustomizers; - - private final List callbacks; - - private final List flywayCallbacks; - - public FlywayConfiguration(FlywayProperties properties, + @Bean + public Flyway flyway(FlywayProperties properties, DataSourceProperties dataSourceProperties, ResourceLoader resourceLoader, ObjectProvider dataSource, @FlywayDataSource ObjectProvider flywayDataSource, @@ -130,141 +113,135 @@ public FlywayConfiguration(FlywayProperties properties, ObjectProvider fluentConfigurationCustomizers, ObjectProvider callbacks, ObjectProvider flywayCallbacks) { - this.properties = properties; - this.dataSourceProperties = dataSourceProperties; - this.resourceLoader = resourceLoader; - this.dataSource = dataSource.getIfUnique(); - this.flywayDataSource = flywayDataSource.getIfAvailable(); - this.migrationStrategy = migrationStrategy.getIfAvailable(); - this.configurationCustomizers = fluentConfigurationCustomizers.orderedStream() - .collect(Collectors.toList()); - this.callbacks = callbacks.orderedStream().collect(Collectors.toList()); - this.flywayCallbacks = flywayCallbacks.orderedStream() - .collect(Collectors.toList()); - } - - @Bean - public Flyway flyway() { FluentConfiguration configuration = new FluentConfiguration(); - DataSource dataSource = configureDataSource(configuration); - checkLocationExists(dataSource); - configureProperties(configuration); - configureCallbacks(configuration); - this.configurationCustomizers + DataSource dataSourceToMigrate = configureDataSource(configuration, + properties, dataSourceProperties, flywayDataSource.getIfAvailable(), + dataSource.getIfAvailable()); + checkLocationExists(dataSourceToMigrate, properties, resourceLoader); + configureProperties(configuration, properties); + List orderedCallbacks = callbacks.orderedStream() + .collect(Collectors.toList()); + configureCallbacks(configuration, orderedCallbacks); + fluentConfigurationCustomizers.orderedStream() .forEach((customizer) -> customizer.customize(configuration)); Flyway flyway = configuration.load(); - configureFlywayCallbacks(flyway); + List orderedFlywayCallbacks = flywayCallbacks.orderedStream() + .collect(Collectors.toList()); + configureFlywayCallbacks(flyway, orderedCallbacks, orderedFlywayCallbacks); return flyway; } - private DataSource configureDataSource(FluentConfiguration configuration) { - if (this.properties.isCreateDataSource()) { - String url = getProperty(this.properties::getUrl, - this.dataSourceProperties::getUrl); - String user = getProperty(this.properties::getUser, - this.dataSourceProperties::getUsername); - String password = getProperty(this.properties::getPassword, - this.dataSourceProperties::getPassword); + private DataSource configureDataSource(FluentConfiguration configuration, + FlywayProperties properties, DataSourceProperties dataSourceProperties, + DataSource flywayDataSource, DataSource dataSource) { + if (properties.isCreateDataSource()) { + String url = getProperty(properties::getUrl, + dataSourceProperties::getUrl); + String user = getProperty(properties::getUser, + dataSourceProperties::getUsername); + String password = getProperty(properties::getPassword, + dataSourceProperties::getPassword); configuration.dataSource(url, user, password); - if (!CollectionUtils.isEmpty(this.properties.getInitSqls())) { - String initSql = StringUtils.collectionToDelimitedString( - this.properties.getInitSqls(), "\n"); + if (!CollectionUtils.isEmpty(properties.getInitSqls())) { + String initSql = StringUtils + .collectionToDelimitedString(properties.getInitSqls(), "\n"); configuration.initSql(initSql); } } - else if (this.flywayDataSource != null) { - configuration.dataSource(this.flywayDataSource); + else if (flywayDataSource != null) { + configuration.dataSource(flywayDataSource); } else { - configuration.dataSource(this.dataSource); + configuration.dataSource(dataSource); } return configuration.getDataSource(); } - private void checkLocationExists(DataSource dataSource) { - if (this.properties.isCheckLocation()) { + private void checkLocationExists(DataSource dataSource, + FlywayProperties properties, ResourceLoader resourceLoader) { + if (properties.isCheckLocation()) { String[] locations = new LocationResolver(dataSource) - .resolveLocations(this.properties.getLocations()); + .resolveLocations(properties.getLocations()); Assert.state(locations.length != 0, "Migration script locations not configured"); - boolean exists = hasAtLeastOneLocation(locations); + boolean exists = hasAtLeastOneLocation(resourceLoader, locations); Assert.state(exists, () -> "Cannot find migrations location in: " + Arrays.asList(locations) + " (please add migrations or check your Flyway configuration)"); } } - private void configureProperties(FluentConfiguration configuration) { + private void configureProperties(FluentConfiguration configuration, + FlywayProperties properties) { PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull(); String[] locations = new LocationResolver(configuration.getDataSource()) - .resolveLocations(this.properties.getLocations()); + .resolveLocations(properties.getLocations()); map.from(locations).to(configuration::locations); - map.from(this.properties.getEncoding()).to(configuration::encoding); - map.from(this.properties.getConnectRetries()) - .to(configuration::connectRetries); - map.from(this.properties.getSchemas()).as(StringUtils::toStringArray) + map.from(properties.getEncoding()).to(configuration::encoding); + map.from(properties.getConnectRetries()).to(configuration::connectRetries); + map.from(properties.getSchemas()).as(StringUtils::toStringArray) .to(configuration::schemas); - map.from(this.properties.getTable()).to(configuration::table); - map.from(this.properties.getBaselineDescription()) + map.from(properties.getTable()).to(configuration::table); + map.from(properties.getBaselineDescription()) .to(configuration::baselineDescription); - map.from(this.properties.getBaselineVersion()) - .to(configuration::baselineVersion); - map.from(this.properties.getInstalledBy()).to(configuration::installedBy); - map.from(this.properties.getPlaceholders()).to(configuration::placeholders); - map.from(this.properties.getPlaceholderPrefix()) + map.from(properties.getBaselineVersion()).to(configuration::baselineVersion); + map.from(properties.getInstalledBy()).to(configuration::installedBy); + map.from(properties.getPlaceholders()).to(configuration::placeholders); + map.from(properties.getPlaceholderPrefix()) .to(configuration::placeholderPrefix); - map.from(this.properties.getPlaceholderSuffix()) + map.from(properties.getPlaceholderSuffix()) .to(configuration::placeholderSuffix); - map.from(this.properties.isPlaceholderReplacement()) + map.from(properties.isPlaceholderReplacement()) .to(configuration::placeholderReplacement); - map.from(this.properties.getSqlMigrationPrefix()) + map.from(properties.getSqlMigrationPrefix()) .to(configuration::sqlMigrationPrefix); - map.from(this.properties.getSqlMigrationSuffixes()) - .as(StringUtils::toStringArray) + map.from(properties.getSqlMigrationSuffixes()).as(StringUtils::toStringArray) .to(configuration::sqlMigrationSuffixes); - map.from(this.properties.getSqlMigrationSeparator()) + map.from(properties.getSqlMigrationSeparator()) .to(configuration::sqlMigrationSeparator); - map.from(this.properties.getRepeatableSqlMigrationPrefix()) + map.from(properties.getRepeatableSqlMigrationPrefix()) .to(configuration::repeatableSqlMigrationPrefix); - map.from(this.properties.getTarget()).to(configuration::target); - map.from(this.properties.isBaselineOnMigrate()) + map.from(properties.getTarget()).to(configuration::target); + map.from(properties.isBaselineOnMigrate()) .to(configuration::baselineOnMigrate); - map.from(this.properties.isCleanDisabled()).to(configuration::cleanDisabled); - map.from(this.properties.isCleanOnValidationError()) + map.from(properties.isCleanDisabled()).to(configuration::cleanDisabled); + map.from(properties.isCleanOnValidationError()) .to(configuration::cleanOnValidationError); - map.from(this.properties.isGroup()).to(configuration::group); - map.from(this.properties.isIgnoreMissingMigrations()) + map.from(properties.isGroup()).to(configuration::group); + map.from(properties.isIgnoreMissingMigrations()) .to(configuration::ignoreMissingMigrations); - map.from(this.properties.isIgnoreIgnoredMigrations()) + map.from(properties.isIgnoreIgnoredMigrations()) .to(configuration::ignoreIgnoredMigrations); - map.from(this.properties.isIgnorePendingMigrations()) + map.from(properties.isIgnorePendingMigrations()) .to(configuration::ignorePendingMigrations); - map.from(this.properties.isIgnoreFutureMigrations()) + map.from(properties.isIgnoreFutureMigrations()) .to(configuration::ignoreFutureMigrations); - map.from(this.properties.isMixed()).to(configuration::mixed); - map.from(this.properties.isOutOfOrder()).to(configuration::outOfOrder); - map.from(this.properties.isSkipDefaultCallbacks()) + map.from(properties.isMixed()).to(configuration::mixed); + map.from(properties.isOutOfOrder()).to(configuration::outOfOrder); + map.from(properties.isSkipDefaultCallbacks()) .to(configuration::skipDefaultCallbacks); - map.from(this.properties.isSkipDefaultResolvers()) + map.from(properties.isSkipDefaultResolvers()) .to(configuration::skipDefaultResolvers); - map.from(this.properties.isValidateOnMigrate()) + map.from(properties.isValidateOnMigrate()) .to(configuration::validateOnMigrate); } - private void configureCallbacks(FluentConfiguration configuration) { - if (!this.callbacks.isEmpty()) { - configuration.callbacks(this.callbacks.toArray(new Callback[0])); + private void configureCallbacks(FluentConfiguration configuration, + List callbacks) { + if (!callbacks.isEmpty()) { + configuration.callbacks(callbacks.toArray(new Callback[0])); } } - private void configureFlywayCallbacks(Flyway flyway) { - if (!this.flywayCallbacks.isEmpty()) { - if (!this.callbacks.isEmpty()) { + private void configureFlywayCallbacks(Flyway flyway, List callbacks, + List flywayCallbacks) { + if (!flywayCallbacks.isEmpty()) { + if (!callbacks.isEmpty()) { throw new IllegalStateException( "Found a mixture of Callback and FlywayCallback beans." + " One type must be used exclusively."); } - flyway.setCallbacks(this.flywayCallbacks.toArray(new FlywayCallback[0])); + flyway.setCallbacks(flywayCallbacks.toArray(new FlywayCallback[0])); } } @@ -274,9 +251,10 @@ private String getProperty(Supplier property, return (value != null) ? value : defaultValue.get(); } - private boolean hasAtLeastOneLocation(String... locations) { + private boolean hasAtLeastOneLocation(ResourceLoader resourceLoader, + String... locations) { for (String location : locations) { - if (this.resourceLoader.getResource(normalizePrefix(location)).exists()) { + if (resourceLoader.getResource(normalizePrefix(location)).exists()) { return true; } } @@ -289,8 +267,10 @@ private String normalizePrefix(String location) { @Bean @ConditionalOnMissingBean - public FlywayMigrationInitializer flywayInitializer(Flyway flyway) { - return new FlywayMigrationInitializer(flyway, this.migrationStrategy); + public FlywayMigrationInitializer flywayInitializer(Flyway flyway, + ObjectProvider migrationStrategy) { + return new FlywayMigrationInitializer(flyway, + migrationStrategy.getIfAvailable()); } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java index 9368d7d11cff..58d798fa48a9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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,14 +74,11 @@ public static class GroovyMarkupConfiguration { private final GroovyTemplateProperties properties; - private final MarkupTemplateEngine templateEngine; - public GroovyMarkupConfiguration(ApplicationContext applicationContext, GroovyTemplateProperties properties, ObjectProvider templateEngine) { this.applicationContext = applicationContext; this.properties = properties; - this.templateEngine = templateEngine.getIfAvailable(); } @PostConstruct @@ -124,13 +121,12 @@ private boolean isUsingGroovyAllJar() { @Bean @ConditionalOnMissingBean(GroovyMarkupConfig.class) @ConfigurationProperties(prefix = "spring.groovy.template.configuration") - public GroovyMarkupConfigurer groovyMarkupConfigurer() { + public GroovyMarkupConfigurer groovyMarkupConfigurer( + ObjectProvider templateEngine) { GroovyMarkupConfigurer configurer = new GroovyMarkupConfigurer(); configurer.setResourceLoaderPath(this.properties.getResourceLoaderPath()); configurer.setCacheTemplates(this.properties.isCache()); - if (this.templateEngine != null) { - configurer.setTemplateEngine(this.templateEngine); - } + templateEngine.ifAvailable(configurer::setTemplateEngine); return configurer; } @@ -143,17 +139,12 @@ public GroovyMarkupConfigurer groovyMarkupConfigurer() { @ConditionalOnProperty(name = "spring.groovy.template.enabled", matchIfMissing = true) public static class GroovyWebConfiguration { - private final GroovyTemplateProperties properties; - - public GroovyWebConfiguration(GroovyTemplateProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean(name = "groovyMarkupViewResolver") - public GroovyMarkupViewResolver groovyMarkupViewResolver() { + public GroovyMarkupViewResolver groovyMarkupViewResolver( + GroovyTemplateProperties properties) { GroovyMarkupViewResolver resolver = new GroovyMarkupViewResolver(); - this.properties.applyToMvcViewResolver(resolver); + properties.applyToMvcViewResolver(resolver); return resolver; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java index 064a11067ba3..3c5e7eba9a13 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -43,19 +43,13 @@ @EnableConfigurationProperties(H2ConsoleProperties.class) public class H2ConsoleAutoConfiguration { - private final H2ConsoleProperties properties; - - public H2ConsoleAutoConfiguration(H2ConsoleProperties properties) { - this.properties = properties; - } - @Bean - public ServletRegistrationBean h2Console() { - String path = this.properties.getPath(); + public ServletRegistrationBean h2Console(H2ConsoleProperties properties) { + String path = properties.getPath(); String urlMapping = path + (path.endsWith("/") ? "*" : "/*"); ServletRegistrationBean registration = new ServletRegistrationBean<>( new WebServlet(), urlMapping); - H2ConsoleProperties.Settings settings = this.properties.getSettings(); + H2ConsoleProperties.Settings settings = properties.getSettings(); if (settings.isTrace()) { registration.addInitParameter("trace", ""); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersAutoConfiguration.java index 19c13148bdda..92cb822e7ae9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersAutoConfiguration.java @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.http; -import java.util.List; import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; @@ -64,17 +63,12 @@ public class HttpMessageConvertersAutoConfiguration { static final String PREFERRED_MAPPER_PROPERTY = "spring.http.converters.preferred-json-mapper"; - private final List> converters; - - public HttpMessageConvertersAutoConfiguration( - ObjectProvider> convertersProvider) { - this.converters = convertersProvider.orderedStream().collect(Collectors.toList()); - } - @Bean @ConditionalOnMissingBean - public HttpMessageConverters messageConverters() { - return new HttpMessageConverters(this.converters); + public HttpMessageConverters messageConverters( + ObjectProvider> converters) { + return new HttpMessageConverters( + converters.orderedStream().collect(Collectors.toList())); } @Configuration @@ -82,17 +76,12 @@ public HttpMessageConverters messageConverters() { @EnableConfigurationProperties(HttpProperties.class) protected static class StringHttpMessageConverterConfiguration { - private final HttpProperties.Encoding properties; - - protected StringHttpMessageConverterConfiguration(HttpProperties httpProperties) { - this.properties = httpProperties.getEncoding(); - } - @Bean @ConditionalOnMissingBean - public StringHttpMessageConverter stringHttpMessageConverter() { + public StringHttpMessageConverter stringHttpMessageConverter( + HttpProperties httpProperties) { StringHttpMessageConverter converter = new StringHttpMessageConverter( - this.properties.getCharset()); + httpProperties.getEncoding().getCharset()); converter.setWriteAcceptCharset(false); return converter; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java index 850e49cbd6c6..2a1e75feaa26 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/influx/InfluxDbAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -46,16 +46,15 @@ public class InfluxDbAutoConfiguration { private static final Log logger = LogFactory.getLog(InfluxDbAutoConfiguration.class); - private final InfluxDbProperties properties; - - private final OkHttpClient.Builder builder; - - public InfluxDbAutoConfiguration(InfluxDbProperties properties, + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty("spring.influx.url") + public InfluxDB influxDb(InfluxDbProperties properties, ObjectProvider builder, ObjectProvider deprecatedBuilder) { - this.properties = properties; - this.builder = determineBuilder(builder.getIfAvailable(), - deprecatedBuilder.getIfAvailable()); + return new InfluxDBImpl(properties.getUrl(), properties.getUser(), + properties.getPassword(), determineBuilder(builder.getIfAvailable(), + deprecatedBuilder.getIfAvailable())); } @Deprecated @@ -75,12 +74,4 @@ else if (deprecatedBuilder != null) { return new OkHttpClient.Builder(); } - @Bean - @ConditionalOnMissingBean - @ConditionalOnProperty("spring.influx.url") - public InfluxDB influxDb() { - return new InfluxDBImpl(this.properties.getUrl(), this.properties.getUser(), - this.properties.getPassword(), this.builder); - } - } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java index 8e187455ef90..6ae8da6ff131 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,9 +19,7 @@ import javax.management.MBeanServer; import javax.sql.DataSource; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -32,7 +30,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.EnvironmentAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -81,34 +78,19 @@ protected static class IntegrationConfiguration { @ConditionalOnMissingBean(value = IntegrationMBeanExporter.class, search = SearchStrategy.CURRENT) @ConditionalOnBean(MBeanServer.class) @ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true) - protected static class IntegrationJmxConfiguration - implements EnvironmentAware, BeanFactoryAware { - - private BeanFactory beanFactory; - - private Environment environment; - - @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.beanFactory = beanFactory; - } - - @Override - public void setEnvironment(Environment environment) { - this.environment = environment; - } + protected static class IntegrationJmxConfiguration { @Bean - public IntegrationMBeanExporter integrationMbeanExporter() { + public IntegrationMBeanExporter integrationMbeanExporter(BeanFactory beanFactory, + Environment environment) { IntegrationMBeanExporter exporter = new IntegrationMBeanExporter(); - String defaultDomain = this.environment - .getProperty("spring.jmx.default-domain"); + String defaultDomain = environment.getProperty("spring.jmx.default-domain"); if (StringUtils.hasLength(defaultDomain)) { exporter.setDefaultDomain(defaultDomain); } - String serverBean = this.environment.getProperty("spring.jmx.server", + String serverBean = environment.getProperty("spring.jmx.server", "mbeanServer"); - exporter.setServer(this.beanFactory.getBean(serverBean, MBeanServer.class)); + exporter.setServer(beanFactory.getBean(serverBean, MBeanServer.class)); return exporter; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java index 43671acc1e51..709921d67f06 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -116,16 +116,12 @@ static class JodaDateTimeJacksonConfiguration { private static final Log logger = LogFactory .getLog(JodaDateTimeJacksonConfiguration.class); - private final JacksonProperties jacksonProperties; - - JodaDateTimeJacksonConfiguration(JacksonProperties jacksonProperties) { - this.jacksonProperties = jacksonProperties; - } - @Bean - public SimpleModule jodaDateTimeSerializationModule() { + public SimpleModule jodaDateTimeSerializationModule( + JacksonProperties jacksonProperties) { SimpleModule module = new SimpleModule(); - JacksonJodaDateFormat jacksonJodaFormat = getJacksonJodaDateFormat(); + JacksonJodaDateFormat jacksonJodaFormat = getJacksonJodaDateFormat( + jacksonProperties); if (jacksonJodaFormat != null) { module.addSerializer(DateTime.class, new DateTimeSerializer(jacksonJodaFormat, 0)); @@ -133,17 +129,17 @@ public SimpleModule jodaDateTimeSerializationModule() { return module; } - private JacksonJodaDateFormat getJacksonJodaDateFormat() { - if (this.jacksonProperties.getJodaDateTimeFormat() != null) { + private JacksonJodaDateFormat getJacksonJodaDateFormat( + JacksonProperties jacksonProperties) { + if (jacksonProperties.getJodaDateTimeFormat() != null) { return new JacksonJodaDateFormat(DateTimeFormat - .forPattern(this.jacksonProperties.getJodaDateTimeFormat()) + .forPattern(jacksonProperties.getJodaDateTimeFormat()) .withZoneUTC()); } - if (this.jacksonProperties.getDateFormat() != null) { + if (jacksonProperties.getDateFormat() != null) { try { return new JacksonJodaDateFormat(DateTimeFormat - .forPattern(this.jacksonProperties.getDateFormat()) - .withZoneUTC()); + .forPattern(jacksonProperties.getDateFormat()).withZoneUTC()); } catch (IllegalArgumentException ex) { if (logger.isWarnEnabled()) { @@ -175,18 +171,13 @@ public ParameterNamesModule parameterNamesModule() { @ConditionalOnClass(Jackson2ObjectMapperBuilder.class) static class JacksonObjectMapperBuilderConfiguration { - private final ApplicationContext applicationContext; - - JacksonObjectMapperBuilderConfiguration(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; - } - @Bean @ConditionalOnMissingBean public Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder( + ApplicationContext applicationContext, List customizers) { Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); - builder.applicationContext(this.applicationContext); + builder.applicationContext(applicationContext); customize(builder, customizers); return builder; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration.java index e37281232614..7deb2f2ba7fb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceTransactionManagerAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -52,26 +52,14 @@ public class DataSourceTransactionManagerAutoConfiguration { @ConditionalOnSingleCandidate(DataSource.class) static class DataSourceTransactionManagerConfiguration { - private final DataSource dataSource; - - private final TransactionManagerCustomizers transactionManagerCustomizers; - - DataSourceTransactionManagerConfiguration(DataSource dataSource, - ObjectProvider transactionManagerCustomizers) { - this.dataSource = dataSource; - this.transactionManagerCustomizers = transactionManagerCustomizers - .getIfAvailable(); - } - @Bean @ConditionalOnMissingBean(PlatformTransactionManager.class) - public DataSourceTransactionManager transactionManager( - DataSourceProperties properties) { + public DataSourceTransactionManager transactionManager(DataSource dataSource, + ObjectProvider transactionManagerCustomizers) { DataSourceTransactionManager transactionManager = new DataSourceTransactionManager( - this.dataSource); - if (this.transactionManagerCustomizers != null) { - this.transactionManagerCustomizers.customize(transactionManager); - } + dataSource); + transactionManagerCustomizers.ifAvailable( + (customizers) -> customizers.customize(transactionManager)); return transactionManager; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java index ea524ee6009c..e86cb984497f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/EmbeddedDataSourceConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,8 +16,6 @@ package org.springframework.boot.autoconfigure.jdbc; -import javax.annotation.PreDestroy; - import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; @@ -37,34 +35,18 @@ @EnableConfigurationProperties(DataSourceProperties.class) public class EmbeddedDataSourceConfiguration implements BeanClassLoaderAware { - private EmbeddedDatabase database; - private ClassLoader classLoader; - private final DataSourceProperties properties; - - public EmbeddedDataSourceConfiguration(DataSourceProperties properties) { - this.properties = properties; - } - @Override public void setBeanClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } - @Bean - public EmbeddedDatabase dataSource() { - this.database = new EmbeddedDatabaseBuilder() + @Bean(destroyMethod = "shutdown") + public EmbeddedDatabase dataSource(DataSourceProperties properties) { + return new EmbeddedDatabaseBuilder() .setType(EmbeddedDatabaseConnection.get(this.classLoader).getType()) - .setName(this.properties.determineDatabaseName()).build(); - return this.database; - } - - @PreDestroy - public void close() { - if (this.database != null) { - this.database.shutdown(); - } + .setName(properties.determineDatabaseName()).build(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration.java index 69d09d8ad410..9e77c1dfdb00 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -53,21 +53,13 @@ public class JdbcTemplateAutoConfiguration { @Configuration static class JdbcTemplateConfiguration { - private final DataSource dataSource; - - private final JdbcProperties properties; - - JdbcTemplateConfiguration(DataSource dataSource, JdbcProperties properties) { - this.dataSource = dataSource; - this.properties = properties; - } - @Bean @Primary @ConditionalOnMissingBean(JdbcOperations.class) - public JdbcTemplate jdbcTemplate() { - JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource); - JdbcProperties.Template template = this.properties.getTemplate(); + public JdbcTemplate jdbcTemplate(DataSource dataSource, + JdbcProperties properties) { + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + JdbcProperties.Template template = properties.getTemplate(); jdbcTemplate.setFetchSize(template.getFetchSize()); jdbcTemplate.setMaxRows(template.getMaxRows()); if (template.getQueryTimeout() != null) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfiguration.java index dcfd3a9a28da..f55f19c6d8f7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -48,24 +48,20 @@ @EnableConfigurationProperties(DataSourceProperties.class) public class JndiDataSourceAutoConfiguration { - private final ApplicationContext context; - - public JndiDataSourceAutoConfiguration(ApplicationContext context) { - this.context = context; - } - @Bean(destroyMethod = "") @ConditionalOnMissingBean - public DataSource dataSource(DataSourceProperties properties) { + public DataSource dataSource(DataSourceProperties properties, + ApplicationContext context) { JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); DataSource dataSource = dataSourceLookup.getDataSource(properties.getJndiName()); - excludeMBeanIfNecessary(dataSource, "dataSource"); + excludeMBeanIfNecessary(dataSource, "dataSource", context); return dataSource; } - private void excludeMBeanIfNecessary(Object candidate, String beanName) { - for (MBeanExporter mbeanExporter : this.context - .getBeansOfType(MBeanExporter.class).values()) { + private void excludeMBeanIfNecessary(Object candidate, String beanName, + ApplicationContext context) { + for (MBeanExporter mbeanExporter : context.getBeansOfType(MBeanExporter.class) + .values()) { if (JmxUtils.isMBean(candidate.getClass())) { mbeanExporter.addExcludedBean(beanName); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java index b46b437e5c83..afe3a9eeb181 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/XADataSourceAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -61,28 +61,14 @@ @ConditionalOnMissingBean(DataSource.class) public class XADataSourceAutoConfiguration implements BeanClassLoaderAware { - private final XADataSourceWrapper wrapper; - - private final DataSourceProperties properties; - - private final XADataSource xaDataSource; - private ClassLoader classLoader; - public XADataSourceAutoConfiguration(XADataSourceWrapper wrapper, - DataSourceProperties properties, ObjectProvider xaDataSource) { - this.wrapper = wrapper; - this.properties = properties; - this.xaDataSource = xaDataSource.getIfAvailable(); - } - @Bean - public DataSource dataSource() throws Exception { - XADataSource xaDataSource = this.xaDataSource; - if (xaDataSource == null) { - xaDataSource = createXaDataSource(); - } - return this.wrapper.wrapDataSource(xaDataSource); + public DataSource dataSource(XADataSourceWrapper wrapper, + DataSourceProperties properties, ObjectProvider xaDataSource) + throws Exception { + return wrapper.wrapDataSource( + xaDataSource.getIfAvailable(() -> createXaDataSource(properties))); } @Override @@ -90,16 +76,16 @@ public void setBeanClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } - private XADataSource createXaDataSource() { - String className = this.properties.getXa().getDataSourceClassName(); + private XADataSource createXaDataSource(DataSourceProperties properties) { + String className = properties.getXa().getDataSourceClassName(); if (!StringUtils.hasLength(className)) { - className = DatabaseDriver.fromJdbcUrl(this.properties.determineUrl()) + className = DatabaseDriver.fromJdbcUrl(properties.determineUrl()) .getXaDataSourceClassName(); } Assert.state(StringUtils.hasLength(className), "No XA DataSource class name specified"); XADataSource dataSource = createXaDataSourceInstance(className); - bindXaProperties(dataSource, this.properties); + bindXaProperties(dataSource, properties); return dataSource; } @@ -125,9 +111,9 @@ private void bindXaProperties(XADataSource target, private ConfigurationPropertySource getBinderSource( DataSourceProperties dataSourceProperties) { MapConfigurationPropertySource source = new MapConfigurationPropertySource(); - source.put("user", this.properties.determineUsername()); - source.put("password", this.properties.determinePassword()); - source.put("url", this.properties.determineUrl()); + source.put("user", dataSourceProperties.determineUsername()); + source.put("password", dataSourceProperties.determinePassword()); + source.put("url", dataSourceProperties.determineUrl()); source.putAll(dataSourceProperties.getXa().getProperties()); ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases(); aliases.addAliases("user", "username"); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java index 08fcc3f3f41c..3cfae64adac4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/JndiConnectionFactoryAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -55,28 +55,23 @@ public class JndiConnectionFactoryAutoConfiguration { private static final String[] JNDI_LOCATIONS = { "java:/JmsXA", "java:/XAConnectionFactory" }; - private final JmsProperties properties; - - private final JndiLocatorDelegate jndiLocatorDelegate; - - public JndiConnectionFactoryAutoConfiguration(JmsProperties properties) { - this.properties = properties; - this.jndiLocatorDelegate = JndiLocatorDelegate.createDefaultResourceRefLocator(); - } - @Bean - public ConnectionFactory connectionFactory() throws NamingException { - if (StringUtils.hasLength(this.properties.getJndiName())) { - return this.jndiLocatorDelegate.lookup(this.properties.getJndiName(), + public ConnectionFactory connectionFactory(JmsProperties properties) + throws NamingException { + JndiLocatorDelegate jndiLocatorDelegate = JndiLocatorDelegate + .createDefaultResourceRefLocator(); + if (StringUtils.hasLength(properties.getJndiName())) { + return jndiLocatorDelegate.lookup(properties.getJndiName(), ConnectionFactory.class); } - return findJndiConnectionFactory(); + return findJndiConnectionFactory(jndiLocatorDelegate); } - private ConnectionFactory findJndiConnectionFactory() { + private ConnectionFactory findJndiConnectionFactory( + JndiLocatorDelegate jndiLocatorDelegate) { for (String name : JNDI_LOCATIONS) { try { - return this.jndiLocatorDelegate.lookup(name, ConnectionFactory.class); + return jndiLocatorDelegate.lookup(name, ConnectionFactory.class); } catch (NamingException ex) { // Swallow and continue diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java index a7116b379f73..9af33abaf77a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryConfiguration.java @@ -54,16 +54,12 @@ class ActiveMQConnectionFactoryConfiguration { @ConditionalOnProperty(prefix = "spring.activemq.pool", name = "enabled", havingValue = "false", matchIfMissing = true) static class SimpleConnectionFactoryConfiguration { - private final JmsProperties jmsProperties; - private final ActiveMQProperties properties; private final List connectionFactoryCustomizers; - SimpleConnectionFactoryConfiguration(JmsProperties jmsProperties, - ActiveMQProperties properties, + SimpleConnectionFactoryConfiguration(ActiveMQProperties properties, ObjectProvider connectionFactoryCustomizers) { - this.jmsProperties = jmsProperties; this.properties = properties; this.connectionFactoryCustomizers = connectionFactoryCustomizers .orderedStream().collect(Collectors.toList()); @@ -71,8 +67,9 @@ static class SimpleConnectionFactoryConfiguration { @Bean @ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "true", matchIfMissing = true) - public CachingConnectionFactory cachingJmsConnectionFactory() { - JmsProperties.Cache cacheProperties = this.jmsProperties.getCache(); + public CachingConnectionFactory cachingJmsConnectionFactory( + JmsProperties jmsProperties) { + JmsProperties.Cache cacheProperties = jmsProperties.getCache(); CachingConnectionFactory connectionFactory = new CachingConnectionFactory( createConnectionFactory()); connectionFactory.setCacheConsumers(cacheProperties.isConsumers()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisConnectionFactoryConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisConnectionFactoryConfiguration.java index a4b526df823a..7eb09b8e3f26 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisConnectionFactoryConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisConnectionFactoryConfiguration.java @@ -48,23 +48,21 @@ class ArtemisConnectionFactoryConfiguration { @ConditionalOnProperty(prefix = "spring.artemis.pool", name = "enabled", havingValue = "false", matchIfMissing = true) static class SimpleConnectionFactoryConfiguration { - private final JmsProperties jmsProperties; - private final ArtemisProperties properties; private final ListableBeanFactory beanFactory; - SimpleConnectionFactoryConfiguration(JmsProperties jmsProperties, - ArtemisProperties properties, ListableBeanFactory beanFactory) { - this.jmsProperties = jmsProperties; + SimpleConnectionFactoryConfiguration(ArtemisProperties properties, + ListableBeanFactory beanFactory) { this.properties = properties; this.beanFactory = beanFactory; } @Bean @ConditionalOnProperty(prefix = "spring.jms.cache", name = "enabled", havingValue = "true", matchIfMissing = true) - public CachingConnectionFactory cachingJmsConnectionFactory() { - JmsProperties.Cache cacheProperties = this.jmsProperties.getCache(); + public CachingConnectionFactory cachingJmsConnectionFactory( + JmsProperties jmsProperties) { + JmsProperties.Cache cacheProperties = jmsProperties.getCache(); CachingConnectionFactory connectionFactory = new CachingConnectionFactory( createConnectionFactory()); connectionFactory.setCacheConsumers(cacheProperties.isConsumers()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedServerConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedServerConfiguration.java index fead43342d3b..2d895cb81b95 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedServerConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedServerConfiguration.java @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.jms.artemis; -import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -49,22 +48,8 @@ class ArtemisEmbeddedServerConfiguration { private final ArtemisProperties properties; - private final ObjectProvider configurationCustomizers; - - private final List queuesConfiguration; - - private final List topicsConfiguration; - - ArtemisEmbeddedServerConfiguration(ArtemisProperties properties, - ObjectProvider configurationCustomizers, - ObjectProvider queuesConfiguration, - ObjectProvider topicsConfiguration) { + ArtemisEmbeddedServerConfiguration(ArtemisProperties properties) { this.properties = properties; - this.configurationCustomizers = configurationCustomizers; - this.queuesConfiguration = queuesConfiguration.orderedStream() - .collect(Collectors.toList()); - this.topicsConfiguration = topicsConfiguration.orderedStream() - .collect(Collectors.toList()); } @Bean @@ -78,35 +63,33 @@ public org.apache.activemq.artemis.core.config.Configuration artemisConfiguratio @ConditionalOnMissingBean public EmbeddedJMS artemisServer( org.apache.activemq.artemis.core.config.Configuration configuration, - JMSConfiguration jmsConfiguration) { + JMSConfiguration jmsConfiguration, + ObjectProvider configurationCustomizers) { EmbeddedJMS server = new EmbeddedJMS(); - customize(configuration); + configurationCustomizers.orderedStream() + .forEach((customizer) -> customizer.customize(configuration)); server.setConfiguration(configuration); server.setJmsConfiguration(jmsConfiguration); server.setRegistry(new ArtemisNoOpBindingRegistry()); return server; } - private void customize( - org.apache.activemq.artemis.core.config.Configuration configuration) { - this.configurationCustomizers.orderedStream() - .forEach((customizer) -> customizer.customize(configuration)); - } - @Bean @ConditionalOnMissingBean - public JMSConfiguration artemisJmsConfiguration() { + public JMSConfiguration artemisJmsConfiguration( + ObjectProvider queuesConfiguration, + ObjectProvider topicsConfiguration) { JMSConfiguration configuration = new JMSConfigurationImpl(); - addAll(configuration.getQueueConfigurations(), this.queuesConfiguration); - addAll(configuration.getTopicConfigurations(), this.topicsConfiguration); + addAll(configuration.getQueueConfigurations(), queuesConfiguration); + addAll(configuration.getTopicConfigurations(), topicsConfiguration); addQueues(configuration, this.properties.getEmbedded().getQueues()); addTopics(configuration, this.properties.getEmbedded().getTopics()); return configuration; } - private void addAll(List list, Collection items) { + private void addAll(List list, ObjectProvider items) { if (items != null) { - list.addAll(items); + list.addAll(items.orderedStream().collect(Collectors.toList())); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java index 7ad04ac7663c..3f297b3b44d9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jmx/JmxAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,15 +18,12 @@ import javax.management.MBeanServer; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.SearchStrategy; -import org.springframework.context.EnvironmentAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableMBeanExport; @@ -54,33 +51,26 @@ @Configuration @ConditionalOnClass({ MBeanExporter.class }) @ConditionalOnProperty(prefix = "spring.jmx", name = "enabled", havingValue = "true", matchIfMissing = true) -public class JmxAutoConfiguration implements EnvironmentAware, BeanFactoryAware { +public class JmxAutoConfiguration { - private Environment environment; + private final Environment environment; - private BeanFactory beanFactory; - - @Override - public void setEnvironment(Environment environment) { + public JmxAutoConfiguration(Environment environment) { this.environment = environment; } - @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.beanFactory = beanFactory; - } - @Bean @Primary @ConditionalOnMissingBean(value = MBeanExporter.class, search = SearchStrategy.CURRENT) - public AnnotationMBeanExporter mbeanExporter(ObjectNamingStrategy namingStrategy) { + public AnnotationMBeanExporter mbeanExporter(ObjectNamingStrategy namingStrategy, + BeanFactory beanFactory) { AnnotationMBeanExporter exporter = new AnnotationMBeanExporter(); exporter.setRegistrationPolicy(RegistrationPolicy.FAIL_ON_EXISTING); exporter.setNamingStrategy(namingStrategy); String serverBean = this.environment.getProperty("spring.jmx.server", "mbeanServer"); if (StringUtils.hasLength(serverBean)) { - exporter.setServer(this.beanFactory.getBean(serverBean, MBeanServer.class)); + exporter.setServer(beanFactory.getBean(serverBean, MBeanServer.class)); } return exporter; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java index bc239df595e7..c044ddf73d2d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -90,56 +90,6 @@ public DefaultExecuteListenerProvider jooqExceptionTranslatorExecuteListenerProv @EnableConfigurationProperties(JooqProperties.class) public static class DslContextConfiguration { - private final JooqProperties properties; - - private final ConnectionProvider connection; - - private final DataSource dataSource; - - private final TransactionProvider transactionProvider; - - private final RecordMapperProvider recordMapperProvider; - - private final RecordUnmapperProvider recordUnmapperProvider; - - private final Settings settings; - - private final RecordListenerProvider[] recordListenerProviders; - - private final ExecuteListenerProvider[] executeListenerProviders; - - private final VisitListenerProvider[] visitListenerProviders; - - private final TransactionListenerProvider[] transactionListenerProviders; - - private final ExecutorProvider executorProvider; - - public DslContextConfiguration(JooqProperties properties, - ConnectionProvider connectionProvider, DataSource dataSource, - ObjectProvider transactionProvider, - ObjectProvider recordMapperProvider, - ObjectProvider recordUnmapperProvider, - ObjectProvider settings, - ObjectProvider recordListenerProviders, - ExecuteListenerProvider[] executeListenerProviders, - ObjectProvider visitListenerProviders, - ObjectProvider transactionListenerProviders, - ObjectProvider executorProvider) { - this.properties = properties; - this.connection = connectionProvider; - this.dataSource = dataSource; - this.transactionProvider = transactionProvider.getIfAvailable(); - this.recordMapperProvider = recordMapperProvider.getIfAvailable(); - this.recordUnmapperProvider = recordUnmapperProvider.getIfAvailable(); - this.settings = settings.getIfAvailable(); - this.recordListenerProviders = recordListenerProviders.getIfAvailable(); - this.executeListenerProviders = executeListenerProviders; - this.visitListenerProviders = visitListenerProviders.getIfAvailable(); - this.transactionListenerProviders = transactionListenerProviders - .getIfAvailable(); - this.executorProvider = executorProvider.getIfAvailable(); - } - @Bean public DefaultDSLContext dslContext(org.jooq.Configuration configuration) { return new DefaultDSLContext(configuration); @@ -147,30 +97,33 @@ public DefaultDSLContext dslContext(org.jooq.Configuration configuration) { @Bean @ConditionalOnMissingBean(org.jooq.Configuration.class) - public DefaultConfiguration jooqConfiguration() { + public DefaultConfiguration jooqConfiguration(JooqProperties properties, + ConnectionProvider connectionProvider, DataSource dataSource, + ObjectProvider transactionProvider, + ObjectProvider recordMapperProvider, + ObjectProvider recordUnmapperProvider, + ObjectProvider settings, + ObjectProvider recordListenerProviders, + ObjectProvider executeListenerProviders, + ObjectProvider visitListenerProviders, + ObjectProvider transactionListenerProviders, + ObjectProvider executorProvider) { DefaultConfiguration configuration = new DefaultConfiguration(); - configuration.set(this.properties.determineSqlDialect(this.dataSource)); - configuration.set(this.connection); - if (this.transactionProvider != null) { - configuration.set(this.transactionProvider); - } - if (this.recordMapperProvider != null) { - configuration.set(this.recordMapperProvider); - } - if (this.recordUnmapperProvider != null) { - configuration.set(this.recordUnmapperProvider); - } - if (this.settings != null) { - configuration.set(this.settings); - } - if (this.executorProvider != null) { - configuration.set(this.executorProvider); - } - configuration.set(this.recordListenerProviders); - configuration.set(this.executeListenerProviders); - configuration.set(this.visitListenerProviders); - configuration - .setTransactionListenerProvider(this.transactionListenerProviders); + configuration.set(properties.determineSqlDialect(dataSource)); + configuration.set(connectionProvider); + transactionProvider.ifAvailable(configuration::set); + recordMapperProvider.ifAvailable(configuration::set); + recordUnmapperProvider.ifAvailable(configuration::set); + settings.ifAvailable(configuration::set); + executorProvider.ifAvailable(configuration::set); + configuration.set(recordListenerProviders.orderedStream() + .toArray(RecordListenerProvider[]::new)); + configuration.set(executeListenerProviders.orderedStream() + .toArray(ExecuteListenerProvider[]::new)); + configuration.set(visitListenerProviders.orderedStream() + .toArray(VisitListenerProvider[]::new)); + configuration.setTransactionListenerProvider(transactionListenerProviders + .orderedStream().toArray(TransactionListenerProvider[]::new)); return configuration; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.java index 7750b3fd5c2b..4ba2a32df035 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -58,24 +58,19 @@ public class KafkaAutoConfiguration { private final KafkaProperties properties; - private final RecordMessageConverter messageConverter; - - public KafkaAutoConfiguration(KafkaProperties properties, - ObjectProvider messageConverter) { + public KafkaAutoConfiguration(KafkaProperties properties) { this.properties = properties; - this.messageConverter = messageConverter.getIfUnique(); } @Bean @ConditionalOnMissingBean(KafkaTemplate.class) public KafkaTemplate kafkaTemplate( ProducerFactory kafkaProducerFactory, - ProducerListener kafkaProducerListener) { + ProducerListener kafkaProducerListener, + ObjectProvider messageConverter) { KafkaTemplate kafkaTemplate = new KafkaTemplate<>( kafkaProducerFactory); - if (this.messageConverter != null) { - kafkaTemplate.setMessageConverter(this.messageConverter); - } + messageConverter.ifUnique(kafkaTemplate::setMessageConverter); kafkaTemplate.setProducerListener(kafkaProducerListener); kafkaTemplate.setDefaultTopic(this.properties.getTemplate().getDefaultTopic()); return kafkaTemplate; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java index 794414b98e79..57b930837ce6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/LdapAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -42,26 +42,18 @@ @EnableConfigurationProperties(LdapProperties.class) public class LdapAutoConfiguration { - private final LdapProperties properties; - - private final Environment environment; - - public LdapAutoConfiguration(LdapProperties properties, Environment environment) { - this.properties = properties; - this.environment = environment; - } - @Bean @ConditionalOnMissingBean - public LdapContextSource ldapContextSource() { + public LdapContextSource ldapContextSource(LdapProperties properties, + Environment environment) { LdapContextSource source = new LdapContextSource(); - source.setUserDn(this.properties.getUsername()); - source.setPassword(this.properties.getPassword()); - source.setAnonymousReadOnly(this.properties.getAnonymousReadOnly()); - source.setBase(this.properties.getBase()); - source.setUrls(this.properties.determineUrls(this.environment)); + source.setUserDn(properties.getUsername()); + source.setPassword(properties.getPassword()); + source.setAnonymousReadOnly(properties.getAnonymousReadOnly()); + source.setBase(properties.getBase()); + source.setUrls(properties.determineUrls(environment)); source.setBaseEnvironmentProperties( - Collections.unmodifiableMap(this.properties.getBaseEnvironment())); + Collections.unmodifiableMap(properties.getBaseEnvironment())); return source; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java index 741e377e6962..61a3bd06be04 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,38 +80,29 @@ public class EmbeddedLdapAutoConfiguration { private final EmbeddedLdapProperties embeddedProperties; - private final LdapProperties properties; - - private final ConfigurableApplicationContext applicationContext; - - private final Environment environment; - private InMemoryDirectoryServer server; - public EmbeddedLdapAutoConfiguration(EmbeddedLdapProperties embeddedProperties, - LdapProperties properties, ConfigurableApplicationContext applicationContext, - Environment environment) { + public EmbeddedLdapAutoConfiguration(EmbeddedLdapProperties embeddedProperties) { this.embeddedProperties = embeddedProperties; - this.properties = properties; - this.applicationContext = applicationContext; - this.environment = environment; } @Bean @DependsOn("directoryServer") @ConditionalOnMissingBean - public LdapContextSource ldapContextSource() { + public LdapContextSource ldapContextSource(Environment environment, + LdapProperties properties) { LdapContextSource source = new LdapContextSource(); if (hasCredentials(this.embeddedProperties.getCredential())) { source.setUserDn(this.embeddedProperties.getCredential().getUsername()); source.setPassword(this.embeddedProperties.getCredential().getPassword()); } - source.setUrls(this.properties.determineUrls(this.environment)); + source.setUrls(properties.determineUrls(environment)); return source; } @Bean - public InMemoryDirectoryServer directoryServer() throws LDAPException { + public InMemoryDirectoryServer directoryServer(ApplicationContext applicationContext) + throws LDAPException { String[] baseDn = StringUtils.toStringArray(this.embeddedProperties.getBaseDn()); InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig(baseDn); if (hasCredentials(this.embeddedProperties.getCredential())) { @@ -124,9 +115,9 @@ public InMemoryDirectoryServer directoryServer() throws LDAPException { .createLDAPConfig("LDAP", this.embeddedProperties.getPort()); config.setListenerConfigs(listenerConfig); this.server = new InMemoryDirectoryServer(config); - importLdif(); + importLdif(applicationContext); this.server.startListening(); - setPortProperty(this.applicationContext, this.server.getListenPort()); + setPortProperty(applicationContext, this.server.getListenPort()); return this.server; } @@ -158,11 +149,11 @@ private boolean hasCredentials(Credential credential) { && StringUtils.hasText(credential.getPassword()); } - private void importLdif() throws LDAPException { + private void importLdif(ApplicationContext applicationContext) throws LDAPException { String location = this.embeddedProperties.getLdif(); if (StringUtils.hasText(location)) { try { - Resource resource = this.applicationContext.getResource(location); + Resource resource = applicationContext.getResource(location); if (resource.exists()) { try (InputStream inputStream = resource.getInputStream()) { this.server.importFromLDIF(true, new LDIFReader(inputStream)); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java index cd5fdc03f0ec..86b07e927057 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -83,23 +83,12 @@ public static class LiquibaseConfiguration { private final LiquibaseProperties properties; - private final DataSourceProperties dataSourceProperties; - private final ResourceLoader resourceLoader; - private final DataSource dataSource; - - private final DataSource liquibaseDataSource; - public LiquibaseConfiguration(LiquibaseProperties properties, - DataSourceProperties dataSourceProperties, ResourceLoader resourceLoader, - ObjectProvider dataSource, - @LiquibaseDataSource ObjectProvider liquibaseDataSource) { + ResourceLoader resourceLoader) { this.properties = properties; - this.dataSourceProperties = dataSourceProperties; this.resourceLoader = resourceLoader; - this.dataSource = dataSource.getIfUnique(); - this.liquibaseDataSource = liquibaseDataSource.getIfAvailable(); } @PostConstruct @@ -115,8 +104,12 @@ public void checkChangelogExists() { } @Bean - public SpringLiquibase liquibase() { - SpringLiquibase liquibase = createSpringLiquibase(); + public SpringLiquibase liquibase(DataSourceProperties dataSourceProperties, + ObjectProvider dataSource, + @LiquibaseDataSource ObjectProvider liquibaseDataSource) { + SpringLiquibase liquibase = createSpringLiquibase( + liquibaseDataSource.getIfAvailable(), dataSource.getIfUnique(), + dataSourceProperties); liquibase.setChangeLog(this.properties.getChangeLog()); liquibase.setContexts(this.properties.getContexts()); liquibase.setDefaultSchema(this.properties.getDefaultSchema()); @@ -135,35 +128,39 @@ public SpringLiquibase liquibase() { return liquibase; } - private SpringLiquibase createSpringLiquibase() { - DataSource liquibaseDataSource = getDataSource(); + private SpringLiquibase createSpringLiquibase(DataSource liquibaseDatasource, + DataSource dataSource, DataSourceProperties dataSourceProperties) { + DataSource liquibaseDataSource = getDataSource(liquibaseDatasource, + dataSource); if (liquibaseDataSource != null) { SpringLiquibase liquibase = new SpringLiquibase(); liquibase.setDataSource(liquibaseDataSource); return liquibase; } SpringLiquibase liquibase = new DataSourceClosingSpringLiquibase(); - liquibase.setDataSource(createNewDataSource()); + liquibase.setDataSource(createNewDataSource(dataSourceProperties)); return liquibase; } - private DataSource getDataSource() { - if (this.liquibaseDataSource != null) { - return this.liquibaseDataSource; + private DataSource getDataSource(DataSource liquibaseDataSource, + DataSource dataSource) { + if (liquibaseDataSource != null) { + return liquibaseDataSource; } if (this.properties.getUrl() == null && this.properties.getUser() == null) { - return this.dataSource; + return dataSource; } return null; } - private DataSource createNewDataSource() { + private DataSource createNewDataSource( + DataSourceProperties dataSourceProperties) { String url = getProperty(this.properties::getUrl, - this.dataSourceProperties::getUrl); + dataSourceProperties::getUrl); String user = getProperty(this.properties::getUser, - this.dataSourceProperties::getUsername); + dataSourceProperties::getUsername); String password = getProperty(this.properties::getPassword, - this.dataSourceProperties::getPassword); + dataSourceProperties::getPassword); return DataSourceBuilder.create().url(url).username(user).password(password) .build(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.java index ee02bde721fc..c2ebbf7212b1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mail/MailSenderPropertiesConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -37,33 +37,27 @@ @ConditionalOnProperty(prefix = "spring.mail", name = "host") class MailSenderPropertiesConfiguration { - private final MailProperties properties; - - MailSenderPropertiesConfiguration(MailProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean - public JavaMailSenderImpl mailSender() { + public JavaMailSenderImpl mailSender(MailProperties properties) { JavaMailSenderImpl sender = new JavaMailSenderImpl(); - applyProperties(sender); + applyProperties(properties, sender); return sender; } - private void applyProperties(JavaMailSenderImpl sender) { - sender.setHost(this.properties.getHost()); - if (this.properties.getPort() != null) { - sender.setPort(this.properties.getPort()); + private void applyProperties(MailProperties properties, JavaMailSenderImpl sender) { + sender.setHost(properties.getHost()); + if (properties.getPort() != null) { + sender.setPort(properties.getPort()); } - sender.setUsername(this.properties.getUsername()); - sender.setPassword(this.properties.getPassword()); - sender.setProtocol(this.properties.getProtocol()); - if (this.properties.getDefaultEncoding() != null) { - sender.setDefaultEncoding(this.properties.getDefaultEncoding().name()); + sender.setUsername(properties.getUsername()); + sender.setPassword(properties.getPassword()); + sender.setProtocol(properties.getProtocol()); + if (properties.getDefaultEncoding() != null) { + sender.setDefaultEncoding(properties.getDefaultEncoding().name()); } - if (!this.properties.getProperties().isEmpty()) { - sender.setJavaMailProperties(asProperties(this.properties.getProperties())); + if (!properties.getProperties().isEmpty()) { + sender.setJavaMailProperties(asProperties(properties.getProperties())); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java index f93a7edb36f1..1a015dc688ee 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,8 +16,6 @@ package org.springframework.boot.autoconfigure.mongo; -import javax.annotation.PreDestroy; - import com.mongodb.MongoClient; import com.mongodb.MongoClientOptions; @@ -45,31 +43,13 @@ @ConditionalOnMissingBean(type = "org.springframework.data.mongodb.MongoDbFactory") public class MongoAutoConfiguration { - private final MongoClientOptions options; - - private final MongoClientFactory factory; - - private MongoClient mongo; - - public MongoAutoConfiguration(MongoProperties properties, - ObjectProvider options, Environment environment) { - this.options = options.getIfAvailable(); - this.factory = new MongoClientFactory(properties, environment); - } - - @PreDestroy - public void close() { - if (this.mongo != null) { - this.mongo.close(); - } - } - @Bean @ConditionalOnMissingBean(type = { "com.mongodb.MongoClient", "com.mongodb.client.MongoClient" }) - public MongoClient mongo() { - this.mongo = this.factory.createMongoClient(this.options); - return this.mongo; + public MongoClient mongo(MongoProperties properties, + ObjectProvider options, Environment environment) { + return new MongoClientFactory(properties, environment) + .createMongoClient(options.getIfAvailable()); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java index 390edb1007d2..47a69775ac65 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,8 +18,6 @@ import java.util.stream.Collectors; -import javax.annotation.PreDestroy; - import com.mongodb.MongoClientSettings; import com.mongodb.connection.netty.NettyStreamFactoryFactory; import com.mongodb.reactivestreams.client.MongoClient; @@ -49,31 +47,16 @@ @EnableConfigurationProperties(MongoProperties.class) public class MongoReactiveAutoConfiguration { - private final MongoClientSettings settings; - - private MongoClient mongo; - - public MongoReactiveAutoConfiguration(ObjectProvider settings) { - this.settings = settings.getIfAvailable(); - } - - @PreDestroy - public void close() { - if (this.mongo != null) { - this.mongo.close(); - } - } - @Bean @ConditionalOnMissingBean public MongoClient reactiveStreamsMongoClient(MongoProperties properties, Environment environment, - ObjectProvider builderCustomizers) { + ObjectProvider builderCustomizers, + ObjectProvider settings) { ReactiveMongoClientFactory factory = new ReactiveMongoClientFactory(properties, environment, builderCustomizers.orderedStream().collect(Collectors.toList())); - this.mongo = factory.createMongoClient(this.settings); - return this.mongo; + return factory.createMongoClient(settings.getIfAvailable()); } @Configuration diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java index afc847dc0218..4e2a4ec7fa4c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java @@ -92,30 +92,20 @@ public class EmbeddedMongoAutoConfiguration { private final MongoProperties properties; - private final EmbeddedMongoProperties embeddedProperties; - - private final ApplicationContext context; - - private final IRuntimeConfig runtimeConfig; - public EmbeddedMongoAutoConfiguration(MongoProperties properties, - EmbeddedMongoProperties embeddedProperties, ApplicationContext context, - IRuntimeConfig runtimeConfig) { + EmbeddedMongoProperties embeddedProperties) { this.properties = properties; - this.embeddedProperties = embeddedProperties; - this.context = context; - this.runtimeConfig = runtimeConfig; } @Bean(initMethod = "start", destroyMethod = "stop") @ConditionalOnMissingBean - public MongodExecutable embeddedMongoServer(IMongodConfig mongodConfig) - throws IOException { + public MongodExecutable embeddedMongoServer(IMongodConfig mongodConfig, + IRuntimeConfig runtimeConfig, ApplicationContext context) throws IOException { Integer configuredPort = this.properties.getPort(); if (configuredPort == null || configuredPort == 0) { - setEmbeddedPort(mongodConfig.net().getPort()); + setEmbeddedPort(context, mongodConfig.net().getPort()); } - MongodStarter mongodStarter = getMongodStarter(this.runtimeConfig); + MongodStarter mongodStarter = getMongodStarter(runtimeConfig); return mongodStarter.prepare(mongodConfig); } @@ -128,10 +118,11 @@ private MongodStarter getMongodStarter(IRuntimeConfig runtimeConfig) { @Bean @ConditionalOnMissingBean - public IMongodConfig embeddedMongoConfiguration() throws IOException { + public IMongodConfig embeddedMongoConfiguration( + EmbeddedMongoProperties embeddedProperties) throws IOException { MongodConfigBuilder builder = new MongodConfigBuilder() - .version(determineVersion()); - EmbeddedMongoProperties.Storage storage = this.embeddedProperties.getStorage(); + .version(determineVersion(embeddedProperties)); + EmbeddedMongoProperties.Storage storage = embeddedProperties.getStorage(); if (storage != null) { String databaseDir = storage.getDatabaseDir(); String replSetName = storage.getReplSetName(); @@ -151,20 +142,19 @@ public IMongodConfig embeddedMongoConfiguration() throws IOException { return builder.build(); } - private IFeatureAwareVersion determineVersion() { - if (this.embeddedProperties.getFeatures() == null) { + private IFeatureAwareVersion determineVersion( + EmbeddedMongoProperties embeddedProperties) { + if (embeddedProperties.getFeatures() == null) { for (Version version : Version.values()) { - if (version.asInDownloadPath() - .equals(this.embeddedProperties.getVersion())) { + if (version.asInDownloadPath().equals(embeddedProperties.getVersion())) { return version; } } - return Versions.withFeatures( - new GenericVersion(this.embeddedProperties.getVersion())); + return Versions + .withFeatures(new GenericVersion(embeddedProperties.getVersion())); } - return Versions.withFeatures( - new GenericVersion(this.embeddedProperties.getVersion()), - this.embeddedProperties.getFeatures().toArray(new Feature[0])); + return Versions.withFeatures(new GenericVersion(embeddedProperties.getVersion()), + embeddedProperties.getFeatures().toArray(new Feature[0])); } private InetAddress getHost() throws UnknownHostException { @@ -175,8 +165,8 @@ private InetAddress getHost() throws UnknownHostException { return InetAddress.getByName(this.properties.getHost()); } - private void setEmbeddedPort(int port) { - setPortProperty(this.context, port); + private void setEmbeddedPort(ApplicationContext context, int port) { + setPortProperty(context, port); } private void setPortProperty(ApplicationContext currentContext, int port) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java index 0530bcaa012c..f386374df932 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -52,14 +52,11 @@ public class MustacheAutoConfiguration { private final MustacheProperties mustache; - private final Environment environment; - private final ApplicationContext applicationContext; - public MustacheAutoConfiguration(MustacheProperties mustache, Environment environment, + public MustacheAutoConfiguration(MustacheProperties mustache, ApplicationContext applicationContext) { this.mustache = mustache; - this.environment = environment; this.applicationContext = applicationContext; } @@ -78,14 +75,15 @@ public void checkTemplateLocationExists() { @Bean @ConditionalOnMissingBean - public Mustache.Compiler mustacheCompiler(TemplateLoader mustacheTemplateLoader) { + public Mustache.Compiler mustacheCompiler(TemplateLoader mustacheTemplateLoader, + Environment environment) { return Mustache.compiler().withLoader(mustacheTemplateLoader) - .withCollector(collector()); + .withCollector(collector(environment)); } - private Collector collector() { + private Collector collector(Environment environment) { MustacheEnvironmentCollector collector = new MustacheEnvironmentCollector(); - collector.setEnvironment(this.environment); + collector.setEnvironment(environment); return collector; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebConfiguration.java index b814f31eb312..70253df6bd3b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheReactiveWebConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,21 +30,16 @@ @ConditionalOnWebApplication(type = Type.REACTIVE) class MustacheReactiveWebConfiguration { - private final MustacheProperties mustache; - - protected MustacheReactiveWebConfiguration(MustacheProperties mustache) { - this.mustache = mustache; - } - @Bean @ConditionalOnMissingBean - public MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler) { + public MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler, + MustacheProperties mustache) { MustacheViewResolver resolver = new MustacheViewResolver(mustacheCompiler); - resolver.setPrefix(this.mustache.getPrefix()); - resolver.setSuffix(this.mustache.getSuffix()); - resolver.setViewNames(this.mustache.getViewNames()); - resolver.setRequestContextAttribute(this.mustache.getRequestContextAttribute()); - resolver.setCharset(this.mustache.getCharsetName()); + resolver.setPrefix(mustache.getPrefix()); + resolver.setSuffix(mustache.getSuffix()); + resolver.setViewNames(mustache.getViewNames()); + resolver.setRequestContextAttribute(mustache.getRequestContextAttribute()); + resolver.setCharset(mustache.getCharsetName()); resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 10); return resolver; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebConfiguration.java index b6ff696a4080..774d4dd5e43a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mustache/MustacheServletWebConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,18 +30,13 @@ @ConditionalOnWebApplication(type = Type.SERVLET) class MustacheServletWebConfiguration { - private final MustacheProperties mustache; - - protected MustacheServletWebConfiguration(MustacheProperties mustache) { - this.mustache = mustache; - } - @Bean @ConditionalOnMissingBean - public MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler) { + public MustacheViewResolver mustacheViewResolver(Compiler mustacheCompiler, + MustacheProperties mustache) { MustacheViewResolver resolver = new MustacheViewResolver(mustacheCompiler); - this.mustache.applyToMvcViewResolver(resolver); - resolver.setCharset(this.mustache.getCharsetName()); + mustache.applyToMvcViewResolver(resolver); + resolver.setCharset(mustache.getCharsetName()); resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 10); return resolver; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.java index 0c493532e147..2ec14653086b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.java @@ -36,7 +36,6 @@ import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; -import org.springframework.boot.autoconfigure.transaction.TransactionManagerCustomizers; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.jdbc.SchemaManagementProvider; import org.springframework.boot.jdbc.metadata.CompositeDataSourcePoolMetadataProvider; @@ -90,15 +89,13 @@ class HibernateJpaConfiguration extends JpaBaseConfiguration { HibernateJpaConfiguration(DataSource dataSource, JpaProperties jpaProperties, ConfigurableListableBeanFactory beanFactory, ObjectProvider jtaTransactionManager, - ObjectProvider transactionManagerCustomizers, HibernateProperties hibernateProperties, ObjectProvider> metadataProviders, ObjectProvider providers, ObjectProvider physicalNamingStrategy, ObjectProvider implicitNamingStrategy, ObjectProvider hibernatePropertiesCustomizers) { - super(dataSource, jpaProperties, jtaTransactionManager, - transactionManagerCustomizers); + super(dataSource, jpaProperties, jtaTransactionManager); this.hibernateProperties = hibernateProperties; this.defaultDdlAutoProvider = new HibernateDefaultDdlAutoProvider(providers); this.poolMetadataProvider = new CompositeDataSourcePoolMetadataProvider( diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java index 073c06087b8c..e108adf6acef 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java @@ -81,27 +81,22 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware { private final JtaTransactionManager jtaTransactionManager; - private final TransactionManagerCustomizers transactionManagerCustomizers; - private ConfigurableListableBeanFactory beanFactory; protected JpaBaseConfiguration(DataSource dataSource, JpaProperties properties, - ObjectProvider jtaTransactionManager, - ObjectProvider transactionManagerCustomizers) { + ObjectProvider jtaTransactionManager) { this.dataSource = dataSource; this.properties = properties; this.jtaTransactionManager = jtaTransactionManager.getIfAvailable(); - this.transactionManagerCustomizers = transactionManagerCustomizers - .getIfAvailable(); } @Bean @ConditionalOnMissingBean - public PlatformTransactionManager transactionManager() { + public PlatformTransactionManager transactionManager( + ObjectProvider transactionManagerCustomizers) { JpaTransactionManager transactionManager = new JpaTransactionManager(); - if (this.transactionManagerCustomizers != null) { - this.transactionManagerCustomizers.customize(transactionManager); - } + transactionManagerCustomizers + .ifAvailable((customizers) -> customizers.customize(transactionManager)); return transactionManager; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java index 861b5b2510d0..97fdd9ae303d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.java @@ -60,61 +60,37 @@ HibernateJpaAutoConfiguration.class }) public class QuartzAutoConfiguration { - private final QuartzProperties properties; - - private final ObjectProvider customizers; - - private final JobDetail[] jobDetails; - - private final Map calendars; - - private final Trigger[] triggers; - - private final ApplicationContext applicationContext; - - public QuartzAutoConfiguration(QuartzProperties properties, - ObjectProvider customizers, - ObjectProvider jobDetails, Map calendars, - ObjectProvider triggers, ApplicationContext applicationContext) { - this.properties = properties; - this.customizers = customizers; - this.jobDetails = jobDetails.getIfAvailable(); - this.calendars = calendars; - this.triggers = triggers.getIfAvailable(); - this.applicationContext = applicationContext; - } - @Bean @ConditionalOnMissingBean - public SchedulerFactoryBean quartzScheduler() { + public SchedulerFactoryBean quartzScheduler(QuartzProperties properties, + ObjectProvider customizers, + ObjectProvider jobDetails, Map calendars, + ObjectProvider triggers, ApplicationContext applicationContext) { SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean(); SpringBeanJobFactory jobFactory = new SpringBeanJobFactory(); - jobFactory.setApplicationContext(this.applicationContext); + jobFactory.setApplicationContext(applicationContext); schedulerFactoryBean.setJobFactory(jobFactory); - if (this.properties.getSchedulerName() != null) { - schedulerFactoryBean.setSchedulerName(this.properties.getSchedulerName()); + if (properties.getSchedulerName() != null) { + schedulerFactoryBean.setSchedulerName(properties.getSchedulerName()); } - schedulerFactoryBean.setAutoStartup(this.properties.isAutoStartup()); + schedulerFactoryBean.setAutoStartup(properties.isAutoStartup()); schedulerFactoryBean - .setStartupDelay((int) this.properties.getStartupDelay().getSeconds()); + .setStartupDelay((int) properties.getStartupDelay().getSeconds()); schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown( - this.properties.isWaitForJobsToCompleteOnShutdown()); + properties.isWaitForJobsToCompleteOnShutdown()); schedulerFactoryBean - .setOverwriteExistingJobs(this.properties.isOverwriteExistingJobs()); - if (!this.properties.getProperties().isEmpty()) { + .setOverwriteExistingJobs(properties.isOverwriteExistingJobs()); + if (!properties.getProperties().isEmpty()) { schedulerFactoryBean - .setQuartzProperties(asProperties(this.properties.getProperties())); + .setQuartzProperties(asProperties(properties.getProperties())); } - if (this.jobDetails != null && this.jobDetails.length > 0) { - schedulerFactoryBean.setJobDetails(this.jobDetails); - } - if (this.calendars != null && !this.calendars.isEmpty()) { - schedulerFactoryBean.setCalendars(this.calendars); - } - if (this.triggers != null && this.triggers.length > 0) { - schedulerFactoryBean.setTriggers(this.triggers); - } - customize(schedulerFactoryBean); + schedulerFactoryBean + .setJobDetails(jobDetails.orderedStream().toArray(JobDetail[]::new)); + schedulerFactoryBean.setCalendars(calendars); + schedulerFactoryBean + .setTriggers(triggers.orderedStream().toArray(Trigger[]::new)); + customizers.orderedStream() + .forEach((customizer) -> customizer.customize(schedulerFactoryBean)); return schedulerFactoryBean; } @@ -124,11 +100,6 @@ private Properties asProperties(Map source) { return properties; } - private void customize(SchedulerFactoryBean schedulerFactoryBean) { - this.customizers.orderedStream() - .forEach((customizer) -> customizer.customize(schedulerFactoryBean)); - } - @Configuration @ConditionalOnSingleCandidate(DataSource.class) protected static class JdbcStoreTypeConfiguration { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/reactive/ReactiveOAuth2ClientAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/reactive/ReactiveOAuth2ClientAutoConfiguration.java index 05e3ab8aaec4..ba82b8e221bb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/reactive/ReactiveOAuth2ClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/reactive/ReactiveOAuth2ClientAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -58,19 +58,14 @@ @ConditionalOnClass({ Flux.class, EnableWebFluxSecurity.class, ClientRegistration.class }) public class ReactiveOAuth2ClientAutoConfiguration { - private final OAuth2ClientProperties properties; - - public ReactiveOAuth2ClientAutoConfiguration(OAuth2ClientProperties properties) { - this.properties = properties; - } - @Bean @Conditional(ClientsConfiguredCondition.class) @ConditionalOnMissingBean(ReactiveClientRegistrationRepository.class) - public InMemoryReactiveClientRegistrationRepository clientRegistrationRepository() { + public InMemoryReactiveClientRegistrationRepository clientRegistrationRepository( + OAuth2ClientProperties properties) { List registrations = new ArrayList<>( OAuth2ClientPropertiesRegistrationAdapter - .getClientRegistrations(this.properties).values()); + .getClientRegistrations(properties).values()); return new InMemoryReactiveClientRegistrationRepository(registrations); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.java index 5323a944e917..b5d7588fb1f8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2ClientRegistrationRepositoryConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -42,18 +42,13 @@ @Conditional(ClientsConfiguredCondition.class) class OAuth2ClientRegistrationRepositoryConfiguration { - private final OAuth2ClientProperties properties; - - OAuth2ClientRegistrationRepositoryConfiguration(OAuth2ClientProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean(ClientRegistrationRepository.class) - public InMemoryClientRegistrationRepository clientRegistrationRepository() { + public InMemoryClientRegistrationRepository clientRegistrationRepository( + OAuth2ClientProperties properties) { List registrations = new ArrayList<>( OAuth2ClientPropertiesRegistrationAdapter - .getClientRegistrations(this.properties).values()); + .getClientRegistrations(properties).values()); return new InMemoryClientRegistrationRepository(registrations); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/reactive/ReactiveOAuth2ResourceServerWebSecurityConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/reactive/ReactiveOAuth2ResourceServerWebSecurityConfiguration.java index 5b99e00ec074..735c453c8e7c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/reactive/ReactiveOAuth2ResourceServerWebSecurityConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/oauth2/resource/reactive/ReactiveOAuth2ResourceServerWebSecurityConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -33,17 +33,12 @@ @ConditionalOnBean(ReactiveJwtDecoder.class) class ReactiveOAuth2ResourceServerWebSecurityConfiguration { - private final ReactiveJwtDecoder jwtDecoder; - - ReactiveOAuth2ResourceServerWebSecurityConfiguration(ReactiveJwtDecoder jwtDecoder) { - this.jwtDecoder = jwtDecoder; - } - @Bean @ConditionalOnMissingBean - public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { + public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http, + ReactiveJwtDecoder jwtDecoder) { http.authorizeExchange().anyExchange().authenticated().and() - .oauth2ResourceServer().jwt().jwtDecoder(this.jwtDecoder); + .oauth2ResourceServer().jwt().jwtDecoder(jwtDecoder); return http.build(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java index 288cef443942..49bd63fece38 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -43,22 +43,16 @@ @EnableConfigurationProperties(SendGridProperties.class) public class SendGridAutoConfiguration { - private final SendGridProperties properties; - - public SendGridAutoConfiguration(SendGridProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean - public SendGrid sendGrid() { - if (this.properties.isProxyConfigured()) { - HttpHost proxy = new HttpHost(this.properties.getProxy().getHost(), - this.properties.getProxy().getPort()); - return new SendGrid(this.properties.getApiKey(), + public SendGrid sendGrid(SendGridProperties properties) { + if (properties.isProxyConfigured()) { + HttpHost proxy = new HttpHost(properties.getProxy().getHost(), + properties.getProxy().getPort()); + return new SendGrid(properties.getApiKey(), new Client(HttpClientBuilder.create().setProxy(proxy).build())); } - return new SendGrid(this.properties.getApiKey()); + return new SendGrid(properties.getApiKey()); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java index 2d0aea037df8..066727b54f01 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/solr/SolrAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -32,7 +32,7 @@ import org.springframework.util.StringUtils; /** - * {@link EnableAutoConfiguration Auto-configuration} for Solr 4.x. + * {@link EnableAutoConfiguration Auto-configuration} for Solr. * * @author Christoph Strobl * @since 1.1.0 @@ -42,27 +42,14 @@ @EnableConfigurationProperties(SolrProperties.class) public class SolrAutoConfiguration { - private final SolrProperties properties; - - private SolrClient solrClient; - - public SolrAutoConfiguration(SolrProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean - public SolrClient solrClient() { - this.solrClient = createSolrClient(); - return this.solrClient; - } - - private SolrClient createSolrClient() { - if (StringUtils.hasText(this.properties.getZkHost())) { - return new CloudSolrClient.Builder(Arrays.asList(this.properties.getZkHost()), + public SolrClient solrClient(SolrProperties properties) { + if (StringUtils.hasText(properties.getZkHost())) { + return new CloudSolrClient.Builder(Arrays.asList(properties.getZkHost()), Optional.empty()).build(); } - return new HttpSolrClient.Builder(this.properties.getHost()).build(); + return new HttpSolrClient.Builder(properties.getHost()).build(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfiguration.java index 034957ee52b7..c7d214e97097 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/task/TaskExecutionAutoConfiguration.java @@ -51,36 +51,24 @@ public class TaskExecutionAutoConfiguration { */ public static final String APPLICATION_TASK_EXECUTOR_BEAN_NAME = "applicationTaskExecutor"; - private final TaskExecutionProperties properties; - - private final ObjectProvider taskExecutorCustomizers; - - private final ObjectProvider taskDecorator; - - public TaskExecutionAutoConfiguration(TaskExecutionProperties properties, - ObjectProvider taskExecutorCustomizers, - ObjectProvider taskDecorator) { - this.properties = properties; - this.taskExecutorCustomizers = taskExecutorCustomizers; - this.taskDecorator = taskDecorator; - } - @Bean @ConditionalOnMissingBean - public TaskExecutorBuilder taskExecutorBuilder() { - TaskExecutionProperties.Pool pool = this.properties.getPool(); + public TaskExecutorBuilder taskExecutorBuilder(TaskExecutionProperties properties, + ObjectProvider taskExecutorCustomizers, + ObjectProvider taskDecorator) { + TaskExecutionProperties.Pool pool = properties.getPool(); TaskExecutorBuilder builder = new TaskExecutorBuilder(); builder = builder.queueCapacity(pool.getQueueCapacity()); builder = builder.corePoolSize(pool.getCoreSize()); builder = builder.maxPoolSize(pool.getMaxSize()); builder = builder.allowCoreThreadTimeOut(pool.isAllowCoreThreadTimeout()); builder = builder.keepAlive(pool.getKeepAlive()); - Shutdown shutdown = this.properties.getShutdown(); + Shutdown shutdown = properties.getShutdown(); builder = builder.awaitTermination(shutdown.isAwaitTermination()); builder = builder.awaitTerminationPeriod(shutdown.getAwaitTerminationPeriod()); - builder = builder.threadNamePrefix(this.properties.getThreadNamePrefix()); - builder = builder.customizers(this.taskExecutorCustomizers); - builder = builder.taskDecorator(this.taskDecorator.getIfUnique()); + builder = builder.threadNamePrefix(properties.getThreadNamePrefix()); + builder = builder.customizers(taskExecutorCustomizers); + builder = builder.taskDecorator(taskDecorator.getIfUnique()); return builder; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index 5e5122955fa7..193d796f2d07 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.thymeleaf; -import java.util.Collection; import java.util.LinkedHashMap; import javax.annotation.PostConstruct; @@ -136,29 +135,17 @@ public SpringResourceTemplateResolver defaultTemplateResolver() { @Configuration protected static class ThymeleafDefaultConfiguration { - private final ThymeleafProperties properties; - - private final Collection templateResolvers; - - private final ObjectProvider dialects; - - public ThymeleafDefaultConfiguration(ThymeleafProperties properties, - Collection templateResolvers, - ObjectProvider dialectsProvider) { - this.properties = properties; - this.templateResolvers = templateResolvers; - this.dialects = dialectsProvider; - } - @Bean @ConditionalOnMissingBean - public SpringTemplateEngine templateEngine() { + public SpringTemplateEngine templateEngine(ThymeleafProperties properties, + ObjectProvider templateResolvers, + ObjectProvider dialects) { SpringTemplateEngine engine = new SpringTemplateEngine(); - engine.setEnableSpringELCompiler(this.properties.isEnableSpringElCompiler()); + engine.setEnableSpringELCompiler(properties.isEnableSpringElCompiler()); engine.setRenderHiddenMarkersBeforeCheckboxes( - this.properties.isRenderHiddenMarkersBeforeCheckboxes()); - this.templateResolvers.forEach(engine::addTemplateResolver); - this.dialects.orderedStream().forEach(engine::addDialect); + properties.isRenderHiddenMarkersBeforeCheckboxes()); + templateResolvers.orderedStream().forEach(engine::addTemplateResolver); + dialects.orderedStream().forEach(engine::addDialect); return engine; } @@ -182,33 +169,24 @@ public FilterRegistrationBean resourceUrlEncodingFilt @Configuration static class ThymeleafViewResolverConfiguration { - private final ThymeleafProperties properties; - - private final SpringTemplateEngine templateEngine; - - ThymeleafViewResolverConfiguration(ThymeleafProperties properties, - SpringTemplateEngine templateEngine) { - this.properties = properties; - this.templateEngine = templateEngine; - } - @Bean @ConditionalOnMissingBean(name = "thymeleafViewResolver") - public ThymeleafViewResolver thymeleafViewResolver() { + public ThymeleafViewResolver thymeleafViewResolver( + ThymeleafProperties properties, SpringTemplateEngine templateEngine) { ThymeleafViewResolver resolver = new ThymeleafViewResolver(); - resolver.setTemplateEngine(this.templateEngine); - resolver.setCharacterEncoding(this.properties.getEncoding().name()); + resolver.setTemplateEngine(templateEngine); + resolver.setCharacterEncoding(properties.getEncoding().name()); resolver.setContentType( - appendCharset(this.properties.getServlet().getContentType(), + appendCharset(properties.getServlet().getContentType(), resolver.getCharacterEncoding())); - resolver.setProducePartialOutputWhileProcessing(this.properties - .getServlet().isProducePartialOutputWhileProcessing()); - resolver.setExcludedViewNames(this.properties.getExcludedViewNames()); - resolver.setViewNames(this.properties.getViewNames()); + resolver.setProducePartialOutputWhileProcessing( + properties.getServlet().isProducePartialOutputWhileProcessing()); + resolver.setExcludedViewNames(properties.getExcludedViewNames()); + resolver.setViewNames(properties.getViewNames()); // This resolver acts as a fallback resolver (e.g. like a // InternalResourceViewResolver) so it needs to have low precedence resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 5); - resolver.setCache(this.properties.isCache()); + resolver.setCache(properties.isCache()); return resolver; } @@ -231,29 +209,17 @@ private String appendCharset(MimeType type, String charset) { @ConditionalOnProperty(name = "spring.thymeleaf.enabled", matchIfMissing = true) static class ThymeleafReactiveConfiguration { - private final ThymeleafProperties properties; - - private final Collection templateResolvers; - - private final ObjectProvider dialects; - - ThymeleafReactiveConfiguration(ThymeleafProperties properties, - Collection templateResolvers, - ObjectProvider dialectsProvider) { - this.properties = properties; - this.templateResolvers = templateResolvers; - this.dialects = dialectsProvider; - } - @Bean @ConditionalOnMissingBean(ISpringWebFluxTemplateEngine.class) - public SpringWebFluxTemplateEngine templateEngine() { + public SpringWebFluxTemplateEngine templateEngine(ThymeleafProperties properties, + ObjectProvider templateResolvers, + ObjectProvider dialects) { SpringWebFluxTemplateEngine engine = new SpringWebFluxTemplateEngine(); - engine.setEnableSpringELCompiler(this.properties.isEnableSpringElCompiler()); + engine.setEnableSpringELCompiler(properties.isEnableSpringElCompiler()); engine.setRenderHiddenMarkersBeforeCheckboxes( - this.properties.isRenderHiddenMarkersBeforeCheckboxes()); - this.templateResolvers.forEach(engine::addTemplateResolver); - this.dialects.orderedStream().forEach(engine::addDialect); + properties.isRenderHiddenMarkersBeforeCheckboxes()); + templateResolvers.orderedStream().forEach(engine::addTemplateResolver); + dialects.orderedStream().forEach(engine::addDialect); return engine; } @@ -264,20 +230,15 @@ public SpringWebFluxTemplateEngine templateEngine() { @ConditionalOnProperty(name = "spring.thymeleaf.enabled", matchIfMissing = true) static class ThymeleafWebFluxConfiguration { - private final ThymeleafProperties properties; - - ThymeleafWebFluxConfiguration(ThymeleafProperties properties) { - this.properties = properties; - } - @Bean @ConditionalOnMissingBean(name = "thymeleafReactiveViewResolver") public ThymeleafReactiveViewResolver thymeleafViewResolver( - ISpringWebFluxTemplateEngine templateEngine) { + ISpringWebFluxTemplateEngine templateEngine, + ThymeleafProperties properties) { ThymeleafReactiveViewResolver resolver = new ThymeleafReactiveViewResolver(); resolver.setTemplateEngine(templateEngine); - mapProperties(this.properties, resolver); - mapReactiveProperties(this.properties.getReactive(), resolver); + mapProperties(properties, resolver); + mapReactiveProperties(properties.getReactive(), resolver); // This resolver acts as a fallback resolver (e.g. like a // InternalResourceViewResolver) so it needs to have low precedence resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 5); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java index 4a0b3ad202e8..9a234fc1f19b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/TransactionAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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,17 +64,11 @@ public TransactionManagerCustomizers platformTransactionManagerCustomizers( @ConditionalOnSingleCandidate(PlatformTransactionManager.class) public static class TransactionTemplateConfiguration { - private final PlatformTransactionManager transactionManager; - - public TransactionTemplateConfiguration( - PlatformTransactionManager transactionManager) { - this.transactionManager = transactionManager; - } - @Bean @ConditionalOnMissingBean - public TransactionTemplate transactionTemplate() { - return new TransactionTemplate(this.transactionManager); + public TransactionTemplate transactionTemplate( + PlatformTransactionManager transactionManager) { + return new TransactionTemplate(transactionManager); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java index d6182678459a..666eb2c78cb2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/AtomikosJtaConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -61,34 +61,24 @@ @ConditionalOnMissingBean(PlatformTransactionManager.class) class AtomikosJtaConfiguration { - private final JtaProperties jtaProperties; - - private final TransactionManagerCustomizers transactionManagerCustomizers; - - AtomikosJtaConfiguration(JtaProperties jtaProperties, - ObjectProvider transactionManagerCustomizers) { - this.jtaProperties = jtaProperties; - this.transactionManagerCustomizers = transactionManagerCustomizers - .getIfAvailable(); - } - @Bean(initMethod = "init", destroyMethod = "shutdownWait") @ConditionalOnMissingBean(UserTransactionService.class) public UserTransactionServiceImp userTransactionService( - AtomikosProperties atomikosProperties) { + AtomikosProperties atomikosProperties, JtaProperties jtaProperties) { Properties properties = new Properties(); - if (StringUtils.hasText(this.jtaProperties.getTransactionManagerId())) { + if (StringUtils.hasText(jtaProperties.getTransactionManagerId())) { properties.setProperty("com.atomikos.icatch.tm_unique_name", - this.jtaProperties.getTransactionManagerId()); + jtaProperties.getTransactionManagerId()); } - properties.setProperty("com.atomikos.icatch.log_base_dir", getLogBaseDir()); + properties.setProperty("com.atomikos.icatch.log_base_dir", + getLogBaseDir(jtaProperties)); properties.putAll(atomikosProperties.asProperties()); return new UserTransactionServiceImp(properties); } - private String getLogBaseDir() { - if (StringUtils.hasLength(this.jtaProperties.getLogDir())) { - return this.jtaProperties.getLogDir(); + private String getLogBaseDir(JtaProperties jtaProperties) { + if (StringUtils.hasLength(jtaProperties.getLogDir())) { + return jtaProperties.getLogDir(); } File home = new ApplicationHome().getDir(); return new File(home, "transaction-logs").getAbsolutePath(); @@ -118,12 +108,12 @@ public static AtomikosDependsOnBeanFactoryPostProcessor atomikosDependsOnBeanFac @Bean public JtaTransactionManager transactionManager(UserTransaction userTransaction, - TransactionManager transactionManager) { + TransactionManager transactionManager, + ObjectProvider transactionManagerCustomizers) { JtaTransactionManager jtaTransactionManager = new JtaTransactionManager( userTransaction, transactionManager); - if (this.transactionManagerCustomizers != null) { - this.transactionManagerCustomizers.customize(jtaTransactionManager); - } + transactionManagerCustomizers.ifAvailable( + (customizers) -> customizers.customize(jtaTransactionManager)); return jtaTransactionManager; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java index d446406e8482..9874ee424385 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/BitronixJtaConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -20,6 +20,7 @@ import javax.jms.Message; import javax.transaction.TransactionManager; +import javax.transaction.UserTransaction; import bitronix.tm.BitronixTransactionManager; import bitronix.tm.TransactionManagerServices; @@ -58,35 +59,24 @@ @ConditionalOnMissingBean(PlatformTransactionManager.class) class BitronixJtaConfiguration { - private final JtaProperties jtaProperties; - - private final TransactionManagerCustomizers transactionManagerCustomizers; - - BitronixJtaConfiguration(JtaProperties jtaProperties, - ObjectProvider transactionManagerCustomizers) { - this.jtaProperties = jtaProperties; - this.transactionManagerCustomizers = transactionManagerCustomizers - .getIfAvailable(); - } - @Bean @ConditionalOnMissingBean @ConfigurationProperties(prefix = "spring.jta.bitronix.properties") - public bitronix.tm.Configuration bitronixConfiguration() { + public bitronix.tm.Configuration bitronixConfiguration(JtaProperties jtaProperties) { bitronix.tm.Configuration config = TransactionManagerServices.getConfiguration(); - if (StringUtils.hasText(this.jtaProperties.getTransactionManagerId())) { - config.setServerId(this.jtaProperties.getTransactionManagerId()); + if (StringUtils.hasText(jtaProperties.getTransactionManagerId())) { + config.setServerId(jtaProperties.getTransactionManagerId()); } - File logBaseDir = getLogBaseDir(); + File logBaseDir = getLogBaseDir(jtaProperties); config.setLogPart1Filename(new File(logBaseDir, "part1.btm").getAbsolutePath()); config.setLogPart2Filename(new File(logBaseDir, "part2.btm").getAbsolutePath()); config.setDisableJmx(true); return config; } - private File getLogBaseDir() { - if (StringUtils.hasLength(this.jtaProperties.getLogDir())) { - return new File(this.jtaProperties.getLogDir()); + private File getLogBaseDir(JtaProperties jtaProperties) { + if (StringUtils.hasLength(jtaProperties.getLogDir())) { + return new File(jtaProperties.getLogDir()); } File home = new ApplicationHome().getDir(); return new File(home, "transaction-logs"); @@ -113,13 +103,13 @@ public static BitronixDependentBeanFactoryPostProcessor bitronixDependentBeanFac } @Bean - public JtaTransactionManager transactionManager( - TransactionManager transactionManager) { + public JtaTransactionManager transactionManager(UserTransaction userTransaction, + TransactionManager transactionManager, + ObjectProvider transactionManagerCustomizers) { JtaTransactionManager jtaTransactionManager = new JtaTransactionManager( - transactionManager); - if (this.transactionManagerCustomizers != null) { - this.transactionManagerCustomizers.customize(jtaTransactionManager); - } + userTransaction, transactionManager); + transactionManagerCustomizers.ifAvailable( + (customizers) -> customizers.customize(jtaTransactionManager)); return jtaTransactionManager; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/JndiJtaConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/JndiJtaConfiguration.java index 4ec386bd04fc..e19866c41684 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/JndiJtaConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/transaction/jta/JndiJtaConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -43,21 +43,13 @@ @ConditionalOnMissingBean(PlatformTransactionManager.class) class JndiJtaConfiguration { - private final TransactionManagerCustomizers transactionManagerCustomizers; - - JndiJtaConfiguration( - ObjectProvider transactionManagerCustomizers) { - this.transactionManagerCustomizers = transactionManagerCustomizers - .getIfAvailable(); - } - @Bean - public JtaTransactionManager transactionManager() { + public JtaTransactionManager transactionManager( + ObjectProvider transactionManagerCustomizers) { JtaTransactionManager jtaTransactionManager = new JtaTransactionManagerFactoryBean() .getObject(); - if (this.transactionManagerCustomizers != null) { - this.transactionManagerCustomizers.customize(jtaTransactionManager); - } + transactionManagerCustomizers.ifAvailable( + (customizers) -> customizers.customize(jtaTransactionManager)); return jtaTransactionManager; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java index e9578fea5864..1fdb696c5b6d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/client/RestTemplateAutoConfiguration.java @@ -35,7 +35,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; -import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; /** @@ -51,29 +50,19 @@ @Conditional(NotReactiveWebApplicationCondition.class) public class RestTemplateAutoConfiguration { - private final ObjectProvider messageConverters; - - private final ObjectProvider restTemplateCustomizers; - - public RestTemplateAutoConfiguration( - ObjectProvider messageConverters, - ObjectProvider restTemplateCustomizers) { - this.messageConverters = messageConverters; - this.restTemplateCustomizers = restTemplateCustomizers; - } - @Bean @ConditionalOnMissingBean - public RestTemplateBuilder restTemplateBuilder() { + public RestTemplateBuilder restTemplateBuilder( + ObjectProvider messageConverters, + ObjectProvider restTemplateCustomizers) { RestTemplateBuilder builder = new RestTemplateBuilder(); - HttpMessageConverters converters = this.messageConverters.getIfUnique(); + HttpMessageConverters converters = messageConverters.getIfUnique(); if (converters != null) { builder = builder.messageConverters(converters.getConverters()); } - - List customizers = this.restTemplateCustomizers - .orderedStream().collect(Collectors.toList()); - if (!CollectionUtils.isEmpty(customizers)) { + List customizers = restTemplateCustomizers.orderedStream() + .collect(Collectors.toList()); + if (!customizers.isEmpty()) { builder = builder.customizers(customizers); } return builder; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/ErrorWebFluxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/ErrorWebFluxAutoConfiguration.java index 40d66dd0102d..72e5f9f2790d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/ErrorWebFluxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/ErrorWebFluxAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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.reactive.error; -import java.util.List; import java.util.stream.Collectors; import org.springframework.beans.factory.ObjectProvider; @@ -57,38 +56,25 @@ public class ErrorWebFluxAutoConfiguration { private final ServerProperties serverProperties; - private final ApplicationContext applicationContext; - - private final ResourceProperties resourceProperties; - - private final List viewResolvers; - - private final ServerCodecConfigurer serverCodecConfigurer; - - public ErrorWebFluxAutoConfiguration(ServerProperties serverProperties, - ResourceProperties resourceProperties, - ObjectProvider viewResolversProvider, - ServerCodecConfigurer serverCodecConfigurer, - ApplicationContext applicationContext) { + public ErrorWebFluxAutoConfiguration(ServerProperties serverProperties) { this.serverProperties = serverProperties; - this.applicationContext = applicationContext; - this.resourceProperties = resourceProperties; - this.viewResolvers = viewResolversProvider.orderedStream() - .collect(Collectors.toList()); - this.serverCodecConfigurer = serverCodecConfigurer; } @Bean @ConditionalOnMissingBean(value = ErrorWebExceptionHandler.class, search = SearchStrategy.CURRENT) @Order(-1) public ErrorWebExceptionHandler errorWebExceptionHandler( - ErrorAttributes errorAttributes) { + ErrorAttributes errorAttributes, ResourceProperties resourceProperties, + ObjectProvider viewResolvers, + ServerCodecConfigurer serverCodecConfigurer, + ApplicationContext applicationContext) { DefaultErrorWebExceptionHandler exceptionHandler = new DefaultErrorWebExceptionHandler( - errorAttributes, this.resourceProperties, - this.serverProperties.getError(), this.applicationContext); - exceptionHandler.setViewResolvers(this.viewResolvers); - exceptionHandler.setMessageWriters(this.serverCodecConfigurer.getWriters()); - exceptionHandler.setMessageReaders(this.serverCodecConfigurer.getReaders()); + errorAttributes, resourceProperties, this.serverProperties.getError(), + applicationContext); + exceptionHandler.setViewResolvers( + viewResolvers.orderedStream().collect(Collectors.toList())); + exceptionHandler.setMessageWriters(serverCodecConfigurer.getWriters()); + exceptionHandler.setMessageReaders(serverCodecConfigurer.getReaders()); return exceptionHandler; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration.java index 134b88b7bf4d..8a7c85d99a41 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -85,27 +85,18 @@ public class DispatcherServletAutoConfiguration { @EnableConfigurationProperties({ HttpProperties.class, WebMvcProperties.class }) protected static class DispatcherServletConfiguration { - private final HttpProperties httpProperties; - - private final WebMvcProperties webMvcProperties; - - public DispatcherServletConfiguration(HttpProperties httpProperties, - WebMvcProperties webMvcProperties) { - this.httpProperties = httpProperties; - this.webMvcProperties = webMvcProperties; - } - @Bean(name = DEFAULT_DISPATCHER_SERVLET_BEAN_NAME) - public DispatcherServlet dispatcherServlet() { + public DispatcherServlet dispatcherServlet(HttpProperties httpProperties, + WebMvcProperties webMvcProperties) { DispatcherServlet dispatcherServlet = new DispatcherServlet(); dispatcherServlet.setDispatchOptionsRequest( - this.webMvcProperties.isDispatchOptionsRequest()); - dispatcherServlet.setDispatchTraceRequest( - this.webMvcProperties.isDispatchTraceRequest()); + webMvcProperties.isDispatchOptionsRequest()); + dispatcherServlet + .setDispatchTraceRequest(webMvcProperties.isDispatchTraceRequest()); dispatcherServlet.setThrowExceptionIfNoHandlerFound( - this.webMvcProperties.isThrowExceptionIfNoHandlerFound()); - dispatcherServlet.setEnableLoggingRequestDetails( - this.httpProperties.isLogRequestDetails()); + webMvcProperties.isThrowExceptionIfNoHandlerFound()); + dispatcherServlet + .setEnableLoggingRequestDetails(httpProperties.isLogRequestDetails()); return dispatcherServlet; } @@ -126,29 +117,17 @@ public MultipartResolver multipartResolver(MultipartResolver resolver) { @Import(DispatcherServletConfiguration.class) protected static class DispatcherServletRegistrationConfiguration { - private final WebMvcProperties webMvcProperties; - - private final MultipartConfigElement multipartConfig; - - public DispatcherServletRegistrationConfiguration( - WebMvcProperties webMvcProperties, - ObjectProvider multipartConfigProvider) { - this.webMvcProperties = webMvcProperties; - this.multipartConfig = multipartConfigProvider.getIfAvailable(); - } - @Bean(name = DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME) @ConditionalOnBean(value = DispatcherServlet.class, name = DEFAULT_DISPATCHER_SERVLET_BEAN_NAME) public DispatcherServletRegistrationBean dispatcherServletRegistration( - DispatcherServlet dispatcherServlet) { + DispatcherServlet dispatcherServlet, WebMvcProperties webMvcProperties, + ObjectProvider multipartConfig) { DispatcherServletRegistrationBean registration = new DispatcherServletRegistrationBean( - dispatcherServlet, this.webMvcProperties.getServlet().getPath()); + dispatcherServlet, webMvcProperties.getServlet().getPath()); registration.setName(DEFAULT_DISPATCHER_SERVLET_BEAN_NAME); - registration.setLoadOnStartup( - this.webMvcProperties.getServlet().getLoadOnStartup()); - if (this.multipartConfig != null) { - registration.setMultipartConfig(this.multipartConfig); - } + registration + .setLoadOnStartup(webMvcProperties.getServlet().getLoadOnStartup()); + multipartConfig.ifAvailable(registration::setMultipartConfig); return registration; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java index e23092886784..b3d56398e6d1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/ErrorMvcAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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.web.servlet.error; import java.util.Date; -import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -92,17 +91,8 @@ public class ErrorMvcAutoConfiguration { private final ServerProperties serverProperties; - private final DispatcherServletPath dispatcherServletPath; - - private final List errorViewResolvers; - - public ErrorMvcAutoConfiguration(ServerProperties serverProperties, - DispatcherServletPath dispatcherServletPath, - ObjectProvider errorViewResolvers) { + public ErrorMvcAutoConfiguration(ServerProperties serverProperties) { this.serverProperties = serverProperties; - this.dispatcherServletPath = dispatcherServletPath; - this.errorViewResolvers = errorViewResolvers.orderedStream() - .collect(Collectors.toList()); } @Bean @@ -114,14 +104,16 @@ public DefaultErrorAttributes errorAttributes() { @Bean @ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT) - public BasicErrorController basicErrorController(ErrorAttributes errorAttributes) { + public BasicErrorController basicErrorController(ErrorAttributes errorAttributes, + ObjectProvider errorViewResolvers) { return new BasicErrorController(errorAttributes, this.serverProperties.getError(), - this.errorViewResolvers); + errorViewResolvers.orderedStream().collect(Collectors.toList())); } @Bean - public ErrorPageCustomizer errorPageCustomizer() { - return new ErrorPageCustomizer(this.serverProperties, this.dispatcherServletPath); + public ErrorPageCustomizer errorPageCustomizer( + DispatcherServletPath dispatcherServletPath) { + return new ErrorPageCustomizer(this.serverProperties, dispatcherServletPath); } @Bean diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java index 2541b4b3f0bf..5ec0e9543416 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -66,22 +66,16 @@ @AutoConfigureAfter(ServletWebServerFactoryAutoConfiguration.class) public class WebServicesAutoConfiguration { - private final WebServicesProperties properties; - - public WebServicesAutoConfiguration(WebServicesProperties properties) { - this.properties = properties; - } - @Bean public ServletRegistrationBean messageDispatcherServlet( - ApplicationContext applicationContext) { + ApplicationContext applicationContext, WebServicesProperties properties) { MessageDispatcherServlet servlet = new MessageDispatcherServlet(); servlet.setApplicationContext(applicationContext); - String path = this.properties.getPath(); + String path = properties.getPath(); String urlMapping = path + (path.endsWith("/") ? "*" : "/*"); ServletRegistrationBean registration = new ServletRegistrationBean<>( servlet, urlMapping); - WebServicesProperties.Servlet servletProperties = this.properties.getServlet(); + WebServicesProperties.Servlet servletProperties = properties.getServlet(); registration.setLoadOnStartup(servletProperties.getLoadOnStartup()); servletProperties.getInit().forEach(registration::addInitParameter); return registration; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/client/WebServiceTemplateAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/client/WebServiceTemplateAutoConfiguration.java index ced2ec830adb..60050defa303 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/client/WebServiceTemplateAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/webservices/client/WebServiceTemplateAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -29,7 +29,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; -import org.springframework.util.CollectionUtils; import org.springframework.ws.client.core.WebServiceTemplate; /** @@ -42,20 +41,14 @@ @ConditionalOnClass({ WebServiceTemplate.class, Unmarshaller.class, Marshaller.class }) public class WebServiceTemplateAutoConfiguration { - private final ObjectProvider webServiceTemplateCustomizers; - - public WebServiceTemplateAutoConfiguration( - ObjectProvider webServiceTemplateCustomizers) { - this.webServiceTemplateCustomizers = webServiceTemplateCustomizers; - } - @Bean @ConditionalOnMissingBean - public WebServiceTemplateBuilder webServiceTemplateBuilder() { + public WebServiceTemplateBuilder webServiceTemplateBuilder( + ObjectProvider webServiceTemplateCustomizers) { WebServiceTemplateBuilder builder = new WebServiceTemplateBuilder(); - List customizers = this.webServiceTemplateCustomizers + List customizers = webServiceTemplateCustomizers .orderedStream().collect(Collectors.toList()); - if (!CollectionUtils.isEmpty(customizers)) { + if (!customizers.isEmpty()) { builder = builder.customizers(customizers); } return builder; diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index 0ed57347faf4..37178c05000f 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -64,17 +64,11 @@ public class LocalDevToolsAutoConfiguration { @ConditionalOnProperty(prefix = "spring.devtools.livereload", name = "enabled", matchIfMissing = true) static class LiveReloadConfiguration { - private final DevToolsProperties properties; - - LiveReloadConfiguration(DevToolsProperties properties) { - this.properties = properties; - } - @Bean @RestartScope @ConditionalOnMissingBean - public LiveReloadServer liveReloadServer() { - return new LiveReloadServer(this.properties.getLivereload().getPort(), + public LiveReloadServer liveReloadServer(DevToolsProperties properties) { + return new LiveReloadServer(properties.getLivereload().getPort(), Restarter.getInstance().getThreadFactory()); } diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java index f91b431d6814..60d653e0ea16 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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 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; @@ -66,12 +65,8 @@ public class RemoteDevToolsAutoConfiguration { private final DevToolsProperties properties; - private final ServerProperties serverProperties; - - public RemoteDevToolsAutoConfiguration(DevToolsProperties properties, - ServerProperties serverProperties) { + public RemoteDevToolsAutoConfiguration(DevToolsProperties properties) { this.properties = properties; - this.serverProperties = serverProperties; } @Bean @@ -83,9 +78,10 @@ public AccessManager remoteDevToolsAccessManager() { } @Bean - public HandlerMapper remoteDevToolsHealthCheckHandlerMapper() { + public HandlerMapper remoteDevToolsHealthCheckHandlerMapper( + ServerProperties serverProperties) { Handler handler = new HttpStatusHandler(); - Servlet servlet = this.serverProperties.getServlet(); + Servlet servlet = serverProperties.getServlet(); String servletContextPath = (servlet.getContextPath() != null) ? servlet.getContextPath() : ""; return new UrlHandlerMapper( @@ -108,12 +104,6 @@ public DispatcherFilter remoteDevToolsDispatcherFilter(AccessManager accessManag @ConditionalOnProperty(prefix = "spring.devtools.remote.restart", name = "enabled", matchIfMissing = true) static class RemoteRestartConfiguration { - @Autowired - private DevToolsProperties properties; - - @Autowired - private ServerProperties serverProperties; - @Bean @ConditionalOnMissingBean public SourceFolderUrlFilter remoteRestartSourceFolderUrlFilter() { @@ -129,9 +119,10 @@ public HttpRestartServer remoteRestartHttpRestartServer( @Bean @ConditionalOnMissingBean(name = "remoteRestartHandlerMapper") - public UrlHandlerMapper remoteRestartHandlerMapper(HttpRestartServer server) { - Servlet servlet = this.serverProperties.getServlet(); - RemoteDevToolsProperties remote = this.properties.getRemote(); + public UrlHandlerMapper remoteRestartHandlerMapper(HttpRestartServer server, + ServerProperties serverProperties, DevToolsProperties properties) { + Servlet servlet = serverProperties.getServlet(); + RemoteDevToolsProperties remote = properties.getRemote(); String servletContextPath = (servlet.getContextPath() != null) ? servlet.getContextPath() : ""; String url = servletContextPath + remote.getContextPath() + "/restart"; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java index cefaf160d045..a55024255c06 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -57,17 +57,11 @@ @AutoConfigureBefore(DataSourceAutoConfiguration.class) public class TestDatabaseAutoConfiguration { - private final Environment environment; - - TestDatabaseAutoConfiguration(Environment environment) { - this.environment = environment; - } - @Bean @ConditionalOnProperty(prefix = "spring.test.database", name = "replace", havingValue = "AUTO_CONFIGURED") @ConditionalOnMissingBean - public DataSource dataSource() { - return new EmbeddedDataSourceFactory(this.environment).getEmbeddedDatabase(); + public DataSource dataSource(Environment environment) { + return new EmbeddedDataSourceFactory(environment).getEmbeddedDatabase(); } @Bean diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcWebClientAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcWebClientAutoConfiguration.java index 2a0b303cd113..7f2a1bb04700 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcWebClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcWebClientAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 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. @@ -42,18 +42,13 @@ @ConditionalOnProperty(prefix = "spring.test.mockmvc.webclient", name = "enabled", matchIfMissing = true) public class MockMvcWebClientAutoConfiguration { - private final Environment environment; - - MockMvcWebClientAutoConfiguration(Environment environment) { - this.environment = environment; - } - @Bean @ConditionalOnMissingBean({ WebClient.class, MockMvcWebClientBuilder.class }) @ConditionalOnBean(MockMvc.class) - public MockMvcWebClientBuilder mockMvcWebClientBuilder(MockMvc mockMvc) { + public MockMvcWebClientBuilder mockMvcWebClientBuilder(MockMvc mockMvc, + Environment environment) { return MockMvcWebClientBuilder.mockMvcSetup(mockMvc) - .withDelegate(new LocalHostWebClient(this.environment)); + .withDelegate(new LocalHostWebClient(environment)); } @Bean diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcWebDriverAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcWebDriverAutoConfiguration.java index 55319f2c1eb0..7182fa2ecf54 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcWebDriverAutoConfiguration.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcWebDriverAutoConfiguration.java @@ -48,20 +48,15 @@ @ConditionalOnProperty(prefix = "spring.test.mockmvc.webdriver", name = "enabled", matchIfMissing = true) public class MockMvcWebDriverAutoConfiguration { - private final Environment environment; - private static final String SECURITY_CONTEXT_EXECUTOR = "org.springframework.security.concurrent.DelegatingSecurityContextExecutor"; - MockMvcWebDriverAutoConfiguration(Environment environment) { - this.environment = environment; - } - @Bean @ConditionalOnMissingBean({ WebDriver.class, MockMvcHtmlUnitDriverBuilder.class }) @ConditionalOnBean(MockMvc.class) - public MockMvcHtmlUnitDriverBuilder mockMvcHtmlUnitDriverBuilder(MockMvc mockMvc) { + public MockMvcHtmlUnitDriverBuilder mockMvcHtmlUnitDriverBuilder(MockMvc mockMvc, + Environment environment) { return MockMvcHtmlUnitDriverBuilder.mockMvcSetup(mockMvc) - .withDelegate(new LocalHostWebConnectionHtmlUnitDriver(this.environment, + .withDelegate(new LocalHostWebConnectionHtmlUnitDriver(environment, BrowserVersion.CHROME)); }