最近新看到自動注入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容器中。