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
86cd7275
Commit
86cd7275
authored
Sep 06, 2017
by
Madhura Bhave
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MVC endpoints bean methods are @ConditionalOnMissingBean
Fixes gh-10105
parent
beb257f4
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
328 additions
and
14 deletions
+328
-14
EndpointWebMvcHypermediaManagementContextConfiguration.java
...dpointWebMvcHypermediaManagementContextConfiguration.java
+3
-1
EndpointWebMvcManagementContextConfiguration.java
...nfigure/EndpointWebMvcManagementContextConfiguration.java
+6
-0
EndpointWebMvcHypermediaManagementContextConfigurationTests.java
...tWebMvcHypermediaManagementContextConfigurationTests.java
+68
-5
EndpointWebMvcManagementContextConfigurationTests.java
...re/EndpointWebMvcManagementContextConfigurationTests.java
+251
-8
No files found.
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.java
View file @
86cd7275
...
@@ -111,8 +111,9 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
...
@@ -111,8 +111,9 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
};
};
}
}
@ConditionalOnEnabledEndpoint
(
"actuator"
)
@Bean
@Bean
@ConditionalOnEnabledEndpoint
(
"actuator"
)
@ConditionalOnMissingBean
public
HalJsonMvcEndpoint
halJsonMvcEndpoint
(
public
HalJsonMvcEndpoint
halJsonMvcEndpoint
(
ManagementServletContext
managementServletContext
,
ManagementServletContext
managementServletContext
,
ResourceProperties
resources
,
ResourceLoader
resourceLoader
)
{
ResourceProperties
resources
,
ResourceLoader
resourceLoader
)
{
...
@@ -137,6 +138,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
...
@@ -137,6 +138,7 @@ public class EndpointWebMvcHypermediaManagementContextConfiguration {
static
class
DocsMvcEndpointConfiguration
{
static
class
DocsMvcEndpointConfiguration
{
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
(
"docs"
)
@ConditionalOnEnabledEndpoint
(
"docs"
)
@ConditionalOnResource
(
resources
=
"classpath:/META-INF/resources/spring-boot-actuator/docs/index.html"
)
@ConditionalOnResource
(
resources
=
"classpath:/META-INF/resources/spring-boot-actuator/docs/index.html"
)
public
DocsMvcEndpoint
docsMvcEndpoint
(
public
DocsMvcEndpoint
docsMvcEndpoint
(
...
...
spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfiguration.java
View file @
86cd7275
...
@@ -143,6 +143,7 @@ public class EndpointWebMvcManagementContextConfiguration {
...
@@ -143,6 +143,7 @@ public class EndpointWebMvcManagementContextConfiguration {
}
}
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
EnvironmentEndpoint
.
class
)
@ConditionalOnBean
(
EnvironmentEndpoint
.
class
)
@ConditionalOnEnabledEndpoint
(
"env"
)
@ConditionalOnEnabledEndpoint
(
"env"
)
public
EnvironmentMvcEndpoint
environmentMvcEndpoint
(
EnvironmentEndpoint
delegate
)
{
public
EnvironmentMvcEndpoint
environmentMvcEndpoint
(
EnvironmentEndpoint
delegate
)
{
...
@@ -173,6 +174,7 @@ public class EndpointWebMvcManagementContextConfiguration {
...
@@ -173,6 +174,7 @@ public class EndpointWebMvcManagementContextConfiguration {
}
}
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
LoggersEndpoint
.
class
)
@ConditionalOnBean
(
LoggersEndpoint
.
class
)
@ConditionalOnEnabledEndpoint
(
"loggers"
)
@ConditionalOnEnabledEndpoint
(
"loggers"
)
public
LoggersMvcEndpoint
loggersMvcEndpoint
(
LoggersEndpoint
delegate
)
{
public
LoggersMvcEndpoint
loggersMvcEndpoint
(
LoggersEndpoint
delegate
)
{
...
@@ -180,6 +182,7 @@ public class EndpointWebMvcManagementContextConfiguration {
...
@@ -180,6 +182,7 @@ public class EndpointWebMvcManagementContextConfiguration {
}
}
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
MetricsEndpoint
.
class
)
@ConditionalOnBean
(
MetricsEndpoint
.
class
)
@ConditionalOnEnabledEndpoint
(
"metrics"
)
@ConditionalOnEnabledEndpoint
(
"metrics"
)
public
MetricsMvcEndpoint
metricsMvcEndpoint
(
MetricsEndpoint
delegate
)
{
public
MetricsMvcEndpoint
metricsMvcEndpoint
(
MetricsEndpoint
delegate
)
{
...
@@ -187,6 +190,7 @@ public class EndpointWebMvcManagementContextConfiguration {
...
@@ -187,6 +190,7 @@ public class EndpointWebMvcManagementContextConfiguration {
}
}
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledEndpoint
(
"logfile"
)
@ConditionalOnEnabledEndpoint
(
"logfile"
)
@Conditional
(
LogFileCondition
.
class
)
@Conditional
(
LogFileCondition
.
class
)
public
LogFileMvcEndpoint
logfileMvcEndpoint
()
{
public
LogFileMvcEndpoint
logfileMvcEndpoint
()
{
...
@@ -194,6 +198,7 @@ public class EndpointWebMvcManagementContextConfiguration {
...
@@ -194,6 +198,7 @@ public class EndpointWebMvcManagementContextConfiguration {
}
}
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
ShutdownEndpoint
.
class
)
@ConditionalOnBean
(
ShutdownEndpoint
.
class
)
@ConditionalOnEnabledEndpoint
(
value
=
"shutdown"
,
enabledByDefault
=
false
)
@ConditionalOnEnabledEndpoint
(
value
=
"shutdown"
,
enabledByDefault
=
false
)
public
ShutdownMvcEndpoint
shutdownMvcEndpoint
(
ShutdownEndpoint
delegate
)
{
public
ShutdownMvcEndpoint
shutdownMvcEndpoint
(
ShutdownEndpoint
delegate
)
{
...
@@ -201,6 +206,7 @@ public class EndpointWebMvcManagementContextConfiguration {
...
@@ -201,6 +206,7 @@ public class EndpointWebMvcManagementContextConfiguration {
}
}
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean
(
AuditEventRepository
.
class
)
@ConditionalOnBean
(
AuditEventRepository
.
class
)
@ConditionalOnEnabledEndpoint
(
"auditevents"
)
@ConditionalOnEnabledEndpoint
(
"auditevents"
)
public
AuditEventsMvcEndpoint
auditEventMvcEndpoint
(
public
AuditEventsMvcEndpoint
auditEventMvcEndpoint
(
...
...
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfigurationTests.java
View file @
86cd7275
...
@@ -45,6 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -45,6 +45,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link EndpointWebMvcHypermediaManagementContextConfiguration}.
* Tests for {@link EndpointWebMvcHypermediaManagementContextConfiguration}.
*
*
* @author Andy Wilkinson
* @author Andy Wilkinson
* @author Madhura Bhave
*/
*/
public
class
EndpointWebMvcHypermediaManagementContextConfigurationTests
{
public
class
EndpointWebMvcHypermediaManagementContextConfigurationTests
{
...
@@ -112,7 +113,38 @@ public class EndpointWebMvcHypermediaManagementContextConfigurationTests {
...
@@ -112,7 +113,38 @@ public class EndpointWebMvcHypermediaManagementContextConfigurationTests {
.
isEqualTo
(
"http://localhost/docs/#spring_boot_actuator__{rel}"
);
.
isEqualTo
(
"http://localhost/docs/#spring_boot_actuator__{rel}"
);
}
}
@Test
public
void
halJsonMvcEndpointIsConditionalOnMissingBean
()
throws
Exception
{
createContext
();
this
.
context
.
register
(
HalJsonConfiguration
.
class
,
TestConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
EndpointWebMvcHypermediaManagementContextConfiguration
.
class
);
this
.
context
.
refresh
();
HalJsonMvcEndpoint
bean
=
this
.
context
.
getBean
(
HalJsonMvcEndpoint
.
class
);
assertThat
(
bean
).
isInstanceOf
(
TestHalJsonMvcEndpoint
.
class
);
}
@Test
public
void
docsMvcEndpointIsConditionalOnMissingBean
()
throws
Exception
{
createContext
();
this
.
context
.
register
(
DocsConfiguration
.
class
,
TestConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
EndpointWebMvcHypermediaManagementContextConfiguration
.
class
);
this
.
context
.
refresh
();
DocsMvcEndpoint
bean
=
this
.
context
.
getBean
(
DocsMvcEndpoint
.
class
);
assertThat
(
bean
).
isInstanceOf
(
TestDocsMvcEndpoint
.
class
);
}
private
void
load
(
String
...
properties
)
{
private
void
load
(
String
...
properties
)
{
createContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
properties
);
this
.
context
.
register
(
TestConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
EndpointWebMvcHypermediaManagementContextConfiguration
.
class
);
this
.
context
.
refresh
();
}
private
void
createContext
()
{
this
.
context
=
new
AnnotationConfigWebApplicationContext
();
this
.
context
=
new
AnnotationConfigWebApplicationContext
();
this
.
context
.
setClassLoader
(
new
ClassLoader
(
getClass
().
getClassLoader
())
{
this
.
context
.
setClassLoader
(
new
ClassLoader
(
getClass
().
getClassLoader
())
{
...
@@ -126,11 +158,6 @@ public class EndpointWebMvcHypermediaManagementContextConfigurationTests {
...
@@ -126,11 +158,6 @@ public class EndpointWebMvcHypermediaManagementContextConfigurationTests {
}
}
});
});
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
properties
);
this
.
context
.
register
(
TestConfiguration
.
class
,
HttpMessageConvertersAutoConfiguration
.
class
,
EndpointWebMvcHypermediaManagementContextConfiguration
.
class
);
this
.
context
.
refresh
();
}
}
private
String
getCurieHref
()
{
private
String
getCurieHref
()
{
...
@@ -152,4 +179,40 @@ public class EndpointWebMvcHypermediaManagementContextConfigurationTests {
...
@@ -152,4 +179,40 @@ public class EndpointWebMvcHypermediaManagementContextConfigurationTests {
}
}
@Configuration
static
class
DocsConfiguration
{
@Bean
public
DocsMvcEndpoint
testDocsMvcEndpoint
(
ManagementServletContext
managementServletContext
)
{
return
new
TestDocsMvcEndpoint
(
managementServletContext
);
}
}
@Configuration
static
class
HalJsonConfiguration
{
@Bean
public
HalJsonMvcEndpoint
testHalJsonMvcEndpoint
(
ManagementServletContext
managementServletContext
)
{
return
new
TestHalJsonMvcEndpoint
(
managementServletContext
);
}
}
static
class
TestDocsMvcEndpoint
extends
DocsMvcEndpoint
{
TestDocsMvcEndpoint
(
ManagementServletContext
managementServletContext
)
{
super
(
managementServletContext
);
}
}
static
class
TestHalJsonMvcEndpoint
extends
HalJsonMvcEndpoint
{
TestHalJsonMvcEndpoint
(
ManagementServletContext
managementServletContext
)
{
super
(
managementServletContext
);
}
}
}
}
spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcManagementContextConfigurationTests.java
View file @
86cd7275
This diff is collapsed.
Click to expand it.
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