日期:2014-05-17  浏览次数:20724 次

spring xml中定义的bean如何使用注解定义的bean
假设我再xml中定义一个bean:Test1,我又有另一个bean:Test2,(通过注解定义如@service),我现在想在Test1中拿到Test2,但是现在报Test2未定义,注入不进Test1.我该怎么解决

------解决方案--------------------
在你applicationContext.xml 里面加上

<beans 
//...
xmlns:context="http://www.springframework.org/schema/context"
//...
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd">
//...
 
<context:annotation-config />
//...
</beans>
------解决方案--------------------
<property name="mappingDirectoryLocations">
<list>
<value>classpath:com/bbs/entity</value>
</list>
</property>

要配置这个