Having the next situation:
@ConditionalOnBean(ServiceD.class)
@Component
class ServiceAImpl implements ServiceA {
private ServiceB serviceB;
private ServiceC serviceC;
private ServiceD serviceD;
public ServiceA(ServiceB serviceB, ServiceC serviceC, ServiceD serviceD) {
this.serviceB = serviceB;
this.serviceC = serviceC;
this.serviceD = serviceD;
}
}
interface ServiceD {
void doStuff();
}
@Component
class ServiceDImpl implements ServiceD {
private ServiceE serviceE;
public ServiceD(ServiceE serviceE) {
this.serviceE = serviceE;
}
@Override
public void doStuff() {
//...
}
}
I need serviceA to be loaded only if there exists a serviceD implementation.
From @ConditionalOnBean documentation: "The condition can only match the bean definitions that have been processed by the application context so far and, as such, it is strongly recommended to use this condition on auto-configuration classes only.".
My question is:
As ServiceD is a dependency of ServiceA, will this guarantee that when @ConditionalOnBean is evaluated, ServiceD will be already processed by the application context?
If not, is there any other way to acomplished that without using autoconfiguration classes?