I have tried to autowire a bean for a test class using @Autowire
, however the bean is not wired 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 looks like this:
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 going wrong?
Thanks in advance for any suggestions.
--James