Create @ManagementContextConfiguration annotation
Replace the previously used `EndpointWebMvcConfiguration` `spring.factories` key with a dedicated ManagementContextConfiguration annotation. Also renamed the EndpointWebMvcHypermediaConfiguration and EndpointWebMvcConfiguration classes to make it clearer that they are for the management context. See gh-3345
This commit is contained in:
parent
b2fcd77d93
commit
71dbec381a
|
|
@ -200,7 +200,7 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
|
|||
|
||||
@Configuration
|
||||
@Conditional(OnManagementMvcCondition.class)
|
||||
@Import(EndpointWebMvcImportSelector.class)
|
||||
@Import(ManagementContextConfigurationsImportSelector.class)
|
||||
protected static class EndpointWebMvcConfiguration {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
|||
*/
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
@Import(EndpointWebMvcImportSelector.class)
|
||||
@Import(ManagementContextConfigurationsImportSelector.class)
|
||||
public class EndpointWebMvcChildContextConfiguration {
|
||||
|
||||
private static Log logger = LogFactory
|
||||
|
|
|
|||
|
|
@ -82,13 +82,13 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
|||
* @author Dave Syer
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@Configuration
|
||||
@ManagementContextConfiguration
|
||||
@ConditionalOnClass(Link.class)
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnBean(HttpMessageConverters.class)
|
||||
@ConditionalOnProperty(value = "endpoints.enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties(ResourceProperties.class)
|
||||
public class EndpointWebMvcHypermediaConfiguration {
|
||||
public class EndpointWebMvcHypermediaManagementContextConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "endpoints.hal.enabled", matchIfMissing = true)
|
||||
|
|
@ -217,7 +217,7 @@ public class EndpointWebMvcHypermediaConfiguration {
|
|||
if (isHomePage(path) && hasManagementPath()) {
|
||||
String rel = this.management.getContextPath().substring(1);
|
||||
resource.add(linkTo(
|
||||
EndpointWebMvcHypermediaConfiguration.class).slash(
|
||||
EndpointWebMvcHypermediaManagementContextConfiguration.class).slash(
|
||||
this.management.getContextPath()).withRel(rel));
|
||||
}
|
||||
else {
|
||||
|
|
@ -41,7 +41,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
|
||||
|
|
@ -51,10 +50,10 @@ import org.springframework.web.cors.CorsConfiguration;
|
|||
* @author Dave Syer
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@Configuration
|
||||
@ManagementContextConfiguration
|
||||
@EnableConfigurationProperties({ HealthMvcEndpointProperties.class,
|
||||
EndpointCorsProperties.class })
|
||||
public class EndpointWebMvcConfiguration {
|
||||
public class EndpointWebMvcManagementContextConfiguration {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.autoconfigure;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Specialized {@link Configuration @Configuration} class that defines configuration
|
||||
* specific for the management context. Configurations should be registered in
|
||||
* {@code /META-INF/spring.factories} under the
|
||||
* {@code org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration}
|
||||
* key.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Configuration
|
||||
public @interface ManagementContextConfiguration {
|
||||
|
||||
}
|
||||
|
|
@ -23,19 +23,23 @@ import java.util.List;
|
|||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.context.annotation.DeferredImportSelector;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.io.support.SpringFactoriesLoader;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
* Selects configuration classes for the Actuator MVC endpoints. Customize the MVC
|
||||
* endpoints by adding an entries to <code>/META-INF/spring.factories</code> under the
|
||||
* {@link EndpointWebMvcConfiguration} key.
|
||||
* Selects configuration classes for the management context configuration. Entries are
|
||||
* loaded from {@code /META-INF/spring.factories} under the
|
||||
* {@code org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration}
|
||||
* key.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Phillip Webb
|
||||
* @see ManagementContextConfiguration
|
||||
*/
|
||||
@Order(Ordered.LOWEST_PRECEDENCE)
|
||||
class EndpointWebMvcImportSelector implements DeferredImportSelector,
|
||||
class ManagementContextConfigurationsImportSelector implements DeferredImportSelector,
|
||||
BeanClassLoaderAware {
|
||||
|
||||
private ClassLoader classLoader;
|
||||
|
|
@ -44,8 +48,9 @@ class EndpointWebMvcImportSelector implements DeferredImportSelector,
|
|||
public String[] selectImports(AnnotationMetadata metadata) {
|
||||
// Find all possible auto configuration classes, filtering duplicates
|
||||
List<String> factories = new ArrayList<String>(new LinkedHashSet<String>(
|
||||
SpringFactoriesLoader.loadFactoryNames(EndpointWebMvcConfiguration.class,
|
||||
this.classLoader)));
|
||||
SpringFactoriesLoader.loadFactoryNames(
|
||||
ManagementContextConfiguration.class, this.classLoader)));
|
||||
AnnotationAwareOrderComparator.sort(factories);
|
||||
return factories.toArray(new String[0]);
|
||||
}
|
||||
|
||||
|
|
@ -18,6 +18,6 @@ org.springframework.boot.actuate.autoconfigure.PublicMetricsAutoConfiguration,\
|
|||
org.springframework.boot.actuate.autoconfigure.TraceRepositoryAutoConfiguration,\
|
||||
org.springframework.boot.actuate.autoconfigure.TraceWebFilterAutoConfiguration
|
||||
|
||||
org.springframework.boot.actuate.autoconfigure.EndpointWebMvcConfiguration=\
|
||||
org.springframework.boot.actuate.autoconfigure.EndpointWebMvcConfiguration,\
|
||||
org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaConfiguration
|
||||
org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration=\
|
||||
org.springframework.boot.actuate.autoconfigure.EndpointWebMvcManagementContextConfiguration,\
|
||||
org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration
|
||||
|
|
|
|||
Loading…
Reference in New Issue