I have an existing spring application using xml configuration.
Now, I will be using spring-data-mongodb to connect it to a Mongo database.
My repository/dao are all interfaces like:
public interface CustomerDao extends MongoRepository<Customer, String> {
...
}
and inside my service class CustomerService it autowires CustomerDao interface.
<bean id="customerDao" class="com.myapp.repository.CustomerDao" />
<bean id="customerService" class="com.myapp.service.CustomerService">
<property name="customerDao" ref="customerDao"/>
</bean>
but since CustomerDao is an interface, I am always getting the error:
org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.myapp.repository.CustomerDao]: Specified class is an interface
Based on the tutorials for spring-data-mongodb repositories are mostly interfaces extending to MongoRepository.
My problem is that, I am getting error when autowiring CustomerDao inside CustomerService class if I will not create a bean entry in the xml configuration. Below is the error I am getting:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.myapp.repository.CustomerDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=customerDao)}