我對這個問題感到絕望。我一直在四處尋找了近一個星期找我異常的解決方案:我一直在尋找在這個論壇上,並在網站上給出的許多可能的原因庫存:http://www.baeldung.com/spring-nosuchbeandefinitionexception彈簧配置設置:找不到符合條件的類型[]的依賴關係的
似乎沒有任何配合我的配置。 我必須錯過一些東西。
源的例外是:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [fr.bnp.paiement.persistence.api.idaos.IDaoCompte] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1326)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1072)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:967)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)
... 15 more
如果,而不是該掃描我明確給予在Spring配置我得到相同的異常bean的位置。
我想知道這是因爲我的模塊,我的Maven項目的depency鏈的不是:
Services --> ServicesAPI
Services --> PersistenceAPI
Persistence --> PersistenceAPI
但我想一個持久性的bean注入到一個服務之一。如果服務不依賴於持久性,但在PersistenceAPI上有問題,那麼這是一個問題嗎? 彈簧配置xml文件遵循相同的導入鏈。
Services imports ServicesAPI
Services imports PersistenceAPI
Persistence imports PersistenceAPI
服務模塊如何查看Persistence模塊中的bean?也許通過PersistenceAPI(這是我注入的持久性類型)? 使用EJB這個依賴鏈可以正常工作(可能是因爲沒有xml導入)。
我嘗試直接從服務導入持久性,但如果我不更改依賴關係鏈它不起作用:它只是找不到xml文件。 如果我不打擾拆分API和實現,那麼一切都會很好地工作,但這就是我想要實現的。
我正在嘗試設置一個乾淨的Maven多模塊項目。 代碼在這裏:https://github.com/ASolidGrasp/springTest.git 先決條件,使其工作原理:安裝MySQL。
在WSBanqueServices模塊中運行fr.bnp.paiement.service.test.Main.main()時發生錯誤。
對於那些誰喜歡看這裏的代碼:
在WSBanqueServices模塊\ fr.bnp.paiement.service.test包
public class Main
{
public static void main(String[] args)
{
BeanFactory bF = new ClassPathXmlApplicationContext("classpath:springServices.xml");
IServiceClient iServiceClient = (IServiceClient) bF.getBean("serviceClient");
}
}
在WSBanqueServices模塊\ fr.bnp.paiement.service .ServiceClient
@Service
@Transactional
public class ServiceClient implements IServiceClient {
@Inject
private IDaoCompte iDaoCompte;
@Inject
private IDaoCarte iDaoCarte;
...
在WSBanqueServices模塊\ SRC /主/資源/ springServices.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
">
<import resource="classpath:springServicesAPI.xml" />
<import resource="classpath:springPersistenceAPI.xml" />
<aop:aspectj-autoproxy />
<context:component-scan base-package="fr.bnp.paiement.service" />
</beans>
在WSBanqueServicesAPI模塊\ SRC /主/資源/ springServicesAPI.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
">
<import resource="classpath:springEntities.xml" />
<import resource="classpath:springServicesExceptions.xml" />
<tx:annotation-driven transaction-manager="txManager" />
<aop:aspectj-autoproxy />
<context:component-scan base-package="fr.bnp.paiement.service.api.iservice" />
</beans>
在WSBanquePersistenceAPI模塊\ SRC /主/資源/ springPersistenceAPI。XML
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
">
<import resource="classpath:springEntities.xml" />
<import resource="classpath:springPersistenceExceptions.xml" />
<tx:annotation-driven transaction-manager="txManager" />
<aop:aspectj-autoproxy />
<context:component-scan base-package="fr.bnp.paiement.persistence.api.idaos" />
</beans>
在WSBanquePersistence模量\ SRC /主/資源/ springPersistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
">
<import resource="classpath:springPersistenceAPI.xml" />
<aop:aspectj-autoproxy />
<...datasource & co + transactional + persistenceContext...>
<bean
name="daoCarte"
class="fr.bnp.paiement.persistence.daos.DaoCarte" />
<bean
name="daoCompte"
class="fr.bnp.paiement.persistence.daos.DaoCompte" />
<context:component-scan base-package="fr.bnp.paiement.persistence.daos" />
</beans>
在WSBanquePersistence模量\ fr.bnp.paiement.persistence.daos.DaoCarte
@Transactional
@Repository("daoCarte")
public class DaoCarte implements IDaoCarte
{...}
在WSBanquePersistence模塊\ fr.bnp.paiement.persistence.daos.DaoCompte
@Repository("daoCompte")
@Transactional
public class DaoCompte implements IDaoCompte
{...}
預先感謝您的幫助。
如果不張貼相關的代碼,也沒有與異常的堆棧跟蹤確切的錯誤信息,我們將不可靠的幫助。 –
我想代碼太長閱讀,它可以更好地給鏈接到我的這個項目的github回購。你真的喜歡在這裏有代碼?感謝您對我的問題的關注。 **下代碼 –
**必須在問題。這是這裏的規則。要知道什麼是下的代碼,通過發佈異常的全面和詳細的堆棧跟蹤至少啓動。 –