16
16
17
17
package org .springframework .boot .actuate .autoconfigure .endpoint .web ;
18
18
19
+ import org .glassfish .jersey .server .ResourceConfig ;
20
+
19
21
import org .springframework .boot .actuate .autoconfigure .endpoint .ExposeExcludePropertyEndpointFilter ;
20
22
import org .springframework .boot .actuate .autoconfigure .web .ManagementContextConfiguration ;
21
23
import org .springframework .boot .actuate .endpoint .web .ExposableServletEndpoint ;
22
24
import org .springframework .boot .actuate .endpoint .web .ServletEndpointRegistrar ;
23
25
import org .springframework .boot .actuate .endpoint .web .annotation .ServletEndpointsSupplier ;
26
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
27
+ import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingClass ;
24
28
import org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication ;
25
29
import org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication .Type ;
30
+ import org .springframework .boot .autoconfigure .web .servlet .DispatcherServletPathProvider ;
31
+ import org .springframework .context .ApplicationContext ;
26
32
import org .springframework .context .annotation .Bean ;
27
33
import org .springframework .context .annotation .Configuration ;
34
+ import org .springframework .web .servlet .DispatcherServlet ;
28
35
29
36
/**
30
37
* {@link ManagementContextConfiguration} for servlet endpoints.
31
38
*
32
39
* @author Phillip Webb
33
40
* @author Andy Wilkinson
41
+ * @author Madhura Bhave
34
42
* @since 2.0.0
35
43
*/
36
44
@ Configuration
37
45
@ ConditionalOnWebApplication (type = Type .SERVLET )
38
46
public class ServletEndpointManagementContextConfiguration {
39
47
40
- @ Bean
41
- public ServletEndpointRegistrar servletEndpointRegistrar (
42
- WebEndpointProperties properties ,
43
- ServletEndpointsSupplier servletEndpointsSupplier ) {
44
- return new ServletEndpointRegistrar (properties .getBasePath (),
45
- servletEndpointsSupplier .getEndpoints ());
46
- }
47
-
48
48
@ Bean
49
49
public ExposeExcludePropertyEndpointFilter <ExposableServletEndpoint > servletExposeExcludePropertyEndpointFilter (
50
50
WebEndpointProperties properties ) {
@@ -53,4 +53,41 @@ public ExposeExcludePropertyEndpointFilter<ExposableServletEndpoint> servletExpo
53
53
exposure .getInclude (), exposure .getExclude ());
54
54
}
55
55
56
+ @ Configuration
57
+ @ ConditionalOnClass (DispatcherServlet .class )
58
+ public class WebMvcServletEndpointManagementContextConfiguration {
59
+
60
+ private final ApplicationContext context ;
61
+
62
+ public WebMvcServletEndpointManagementContextConfiguration (ApplicationContext context ) {
63
+ this .context = context ;
64
+ }
65
+
66
+ @ Bean
67
+ public ServletEndpointRegistrar servletEndpointRegistrar (
68
+ WebEndpointProperties properties ,
69
+ ServletEndpointsSupplier servletEndpointsSupplier ) {
70
+ DispatcherServletPathProvider servletPathProvider = this .context .getBean (DispatcherServletPathProvider .class );
71
+ String servletPath = (servletPathProvider .getServletPath ().equals ("/" ) ? "" : servletPathProvider .getServletPath ());
72
+ return new ServletEndpointRegistrar (servletPath + properties .getBasePath (),
73
+ servletEndpointsSupplier .getEndpoints ());
74
+ }
75
+
76
+ }
77
+
78
+ @ Configuration
79
+ @ ConditionalOnClass (ResourceConfig .class )
80
+ @ ConditionalOnMissingClass ("org.springframework.web.servlet.DispatcherServlet" )
81
+ public class JerseyServletEndpointManagementContextConfiguration {
82
+
83
+ @ Bean
84
+ public ServletEndpointRegistrar servletEndpointRegistrar (
85
+ WebEndpointProperties properties ,
86
+ ServletEndpointsSupplier servletEndpointsSupplier ) {
87
+ return new ServletEndpointRegistrar (properties .getBasePath (),
88
+ servletEndpointsSupplier .getEndpoints ());
89
+ }
90
+
91
+ }
92
+
56
93
}
0 commit comments