|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2012-2017 the original author or authors. |
|
|
|
|
* Copyright 2012-2018 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,6 +16,7 @@
@@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.autoconfigure.endpoint.condition; |
|
|
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; |
|
|
|
|
@ -92,16 +93,23 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
@@ -92,16 +93,23 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
|
|
|
|
|
metadata instanceof MethodMetadata |
|
|
|
|
&& metadata.isAnnotated(Bean.class.getName()), |
|
|
|
|
"OnEnabledEndpointCondition may only be used on @Bean methods"); |
|
|
|
|
return getEndpointAttributes(context, (MethodMetadata) metadata); |
|
|
|
|
Class<?> endpointType = getEndpointType(context, (MethodMetadata) metadata); |
|
|
|
|
return getEndpointAttributes(endpointType); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private AnnotationAttributes getEndpointAttributes(ConditionContext context, |
|
|
|
|
MethodMetadata metadata) { |
|
|
|
|
private Class<?> getEndpointType(ConditionContext context, MethodMetadata metadata) { |
|
|
|
|
Map<String, Object> attributes = metadata |
|
|
|
|
.getAnnotationAttributes(ConditionalOnEnabledEndpoint.class.getName()); |
|
|
|
|
if (attributes != null && attributes.containsKey("endpoint")) { |
|
|
|
|
Class<?> target = (Class<?>) attributes.get("endpoint"); |
|
|
|
|
if (target != Void.class) { |
|
|
|
|
return target; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// We should be safe to load at this point since we are in the REGISTER_BEAN phase
|
|
|
|
|
try { |
|
|
|
|
Class<?> returnType = ClassUtils.forName(metadata.getReturnTypeName(), |
|
|
|
|
return ClassUtils.forName(metadata.getReturnTypeName(), |
|
|
|
|
context.getClassLoader()); |
|
|
|
|
return getEndpointAttributes(returnType); |
|
|
|
|
} |
|
|
|
|
catch (Throwable ex) { |
|
|
|
|
throw new IllegalStateException("Failed to extract endpoint id for " |
|
|
|
|
@ -119,8 +127,8 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
@@ -119,8 +127,8 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
|
|
|
|
|
attributes = AnnotatedElementUtils.findMergedAnnotationAttributes(type, |
|
|
|
|
EndpointExtension.class, false, true); |
|
|
|
|
Assert.state(attributes != null, |
|
|
|
|
"OnEnabledEndpointCondition may only be used on @Bean methods that " |
|
|
|
|
+ "return an @Endpoint or @EndpointExtension"); |
|
|
|
|
"No endpoint is specified and the return type of the @Bean method is " |
|
|
|
|
+ "neither an @Endpoint, nor an @EndpointExtension"); |
|
|
|
|
return getEndpointAttributes(attributes.getClass("endpoint")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|