Spring Conditionals with optional Maven scope

I have a library which has a @Configuration with the following Bean:

@Bean

@ConditionalOnClass(HealthEndpoint.class)

@ConditionalOnEnabledEndpoint(endpoint = HealthEndpoint.class)

@ConditionalOnProperty(prefix = "custom.health", name = "enabled", havingValue = "true", matchIfMissing = true)

public CustomBean healthBean(final HealthEndpoint healthEndpoint) {

return new CustomBean(healthEndpoint);

}

I want the bean to be declared only if the health actuator endpoint is available and enabled. My pom.xml defines the following optional dependency for the actuator:



org.springframework.boot

spring-boot-starter-actuator

true



Then, I use this library in another project which does not use actuator. This bean should not be declared, but I am getting the following exception:

...

Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/actuate/health/HealthEndpoint

at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_152]

at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)...

Read More »

By: StackOverFlow - 7 days ago

Related Posts