文章詳情頁
Spring如何使用xml創(chuàng)建bean對象
瀏覽:54日期:2023-08-22 16:07:14
一、導入JAR包
二、配置applicationContext.xml的spring核心配置
三、
public static void main(String[] args) { //1.使用 ApplicationContext 接口,就是在獲取 spring 容器 ApplicationContext ac = new ClassPathXmlApplicationContext('bean.xml'); //2.根據(jù) bean 的 id 獲取對象 IAccountService aService = (IAccountService) ac.getBean('accountService'); System.out.println(aService); IAccountDao aDao = (IAccountDao) ac.getBean('accountDao'); System.out.println(aDao); }
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
標簽:
Spring
相關(guān)文章:
1. 每日六道java新手入門面試題,通往自由的道路--多線程2. ASP.NET MVC視圖頁使用jQuery傳遞異步數(shù)據(jù)的幾種方式詳解3. SpringBoot+SpringCache實現(xiàn)兩級緩存(Redis+Caffeine)4. php讀取xml中某個元素的內(nèi)容(PHP5以上才支持)5. ASP.NET泛型三之使用協(xié)變和逆變實現(xiàn)類型轉(zhuǎn)換6. Idea 2019.3 本應該搜索到的插件卻搜索不到的解決方法7. 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法8. 快速解決ajax返回值給外部函數(shù)的問題9. 每日六道java新手入門面試題,通往自由的道路10. IntelliJ IDEA導入jar包的方法
排行榜
