1. 程式人生 > >spring xml配置bean和context:component-scan掃描註解註冊bean的區別

spring xml配置bean和context:component-scan掃描註解註冊bean的區別

本文啟動spring容器用的是dubbo的main方法

1.xml配置bean:
2.<context:component-scan>掃描註解註冊bean:


測試猜測結果:
前者啟動spring容器時建立bean,不會掃描到類屬性
後者則會,如下圖:



後者啟動會報錯,因為配置檔案載入順序中,generalDao的bean建立是在application-db.xml中,AlarmDataSchedule該類在application-service.xml,比generalDao提前掃描註冊了