spring基于xml创建bean对象

时间:2020-07-13 00:38:08   收藏:0   阅读:103

一、导入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);  
  }

原文:https://www.cnblogs.com/jock766/p/13290705.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!