我有这样的设置:
@Configuration
class DBConfig{
@Bean(name="dbTemplate")
public JdbcTemplate template(){
return new JdbcTemplate()
}
}
@Service
@Conditional(value=MyCondition.class)
class ABC{
}
class MyCondition implements Condition{
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
System.out.println(context.getBeanFactory().getBean("dbTemplate"));
}
}
问题是System.out.println(context.getBeanFactory()。getBean(“dbTemplate”));虽然bean可用,但是在Condition类中发生了一个bean找不到异常。请解释为何如此