目錄
:用註解來向Spring容器註冊Bean。需要在applicationContext.xml中註冊:
<context:component-scan base-package=”pagkage1[,pagkage2,…,pagkageN]”/>
(1)Spring IOC常用註解的解釋
代碼參考:
https://blog.csdn.net/weixin_40391011/article/details/104191033
https://www.cnblogs.com/hoobey/p/6961410.html
視頻參考:https://www.bilibili.com/video/BV1mE411X7yp?p=104
(2)IOC案例(基於XML和基於註解的案例)
代碼參考:
基本(xml和註解兩個案例)案例:https://blog.csdn.net/friendA3103/article/details/104983388
含有事務案例:https://blog.csdn.net/qq_45147812/article/details/105204662
視頻參考:https://www.bilibili.com/video/BV1mE411X7yp?p=110
(3)Spring中@Configuration註解的使用
上述(2)中基於註解開發的IOC案例中,還需要XML配置註解掃描包和數據源,因此在XML配置中待改造的問題:
<context:component-scan base-package=“com.cn”/>掃描包
數據源以及QueryRunner的配置都需要進行配置,離不開bean.xml配置文件
代碼參考:https://blog.csdn.net/friendA3103/article/details/104989108
視頻參考:https://www.bilibili.com/video/BV1mE411X7yp?p=114
實際開發中使用XML和註解的原則:
自己寫的controller、service及dao使用註解的方式實現,第三方的類使用XML配置實現,如及QueryRunner及DataSource等