软件编程
位置:首页>> 软件编程>> java编程>> Spring如何使用xml创建bean对象

Spring如何使用xml创建bean对象

作者:jock_javaEE  发布时间:2023-10-24 08:53:56 

标签:spring,xml,bean

一、导入JAR包

Spring如何使用xml创建bean对象

二、配置applicationContext.xml的spring核心配置

Spring如何使用xml创建bean对象

三、


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);
}

来源:https://www.cnblogs.com/jock766/p/13290705.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com