I defined a class with annotation Configuration
@Configuration
@AutoConfigureAfter(EndpointAutoConfiguration.class)
public class EndpointConfiguration {
@Resource
private MetricsEndpoint metricsEndpoint;
@Bean
public MetricsFormatEndpoint metricsFormatEndpoint() {
return new MetricsFormatEndpoint(metricsEndpoint);
}
}
the MetricsFormatEndpoint works well.
but I use the annotation conditionalOnBean, it doesn't work at all.
@Bean
@ConditionalOnBean(MetricsEndpoint.class)
public MetricsFormatEndpoint metricsFormatEndpoint() {
return new MetricsFormatEndpoint(metricsEndpoint);
}
see the localhost:8080/beans,the spring applicationContext has the bean 'metricsEndpoint',
{"bean":"metricsEndpoint","scope":"singleton",
"type":"org.springframework.boot.actuate.endpoint.MetricsEndpoint",
"resource":"class path resource
[org/springframework/boot/actuate/autoconfigure/EndpointAutoConfiguration.class]",
"dependencies":[]}
I read the document of the annotation @ConditionalOnBean, it says The class type of bean that should be checked. The condition matches when any of the classes specified is contained in the {@link ApplicationContext}.
who can tell me why