2011-03-07 38 views
0

我有一個用@Service註釋的UserDetailsS​​ervice類。我也有DAO類的annonated自動裝配,並在我的控制器內正常工作。Spring Component被掃描的bean無法訪問

問題是當我想在我的security-context.xml中連接UserDetailsS​​ervice bean時。 Spring無法找到該bean。是否因爲我的組件掃描位於我的controllers.xml文件中並超出了我的安全配置範圍?

XML配置文件佈局像這樣:

的web.xml:

<context-param> 
    <param-name>contextConfigLocation</param-name> 
     <param-value> 
       /WEB-INF/spring/root-context.xml 
       /WEB-INF/spring/appServlet/security-context.xml 
     </param-value> 
</context-param> 

的servlet-context.xml中:

... 
<beans:import resource="controllers.xml" /> 
... 
+0

另請參閱http://stackoverflow.com/questions/4333390/service-are-constructed-twice/4335438#4335438 – axtavt 2011-03-07 16:53:20

回答

3

是的,你需要添加的組件掃描對於這兩種情況來說,只用一種方法來做是不夠的。