Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
2d2aa96c
Commit
2d2aa96c
authored
Jan 07, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow ConditionalOnEnabledEndpoint to be set at class level
See gh-15451
parent
580c73a0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
15 deletions
+34
-15
ConditionalOnEnabledEndpoint.java
...gure/endpoint/condition/ConditionalOnEnabledEndpoint.java
+2
-2
OnEnabledEndpointCondition.java
...figure/endpoint/condition/OnEnabledEndpointCondition.java
+12
-12
ConditionalOnEnabledEndpointTests.java
...endpoint/condition/ConditionalOnEnabledEndpointTests.java
+20
-1
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpoint.java
View file @
2d2aa96c
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
...
@@ -92,7 +92,7 @@ import org.springframework.core.env.Environment;
* @see Endpoint
*/
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
ElementType
.
METHOD
)
@Target
(
{
ElementType
.
METHOD
,
ElementType
.
TYPE
}
)
@Documented
@Conditional
(
OnEnabledEndpointCondition
.
class
)
public
@interface
ConditionalOnEnabledEndpoint
{
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/OnEnabledEndpointCondition.java
View file @
2d2aa96c
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
...
@@ -90,15 +90,11 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
private
AnnotationAttributes
getEndpointAttributes
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
Assert
.
state
(
metadata
instanceof
MethodMetadata
&&
metadata
.
isAnnotated
(
Bean
.
class
.
getName
()),
"OnEnabledEndpointCondition may only be used on @Bean methods"
);
Class
<?>
endpointType
=
getEndpointType
(
context
,
(
MethodMetadata
)
metadata
);
return
getEndpointAttributes
(
endpointType
);
return
getEndpointAttributes
(
getEndpointType
(
context
,
metadata
));
}
private
Class
<?>
getEndpointType
(
ConditionContext
context
,
MethodMetadata
metadata
)
{
private
Class
<?>
getEndpointType
(
ConditionContext
context
,
AnnotatedTypeMetadata
metadata
)
{
Map
<
String
,
Object
>
attributes
=
metadata
.
getAnnotationAttributes
(
ConditionalOnEnabledEndpoint
.
class
.
getName
());
if
(
attributes
!=
null
&&
attributes
.
containsKey
(
"endpoint"
))
{
...
...
@@ -107,15 +103,19 @@ class OnEnabledEndpointCondition extends SpringBootCondition {
return
target
;
}
}
// We should be safe to load at this point since we are in the REGISTER_BEAN phase
Assert
.
state
(
metadata
instanceof
MethodMetadata
&&
metadata
.
isAnnotated
(
Bean
.
class
.
getName
()),
"OnEnabledEndpointCondition must be used on @Bean methods when the endpoint is not specified"
);
MethodMetadata
methodMetadata
=
(
MethodMetadata
)
metadata
;
try
{
return
ClassUtils
.
forName
(
metadata
.
getReturnTypeName
(),
return
ClassUtils
.
forName
(
met
hodMet
adata
.
getReturnTypeName
(),
context
.
getClassLoader
());
}
catch
(
Throwable
ex
)
{
throw
new
IllegalStateException
(
"Failed to extract endpoint id for "
+
met
adata
.
getDeclaringClassName
()
+
"."
+
metadata
.
getMethodName
(),
ex
);
+
met
hodMetadata
.
getDeclaringClassName
()
+
"."
+
methodMetadata
.
getMethodName
(),
ex
);
}
}
...
...
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/condition/ConditionalOnEnabledEndpointTests.java
View file @
2d2aa96c
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
...
@@ -148,6 +148,14 @@ public class ConditionalOnEnabledEndpointTests {
.
run
((
context
)
->
assertThat
(
context
).
hasBean
(
"fooBar"
));
}
@Test
public
void
outcomeWhenEndpointEnabledPropertyIsFalseOnClassShouldNotMatch
()
{
this
.
contextRunner
.
withPropertyValues
(
"management.endpoint.foo.enabled=false"
)
.
withUserConfiguration
(
FooEndpointEnabledByDefaultTrueOnConfigurationConfiguration
.
class
)
.
run
((
context
)
->
assertThat
(
context
).
doesNotHaveBean
(
"foo"
));
}
@Endpoint
(
id
=
"foo"
,
enableByDefault
=
true
)
static
class
FooEndpointEnabledByDefaultTrue
{
...
...
@@ -193,6 +201,17 @@ public class ConditionalOnEnabledEndpointTests {
}
@Configuration
@ConditionalOnEnabledEndpoint
(
endpoint
=
FooEndpointEnabledByDefaultTrue
.
class
)
static
class
FooEndpointEnabledByDefaultTrueOnConfigurationConfiguration
{
@Bean
public
FooEndpointEnabledByDefaultTrue
foo
()
{
return
new
FooEndpointEnabledByDefaultTrue
();
}
}
@Configuration
static
class
FooEndpointEnabledByDefaultFalseConfiguration
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment