2013-05-14 37 views
1

我配置春豆使用參考「自動檢測」在Spring上下文

<context:component-scan base-package="com.mycomp.app" /> 
<tx:annotation-driven />. 

@Repository("transactionDao") 
public class TransactionDao { 
... 
} 

現在我手動配置在上下文中的另一個Bean上引用此一個自動檢測一些DAOS。

<property name="schedulerContextAsMap"> 
    <map> 
     <entry key="transactionDao" value-ref="transactionDao" /> 
    </map> 
</property> 

現在Spring的抱怨:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionDao' is defined 

是否有可能引用自動檢測上下文中豆?

回答

0
Is it possible to reference auto detected bean inside context? 

是的,這是非常可能的。

爲了看看爲什麼沒有被發現transactionDao豆,你可以驗證以下的事情:

  1. TransactionDao應該在類路徑和位於com.mycomp.app的一些子包

  2. 如果Step-1已經存在,運行Logger級別爲org.springframework的應用程序設置爲DEBUG,您可以在spring的啓動日誌中看到所有bean已初始化的日誌。