Sring自動注入Bean

最近新看到自動注入Bean,翻起以前的項目看了下。

以前我們使用註解的的配置

<context:component-scan base-package=”XX.XX”/>

這種需要使用繁瑣的註解。

自動註解配置:

  <!-- 使用annotation 自動註冊bean, 並保證@Required、@Autowired的屬性被注入 -->
	<context:component-scan base-package="com.zucp.ciap">
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
		<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
	</context:component-scan>

這樣每個Bead就不必都去寫繁瑣的註解。

context:exclude-filter標籤的含義是:排除掃描到的所有類,不納入Spring容器中。


發佈了26 篇原創文章 · 獲贊 14 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章