@Retention(value=RUNTIME) @Target(value={METHOD,TYPE}) @Documented @Conditional(value=org.springframework.boot.actuate.autoconfigure.endpoint.condition.OnAvailableEndpointCondition.class) public @interface ConditionalOnAvailableEndpoint
@Conditional
that checks whether an endpoint is available. An
endpoint is considered available if it is both enabled and exposed. Matches enablement
according to the endpoints specific Environment
property, falling back to
management.endpoints.enabled-by-default
or failing that
Endpoint.enableByDefault()
. Matches exposure according to any of the
management.endpoints.web.exposure.<id>
or
management.endpoints.jmx.exposure.<id>
specific properties or failing that to
whether the application runs on
CloudPlatform.CLOUD_FOUNDRY
. Both those
conditions should match for the endpoint to be considered available.
When placed on a @Bean
method, the endpoint defaults to the return type of the
factory method:
@Configuration public class MyConfiguration { @ConditionalOnAvailableEndpoint @Bean public MyEndpoint myEndpoint() { ... } }
It is also possible to use the same mechanism for extensions:
@Configuration public class MyConfiguration { @ConditionalOnAvailableEndpoint @Bean public MyEndpointWebExtension myEndpointWebExtension() { ... } }
In the sample above, MyEndpointWebExtension
will be created if the endpoint is
available as defined by the rules above. MyEndpointWebExtension
must be a
regular extension that refers to an endpoint, something like:
@EndpointWebExtension(endpoint = MyEndpoint.class) public class MyEndpointWebExtension { }
Alternatively, the target endpoint can be manually specified for components that should only be created when a given endpoint is available:
@Configuration public class MyConfiguration { @ConditionalOnAvailableEndpoint(endpoint = MyEndpoint.class) @Bean public MyComponent myComponent() { ... } }
Endpoint
public abstract Class<?> endpoint
@Bean
method is either an @Endpoint
or an
@EndpointExtension
.Copyright © 2019 Pivotal Software, Inc.. All rights reserved.