I would like to provide a standard bean custom jar. Only if the user implements a specific class abstract, the default bean injection should be skipped.
The following setup works fine, except for one thing: any classes introduced in a wired class default null! What can I lose?
@Configration
public class AppConfig {
@Bean
@Conditional(MissingServiceBean.class)
public MyService myService() {
return new MyService() {};
}
}
@Component
public abstract class MyService {
@Autowired
private SomeOtherService other;
public void run() {
System.out.println(other);
}
}
public class MissingServiceBean implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return context.getBeanFactory().getBeansOfType(MyService.class).isEmpty();
}
}
A MyServicebean is created and can also be entered. But the contained classes are null.
If I delete the annotation @Conditioanl, everything works as expected.
source
share