1616
1717package org .springframework .boot .actuate .autoconfigure .endpoint .web ;
1818
19+ import org .glassfish .jersey .server .ResourceConfig ;
20+
1921import org .springframework .boot .actuate .autoconfigure .endpoint .ExposeExcludePropertyEndpointFilter ;
2022import org .springframework .boot .actuate .autoconfigure .web .ManagementContextConfiguration ;
2123import org .springframework .boot .actuate .endpoint .web .ExposableServletEndpoint ;
2224import org .springframework .boot .actuate .endpoint .web .ServletEndpointRegistrar ;
2325import org .springframework .boot .actuate .endpoint .web .annotation .ServletEndpointsSupplier ;
26+ import org .springframework .boot .autoconfigure .condition .ConditionalOnClass ;
27+ import org .springframework .boot .autoconfigure .condition .ConditionalOnMissingClass ;
2428import org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication ;
2529import org .springframework .boot .autoconfigure .condition .ConditionalOnWebApplication .Type ;
30+ import org .springframework .boot .autoconfigure .web .servlet .DispatcherServletPathProvider ;
31+ import org .springframework .context .ApplicationContext ;
2632import org .springframework .context .annotation .Bean ;
2733import org .springframework .context .annotation .Configuration ;
34+ import org .springframework .web .servlet .DispatcherServlet ;
2835
2936/**
3037 * {@link ManagementContextConfiguration} for servlet endpoints.
3138 *
3239 * @author Phillip Webb
3340 * @author Andy Wilkinson
41+ * @author Madhura Bhave
3442 * @since 2.0.0
3543 */
3644@ Configuration
3745@ ConditionalOnWebApplication (type = Type .SERVLET )
3846public class ServletEndpointManagementContextConfiguration {
3947
40- @ Bean
41- public ServletEndpointRegistrar servletEndpointRegistrar (
42- WebEndpointProperties properties ,
43- ServletEndpointsSupplier servletEndpointsSupplier ) {
44- return new ServletEndpointRegistrar (properties .getBasePath (),
45- servletEndpointsSupplier .getEndpoints ());
46- }
47-
4848 @ Bean
4949 public ExposeExcludePropertyEndpointFilter <ExposableServletEndpoint > servletExposeExcludePropertyEndpointFilter (
5050 WebEndpointProperties properties ) {
@@ -53,4 +53,41 @@ public ExposeExcludePropertyEndpointFilter<ExposableServletEndpoint> servletExpo
5353 exposure .getInclude (), exposure .getExclude ());
5454 }
5555
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+
5693}
0 commit comments