Spring如何使用xml建立bean物件
阿新 • • 發佈:2020-08-10
一、匯入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); }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。