是否可以在不使用組件掃描的情況下使用@Autowired
批註自動調用豆豆?在不使用組件掃描的情況下,春季的Autowire註釋
4
A
回答
3
是的。 <context-component-scan .. />
負責發現與@Component
,@Controller
,@Service
,@Respository
註解豆類等
爲了有處理註釋(@Autowired
,@Resource
等),你需要<context:annotation-config />
。因此註釋在applicationContext.xml
中列出的bean上處理。
據我所知,<context-component-scan .. />
自動激活<context:annotation-config />
。
這對2.5和3.0春天都是如此。 (謝謝skaffman)
0
我從來沒有嘗試過沒有啓用組件掃描,但是我可以證實@Autowire註解在Spring 3.0.x中工作,即使是通過XML定義的bean也是如此。
@Bozho好(+1)看看這個問題:http://stackoverflow.com/questions/2458769/how-to-create-commandlink-programmatically – 2010-03-17 04:06:35
(+1)是的,這仍然是這種情況在3.0 – skaffman 2010-03-17 07:27:21
我使用的是Spring 3.1,而自動裝配僅適用於 。事實上,我不需要 來激活bean中的自動裝配 –
2012-05-03 05:49:58