Hello Spring(5)ApplicationContext

Tester.java

复制代码
 1 package test;
 2 
 3 import org.springframework.context.ApplicationContext;
 4 import org.springframework.context.support.ClassPathXmlApplicationContext;
 5 import user.Dao;
 6 
 7 public class Tester {
 8     
 9     public static void main( String[] args){
10         
11         /*Resource r = new ClassPathResource("beans.xml");
12         BeanFactory factory = new XmlBeanFactory(r);*/
13         
14         @SuppressWarnings("resource")
15         ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
16         
17         user.Dao dao = (Dao) context.getBean("userDao");
18         dao.register( new user.Bean());
19         
20     }
21 
22 }
复制代码

换成这种写法需要增加两个 jar 包:

spring-beans-3.2.2.RELEASE.jar

spring-context-3.2.2.RELEASE.jar

这个方法常用。

posted on   Livon  阅读(186)  评论(0编辑  收藏  举报

努力加载评论中...

导航

点击右上角即可分享
微信分享提示