Log summary of web-exposed endpoints during startup

Closes gh-12442
This commit is contained in:
Andy Wilkinson 2018-03-13 14:12:57 +00:00
parent f758a4ddd5
commit 2f1b2e3ce2
4 changed files with 33 additions and 4 deletions

View File

@ -33,7 +33,6 @@ import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
import org.springframework.boot.actuate.endpoint.web.ExposableWebEndpoint;
import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier;
import org.springframework.boot.actuate.endpoint.web.jersey.JerseyEndpointResourceFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
@ -76,7 +75,7 @@ class JerseyWebEndpointManagementContextConfiguration {
resourceConfig.registerResources(
new HashSet<>(resourceFactory.createEndpointResources(endpointMapping,
webEndpoints, endpointMediaTypes,
new EndpointLinksResolver(allEndpoints))));
new EndpointLinksResolver(allEndpoints, basePath))));
};
}

View File

@ -72,7 +72,8 @@ public class WebFluxEndpointManagementContextConfiguration {
allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
return new WebFluxEndpointHandlerMapping(endpointMapping, endpoints,
endpointMediaTypes, corsProperties.toCorsConfiguration(),
new EndpointLinksResolver(allEndpoints));
new EndpointLinksResolver(allEndpoints,
webEndpointProperties.getBasePath()));
}
@Bean

View File

@ -75,7 +75,8 @@ public class WebMvcEndpointManagementContextConfiguration {
webEndpointProperties.getBasePath());
return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints,
endpointMediaTypes, corsProperties.toCorsConfiguration(),
new EndpointLinksResolver(allEndpoints));
new EndpointLinksResolver(allEndpoints,
webEndpointProperties.getBasePath()));
}
@Bean

View File

@ -20,6 +20,9 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
/**
@ -30,12 +33,37 @@ import org.springframework.boot.actuate.endpoint.ExposableEndpoint;
*/
public class EndpointLinksResolver {
private static final Log logger = LogFactory.getLog(EndpointLinksResolver.class);
private final Collection<? extends ExposableEndpoint<?>> endpoints;
/**
* Creates a new {@code EndpointLinksResolver} that will resolve links to the given
* {@code endpoints}.
* @param endpoints the endpoints
* @deprecated since 2.0.1 in favor of
* {@link #EndpointLinksResolver(Collection, String)}
*/
@Deprecated
public EndpointLinksResolver(Collection<? extends ExposableEndpoint<?>> endpoints) {
this.endpoints = endpoints;
}
/**
* Creates a new {@code EndpointLinksResolver} that will resolve links to the given
* {@code endpoints} that are exposed beneath the given {@code basePath}.
* @param endpoints the endpoints
* @param basePath the basePath
*/
public EndpointLinksResolver(Collection<? extends ExposableEndpoint<?>> endpoints,
String basePath) {
this.endpoints = endpoints;
if (logger.isInfoEnabled()) {
logger.info("Exposing " + endpoints.size()
+ " endpoint(s) beneath base path '" + basePath + "'");
}
}
/**
* Resolves links to the known endpoints based on a request with the given
* {@code requestUrl}.