Update auto-configuration @Bean methods to return most specific type
Closes gh-2536 Closes gh-2403
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2015 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.
|
||||
@@ -60,7 +60,7 @@ public class AuditAutoConfiguration {
|
||||
@ConditionalOnMissingBean(AuditEventRepository.class)
|
||||
protected static class AuditEventRepositoryConfiguration {
|
||||
@Bean
|
||||
public AuditEventRepository auditEventRepository() throws Exception {
|
||||
public InMemoryAuditEventRepository auditEventRepository() throws Exception {
|
||||
return new InMemoryAuditEventRepository();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,28 +124,28 @@ public class CrshAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "shell", name = "auth", havingValue = "jaas")
|
||||
@ConditionalOnMissingBean({ CrshShellAuthenticationProperties.class })
|
||||
public CrshShellAuthenticationProperties jaasAuthenticationProperties() {
|
||||
@ConditionalOnMissingBean(CrshShellAuthenticationProperties.class)
|
||||
public JaasAuthenticationProperties jaasAuthenticationProperties() {
|
||||
return new JaasAuthenticationProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "shell", name = "auth", havingValue = "key")
|
||||
@ConditionalOnMissingBean({ CrshShellAuthenticationProperties.class })
|
||||
public CrshShellAuthenticationProperties keyAuthenticationProperties() {
|
||||
@ConditionalOnMissingBean(CrshShellAuthenticationProperties.class)
|
||||
public KeyAuthenticationProperties keyAuthenticationProperties() {
|
||||
return new KeyAuthenticationProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "shell", name = "auth", havingValue = "simple", matchIfMissing = true)
|
||||
@ConditionalOnMissingBean({ CrshShellAuthenticationProperties.class })
|
||||
public CrshShellAuthenticationProperties simpleAuthenticationProperties() {
|
||||
@ConditionalOnMissingBean(CrshShellAuthenticationProperties.class)
|
||||
public SimpleAuthenticationProperties simpleAuthenticationProperties() {
|
||||
return new SimpleAuthenticationProperties();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean({ PluginLifeCycle.class })
|
||||
public PluginLifeCycle shellBootstrap() {
|
||||
@ConditionalOnMissingBean(PluginLifeCycle.class)
|
||||
public CrshBootstrapBean shellBootstrap() {
|
||||
CrshBootstrapBean bootstrapBean = new CrshBootstrapBean();
|
||||
bootstrapBean.setConfig(this.properties.asCrshShellConfig());
|
||||
return bootstrapBean;
|
||||
@@ -156,7 +156,7 @@ public class CrshAutoConfiguration {
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "shell", name = "auth", havingValue = "spring", matchIfMissing = true)
|
||||
@ConditionalOnBean({ AuthenticationManager.class })
|
||||
@ConditionalOnBean(AuthenticationManager.class)
|
||||
@AutoConfigureAfter(CrshAutoConfiguration.class)
|
||||
public static class AuthenticationManagerAdapterAutoConfiguration {
|
||||
|
||||
@@ -164,13 +164,13 @@ public class CrshAutoConfiguration {
|
||||
private ManagementServerProperties management;
|
||||
|
||||
@Bean
|
||||
public CRaSHPlugin<?> shellAuthenticationManager() {
|
||||
public AuthenticationManagerAdapter shellAuthenticationManager() {
|
||||
return new AuthenticationManagerAdapter();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean({ CrshShellAuthenticationProperties.class })
|
||||
public CrshShellAuthenticationProperties springAuthenticationProperties() {
|
||||
@ConditionalOnMissingBean(CrshShellAuthenticationProperties.class)
|
||||
public SpringAuthenticationProperties springAuthenticationProperties() {
|
||||
// In case no shell.auth property is provided fall back to Spring Security
|
||||
// based authentication and get role to access shell from
|
||||
// ManagementServerProperties.
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletException;
|
||||
@@ -91,11 +90,12 @@ import org.springframework.web.servlet.DispatcherServlet;
|
||||
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class })
|
||||
@ConditionalOnWebApplication
|
||||
@AutoConfigureAfter({ PropertyPlaceholderAutoConfiguration.class,
|
||||
EmbeddedServletContainerAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
||||
ManagementServerPropertiesAutoConfiguration.class, RepositoryRestMvcAutoConfiguration.class,
|
||||
HypermediaAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class })
|
||||
EmbeddedServletContainerAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
||||
ManagementServerPropertiesAutoConfiguration.class,
|
||||
RepositoryRestMvcAutoConfiguration.class, HypermediaAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class })
|
||||
public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
||||
BeanFactoryAware, SmartInitializingSingleton {
|
||||
BeanFactoryAware, SmartInitializingSingleton {
|
||||
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(EndpointWebMvcAutoConfiguration.class);
|
||||
@@ -130,7 +130,7 @@ BeanFactoryAware, SmartInitializingSingleton {
|
||||
if (managementPort == ManagementServerPort.DIFFERENT
|
||||
&& this.applicationContext instanceof EmbeddedWebApplicationContext
|
||||
&& ((EmbeddedWebApplicationContext) this.applicationContext)
|
||||
.getEmbeddedServletContainer() != null) {
|
||||
.getEmbeddedServletContainer() != null) {
|
||||
createChildManagementContext();
|
||||
}
|
||||
if (managementPort == ManagementServerPort.SAME
|
||||
@@ -150,7 +150,7 @@ BeanFactoryAware, SmartInitializingSingleton {
|
||||
EmbeddedServletContainerAutoConfiguration.class,
|
||||
DispatcherServletAutoConfiguration.class);
|
||||
CloseEventPropagationListener
|
||||
.addIfPossible(this.applicationContext, childContext);
|
||||
.addIfPossible(this.applicationContext, childContext);
|
||||
try {
|
||||
childContext.refresh();
|
||||
managementContextResolver().setApplicationContext(childContext);
|
||||
@@ -193,7 +193,8 @@ BeanFactoryAware, SmartInitializingSingleton {
|
||||
protected static class ApplicationContextFilterConfiguration {
|
||||
|
||||
@Bean
|
||||
public Filter applicationContextIdFilter(ApplicationContext context) {
|
||||
public ApplicationContextHeaderFilter applicationContextIdFilter(
|
||||
ApplicationContext context) {
|
||||
return new ApplicationContextHeaderFilter(context);
|
||||
}
|
||||
|
||||
@@ -222,7 +223,7 @@ BeanFactoryAware, SmartInitializingSingleton {
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request,
|
||||
HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
throws ServletException, IOException {
|
||||
if (this.properties == null) {
|
||||
this.properties = this.applicationContext
|
||||
.getBean(ManagementServerProperties.class);
|
||||
@@ -241,7 +242,7 @@ BeanFactoryAware, SmartInitializingSingleton {
|
||||
* parent to a child.
|
||||
*/
|
||||
private static class CloseEventPropagationListener implements
|
||||
ApplicationListener<ContextClosedEvent> {
|
||||
ApplicationListener<ContextClosedEvent> {
|
||||
|
||||
private final ApplicationContext parentContext;
|
||||
|
||||
@@ -276,7 +277,7 @@ BeanFactoryAware, SmartInitializingSingleton {
|
||||
}
|
||||
|
||||
private static class OnManagementMvcCondition extends SpringBootCondition implements
|
||||
ConfigurationCondition {
|
||||
ConfigurationCondition {
|
||||
|
||||
@Override
|
||||
public ConfigurationPhase getConfigurationPhase() {
|
||||
@@ -325,7 +326,7 @@ BeanFactoryAware, SmartInitializingSingleton {
|
||||
return ((managementPort == null)
|
||||
|| (serverPort == null && managementPort.equals(8080))
|
||||
|| (managementPort != 0 && managementPort.equals(serverPort)) ? SAME
|
||||
: DIFFERENT);
|
||||
: DIFFERENT);
|
||||
}
|
||||
|
||||
private static Integer getPortProperty(Environment environment, String prefix) {
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
@@ -84,6 +82,8 @@ import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
|
||||
/**
|
||||
* Configuration for hypermedia in HTTP endpoints.
|
||||
*
|
||||
@@ -136,7 +136,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
|
||||
@Configuration("EndpointHypermediaAutoConfiguration.MissingResourceCondition")
|
||||
@ConditionalOnResource(resources = "classpath:/META-INF/spring-data-rest/hal-browser/index.html")
|
||||
protected static class MissingSpringDataRestResourceCondition extends
|
||||
SpringBootCondition {
|
||||
SpringBootCondition {
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
@@ -175,7 +175,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
|
||||
}
|
||||
|
||||
private static class NotSpringDataRestHomePageCondition extends
|
||||
SpringBootCondition {
|
||||
SpringBootCondition {
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
@@ -302,7 +302,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
|
||||
public Object beforeBodyWrite(Object body, MethodParameter returnType,
|
||||
MediaType selectedContentType,
|
||||
Class<? extends HttpMessageConverter<?>> selectedConverterType,
|
||||
ServerHttpRequest request, ServerHttpResponse response) {
|
||||
ServerHttpRequest request, ServerHttpResponse response) {
|
||||
if (request instanceof ServletServerHttpRequest) {
|
||||
beforeBodyWrite(body, (ServletServerHttpRequest) request);
|
||||
}
|
||||
@@ -383,7 +383,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
|
||||
public Object beforeBodyWrite(Object body, MethodParameter returnType,
|
||||
MediaType selectedContentType,
|
||||
Class<? extends HttpMessageConverter<?>> selectedConverterType,
|
||||
ServerHttpRequest request, ServerHttpResponse response) {
|
||||
ServerHttpRequest request, ServerHttpResponse response) {
|
||||
if (request instanceof ServletServerHttpRequest) {
|
||||
return beforeBodyWrite(body, returnType, selectedContentType,
|
||||
selectedConverterType, (ServletServerHttpRequest) request,
|
||||
@@ -395,7 +395,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
|
||||
private Object beforeBodyWrite(Object body, MethodParameter returnType,
|
||||
MediaType selectedContentType,
|
||||
Class<? extends HttpMessageConverter<?>> selectedConverterType,
|
||||
ServletServerHttpRequest request, ServerHttpResponse response) {
|
||||
ServletServerHttpRequest request, ServerHttpResponse response) {
|
||||
if (body == null || body instanceof Resource) {
|
||||
// Assume it already was handled or it already has its links
|
||||
return body;
|
||||
@@ -420,7 +420,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
|
||||
@SuppressWarnings("unchecked")
|
||||
private HttpMessageConverter<Object> findConverter(
|
||||
Class<? extends HttpMessageConverter<?>> selectedConverterType,
|
||||
MediaType mediaType) {
|
||||
MediaType mediaType) {
|
||||
if (this.converterCache.containsKey(mediaType)) {
|
||||
return (HttpMessageConverter<Object>) this.converterCache
|
||||
.get(mediaType);
|
||||
|
||||
@@ -92,8 +92,8 @@ public class HealthIndicatorAutoConfiguration {
|
||||
private HealthIndicatorAutoConfigurationProperties configurationProperties = new HealthIndicatorAutoConfigurationProperties();
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public HealthAggregator healthAggregator() {
|
||||
@ConditionalOnMissingBean(HealthAggregator.class)
|
||||
public OrderedHealthAggregator healthAggregator() {
|
||||
OrderedHealthAggregator healthAggregator = new OrderedHealthAggregator();
|
||||
if (this.configurationProperties.getOrder() != null) {
|
||||
healthAggregator.setStatusOrder(this.configurationProperties.getOrder());
|
||||
@@ -103,7 +103,7 @@ public class HealthIndicatorAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(HealthIndicator.class)
|
||||
public HealthIndicator applicationHealthIndicator() {
|
||||
public ApplicationHealthIndicator applicationHealthIndicator() {
|
||||
return new ApplicationHealthIndicator();
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ public class HealthIndicatorAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "diskSpaceHealthIndicator")
|
||||
public HealthIndicator diskSpaceHealthIndicator(
|
||||
public DiskSpaceHealthIndicator diskSpaceHealthIndicator(
|
||||
DiskSpaceHealthIndicatorProperties properties) {
|
||||
return new DiskSpaceHealthIndicator(properties);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletRegistration;
|
||||
|
||||
@@ -56,7 +55,7 @@ public class MetricFilterAutoConfiguration {
|
||||
private GaugeService gaugeService;
|
||||
|
||||
@Bean
|
||||
public Filter metricFilter() {
|
||||
public MetricsFilter metricFilter() {
|
||||
return new MetricsFilter(this.counterService, this.gaugeService);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,14 +91,14 @@ public class MetricRepositoryAutoConfiguration {
|
||||
private MetricWriter writer;
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public CounterService counterService() {
|
||||
@ConditionalOnMissingBean(CounterService.class)
|
||||
public DefaultCounterService counterService() {
|
||||
return new DefaultCounterService(this.writer);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public GaugeService gaugeService() {
|
||||
@ConditionalOnMissingBean(GaugeService.class)
|
||||
public DefaultGaugeService gaugeService() {
|
||||
return new DefaultGaugeService(this.writer);
|
||||
}
|
||||
|
||||
@@ -130,14 +130,14 @@ public class MetricRepositoryAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public CounterService counterService(CounterBuffers writer) {
|
||||
@ConditionalOnMissingBean(CounterService.class)
|
||||
public BufferCounterService counterService(CounterBuffers writer) {
|
||||
return new BufferCounterService(writer);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public GaugeService gaugeService(GaugeBuffers writer) {
|
||||
@ConditionalOnMissingBean(GaugeService.class)
|
||||
public BufferGaugeService gaugeService(GaugeBuffers writer) {
|
||||
return new BufferGaugeService(writer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics;
|
||||
import org.springframework.boot.actuate.endpoint.PublicMetrics;
|
||||
import org.springframework.boot.actuate.metrics.CounterService;
|
||||
import org.springframework.boot.actuate.metrics.GaugeService;
|
||||
import org.springframework.boot.actuate.metrics.dropwizard.DropwizardMetricServices;
|
||||
@@ -56,7 +55,7 @@ public class MetricsDropwizardAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PublicMetrics dropwizardPublicMetrics(MetricRegistry metricRegistry) {
|
||||
public MetricReaderPublicMetrics dropwizardPublicMetrics(MetricRegistry metricRegistry) {
|
||||
MetricRegistryMetricReader reader = new MetricRegistryMetricReader(metricRegistry);
|
||||
return new MetricReaderPublicMetrics(reader);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2015 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.
|
||||
@@ -31,9 +31,9 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
public class TraceRepositoryAutoConfiguration {
|
||||
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnMissingBean(TraceRepository.class)
|
||||
@Bean
|
||||
public TraceRepository traceRepository() {
|
||||
public InMemoryTraceRepository traceRepository() {
|
||||
return new InMemoryTraceRepository();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user