Skip to content

Commit

Permalink
Merge branch '1.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Feb 24, 2016
2 parents 852ba54 + 1397169 commit bee651f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration.EndpointHypermediaEnabledCondition;
import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.DocsMvcEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.HalBrowserMvcEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.HalJsonMvcEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.HypermediaDisabled;
import org.springframework.boot.actuate.endpoint.mvc.ManagementServletContext;
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoints;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -50,6 +53,7 @@
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.io.ResourceLoader;
Expand Down Expand Up @@ -85,7 +89,7 @@
@ConditionalOnClass(Link.class)
@ConditionalOnWebApplication
@ConditionalOnBean(HttpMessageConverters.class)
@ConditionalOnProperty(value = "endpoints.enabled", matchIfMissing = true)
@Conditional(EndpointHypermediaEnabledCondition.class)
@EnableConfigurationProperties(ResourceProperties.class)
public class EndpointWebMvcHypermediaManagementContextConfiguration {

Expand All @@ -102,7 +106,7 @@ public String getContextPath() {
};
}

@ConditionalOnProperty(prefix = "endpoints.actuator", name = "enabled", matchIfMissing = true)
@ConditionalOnEnabledEndpoint("actuator")
@Bean
public HalJsonMvcEndpoint halJsonMvcEndpoint(
ManagementServletContext managementServletContext,
Expand All @@ -114,7 +118,7 @@ public HalJsonMvcEndpoint halJsonMvcEndpoint(
}

@Bean
@ConditionalOnProperty(prefix = "endpoints.docs", name = "enabled", matchIfMissing = true)
@ConditionalOnEnabledEndpoint("docs")
@ConditionalOnResource(resources = "classpath:/META-INF/resources/spring-boot-actuator/docs/index.html")
public DocsMvcEndpoint docsMvcEndpoint(
ManagementServletContext managementServletContext) {
Expand Down Expand Up @@ -333,4 +337,22 @@ public Map<String, Object> getEmbedded() {

}

static class EndpointHypermediaEnabledCondition extends AnyNestedCondition {

public EndpointHypermediaEnabledCondition() {
super(ConfigurationPhase.REGISTER_BEAN);
}

@ConditionalOnEnabledEndpoint("actuator")
static class ActuatorEndpointEnabled {

}

@ConditionalOnEnabledEndpoint("docs")
static class DocsEndpointEnabled {

}

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,7 +35,7 @@
*/
@Conditional(OnEnabledEndpointCondition.class)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Target({ ElementType.METHOD, ElementType.TYPE })
public @interface ConditionalOnEnabledEndpoint {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping;
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMappingCustomizer;
import org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.HalJsonMvcEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
Expand Down Expand Up @@ -451,6 +452,17 @@ public void shutdownEndpointEnabled() {
.hasSize(1);
}

@Test
public void actuatorEndpointEnabledIndividually() {
this.applicationContext.register(RootConfig.class, BaseConfiguration.class,
ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.applicationContext,
"endpoints.enabled:false", "endpoints.actuator.enabled:true");
this.applicationContext.refresh();
assertThat(this.applicationContext.getBeansOfType(HalJsonMvcEndpoint.class))
.hasSize(1);
}

private void endpointDisabled(String name, Class<? extends MvcEndpoint> type) {
this.applicationContext.register(RootConfig.class, BaseConfiguration.class,
ServerPortConfig.class, EndpointWebMvcAutoConfiguration.class);
Expand Down

0 comments on commit bee651f

Please sign in to comment.