69
69
*
70
70
* @author Andy Wilkinson
71
71
* @author Phillip Webb
72
+ * @author yongjunhong
72
73
* @since 2.0.0
73
74
*/
74
75
@ ManagementContextConfiguration (proxyBeanMethods = false )
@@ -93,6 +94,19 @@ public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpoint
93
94
allEndpoints .addAll (controllerEndpointsSupplier .getEndpoints ());
94
95
String basePath = webEndpointProperties .getBasePath ();
95
96
EndpointMapping endpointMapping = new EndpointMapping (basePath );
97
+
98
+ if (basePath .isEmpty () && ManagementPortType .get (environment ).equals (ManagementPortType .SAME )) {
99
+ for (ExposableWebEndpoint endpoint : webEndpoints ) {
100
+ if ("/" .equals (endpoint .getRootPath ())) {
101
+ throw new IllegalStateException (
102
+ "Management endpoints and endpoint path are both mapped to '/' on the server port which will " +
103
+ "block access to other endpoints. Please use a different path for management endpoints or " +
104
+ "map them to a dedicated management port."
105
+ );
106
+ }
107
+ }
108
+ }
109
+
96
110
boolean shouldRegisterLinksMapping = shouldRegisterLinksMapping (webEndpointProperties , environment , basePath );
97
111
return new WebMvcEndpointHandlerMapping (endpointMapping , webEndpoints , endpointMediaTypes ,
98
112
corsProperties .toCorsConfiguration (), new EndpointLinksResolver (allEndpoints , basePath ),
@@ -154,7 +168,7 @@ static EndpointObjectMapperWebMvcConfigurer endpointObjectMapperWebMvcConfigurer
154
168
static class EndpointObjectMapperWebMvcConfigurer implements WebMvcConfigurer {
155
169
156
170
private static final List <MediaType > MEDIA_TYPES = Collections
157
- .unmodifiableList (Arrays .asList (MediaType .APPLICATION_JSON , new MediaType ("application" , "*+json" )));
171
+ .unmodifiableList (Arrays .asList (MediaType .APPLICATION_JSON , new MediaType ("application" , "*+json" )));
158
172
159
173
private final EndpointObjectMapper endpointObjectMapper ;
160
174
@@ -181,3 +195,4 @@ private void configure(MappingJackson2HttpMessageConverter converter) {
181
195
}
182
196
183
197
}
198
+
0 commit comments