I tried an autowire bean for the test class using @Autowire , however the bean is not connected, and I get this exception:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.abc.MyDaoHibernateImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
My test class is as follows:
package com.abc; @ContextConfiguration(locations = { "classpath:applicationContext.xml" }) @TransactionConfiguration(transactionManager = "hibernateTransactionManager") public class MyDaoHibernateImplTest extends AbstractTransactionalJUnit4SpringContextTests { @Autowired private MyDaoHibernateImpl myDao; .... }
The applicationContext.xml file has this bean definition:
<bean id="myDao" class="com.abc.MyDaoHibernateImpl"> <property name="sessionFactory" ref="hibernateSessionFactory" /> </bean>
Can anyone see where I'm wrong?
Thanks in advance for any suggestions.
- james
java spring dependency-injection autowired
James adams
source share