mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Replace field injection with constructor injection in config classes
Closes gh-7563
This commit is contained in:
parent
5ac75c949c
commit
967625db1e
@ -16,10 +16,11 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint;
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.EnvironmentEndpoint;
|
||||
@ -67,17 +68,28 @@ import org.springframework.web.cors.CorsConfiguration;
|
||||
EndpointCorsProperties.class })
|
||||
public class EndpointWebMvcManagementContextConfiguration {
|
||||
|
||||
@Autowired
|
||||
private HealthMvcEndpointProperties healthMvcEndpointProperties;
|
||||
private final HealthMvcEndpointProperties healthMvcEndpointProperties;
|
||||
|
||||
@Autowired
|
||||
private ManagementServerProperties managementServerProperties;
|
||||
private final ManagementServerProperties managementServerProperties;
|
||||
|
||||
@Autowired
|
||||
private EndpointCorsProperties corsProperties;
|
||||
private final EndpointCorsProperties corsProperties;
|
||||
|
||||
@Autowired(required = false)
|
||||
private List<EndpointHandlerMappingCustomizer> mappingCustomizers;
|
||||
private final List<EndpointHandlerMappingCustomizer> mappingCustomizers;
|
||||
|
||||
public EndpointWebMvcManagementContextConfiguration(
|
||||
HealthMvcEndpointProperties healthMvcEndpointProperties,
|
||||
ManagementServerProperties managementServerProperties,
|
||||
EndpointCorsProperties corsProperties,
|
||||
ObjectProvider<List<EndpointHandlerMappingCustomizer>> mappingCustomizersProvider) {
|
||||
this.healthMvcEndpointProperties = healthMvcEndpointProperties;
|
||||
this.managementServerProperties = managementServerProperties;
|
||||
this.corsProperties = corsProperties;
|
||||
List<EndpointHandlerMappingCustomizer> providedCustomizers = mappingCustomizersProvider
|
||||
.getIfAvailable();
|
||||
this.mappingCustomizers = providedCustomizers == null
|
||||
? Collections.<EndpointHandlerMappingCustomizer>emptyList()
|
||||
: providedCustomizers;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ -87,10 +99,8 @@ public class EndpointWebMvcManagementContextConfiguration {
|
||||
EndpointHandlerMapping mapping = new EndpointHandlerMapping(endpoints,
|
||||
corsConfiguration);
|
||||
mapping.setPrefix(this.managementServerProperties.getContextPath());
|
||||
if (this.mappingCustomizers != null) {
|
||||
for (EndpointHandlerMappingCustomizer customizer : this.mappingCustomizers) {
|
||||
customizer.customize(mapping);
|
||||
}
|
||||
for (EndpointHandlerMappingCustomizer customizer : this.mappingCustomizers) {
|
||||
customizer.customize(mapping);
|
||||
}
|
||||
return mapping;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import javax.management.MBeanServer;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
@ -66,13 +66,16 @@ public class IntegrationAutoConfiguration {
|
||||
protected static class IntegrationJmxConfiguration
|
||||
implements EnvironmentAware, BeanFactoryAware {
|
||||
|
||||
private final IntegrationManagementConfigurer configurer;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
private RelaxedPropertyResolver propertyResolver;
|
||||
|
||||
@Autowired(required = false)
|
||||
@Qualifier(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME)
|
||||
private IntegrationManagementConfigurer configurer;
|
||||
protected IntegrationJmxConfiguration(
|
||||
@Qualifier(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME) ObjectProvider<IntegrationManagementConfigurer> configurerProvider) {
|
||||
this.configurer = configurerProvider.getIfAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
|
Loading…
Reference in New Issue
Block a user