Java Spring@Conditional context未从beanFactory提供bean
我有这样的设置:Java Spring@Conditional context未从beanFactory提供bean,java,spring,Java,Spring,我有这样的设置: @Configuration class DBConfig{ @Bean(name="dbTemplate") public JdbcTemplate template(){ return new JdbcTemplate() } } @Service @Conditional(value=MyCondition.class) class ABC{ } class MyCondition implements Condition{ @Override pub
@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 not found异常发生冲突,即使该bean可用。请解释为什么会这样