文章詳情頁
Spring如何使用xml創建bean對象
瀏覽:63日期: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.根據 bean 的 id 獲取對象 IAccountService aService = (IAccountService) ac.getBean('accountService'); System.out.println(aService); IAccountDao aDao = (IAccountDao) ac.getBean('accountDao'); System.out.println(aDao); }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。
標簽:
Spring
相關文章:
排行榜