我的项目(Maven项目)包括三个模块:sr-web,sr-domain和sr-dao,就像这样:
SR ---- | ---- SR-域 | ---- SR-道 | ---- SR-网络
在域模块中,我定义了我的实体,在dao模块中,我定义了扩展org.springframework.data.repository.PagingAndSortingRepository
的相关DAO接口
和
org.springframework.data.jpa.repository.JpaSpecificationExecutor
但是当我在sr-web模块的applicationContext.xml中定义Dao bean时,我得到了异常:
UnsatisfiedDependencyException: Error creating bean with name 'accountService': Unsatisfied dependency expressed through method 'setUserDao' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'edu.whu.irlab.scholarreader.dao.repository.UserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:671)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:370)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 77 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'edu.whu.irlab.scholarreader.dao.repository.UserDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1466)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1097)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1059)
在sr-web模块中,我的applicationContext.xml是这样的:
<bean id="authorDao" class="edu.whu.irlab.scholarreader.dao.repository.AuthorDao" abstract="true"/>
<bean id="journalDao" class="edu.whu.irlab.scholarreader.dao.repository.JournalDao" abstract="true"/>
<bean id="keywordDao" class="edu.whu.irlab.scholarreader.dao.repository.KeywordDao" abstract="true"/>
<bean id="paperDao" class="edu.whu.irlab.scholarreader.dao.repository.PaperDao" abstract="true"/>
<bean id="referenceDao" class="edu.whu.irlab.scholarreader.dao.repository.ReferenceDao" abstract="true"/>
<bean id="taskDao" class="edu.whu.irlab.scholarreader.dao.repository.TaskDao" abstract="true"/>
<bean id="userDao" class="edu.whu.irlab.scholarreader.dao.repository.UserDao" abstract="true"/>
然后如何在sr-web模块中定义我的Dao bean?