我有这个春天的配置:
<bean id="boo" class="com.x.TheClass"/>
该类TheClass实现TheInterface。然后,我有以下(假设的)Java代码:
TheClass
TheInterface
@Autowired TheInterface x; @Autowired TheClass y;
自动布线TheInterface工作,但自动布线TheClass失败。春天给我NoSuchBeanDefinitionException上课了。
NoSuchBeanDefinitionException
为什么可以连接接口而不是类?
通常,两者都可以使用,你可以自动装配接口或类。
你的上下文中某处可能有boo一个自动代理生成器,它将你的bean 包装在一个生成的代理对象中。此代理对象将实现TheInterface,但不是TheClass。使用自动代理时,你需要对接口进行编程,而不是对实现进行编程。
boo
可能的候选对象是事务代理-你是在使用Spring事务,还是使用AspectJ或@Transactional?
@Transactional