您的位置:首页 > 编程语言 > Java开发

Spring 容器初始化方法

2015-10-14 22:37 501 查看
Resource resource = new ClassPathResource("/bean.xml");
resource = new FileSystemResource("d:/tzspring02/src/bean.xml");
XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);

/*spring容器加载资源文件的核心类 PathMatchingResourcePatternResolver*/
ResourcePatternResolver resourceLoader = new PathMatchingResourcePatternResolver();
Resource resource = resourceLoader.getResource("classpath:bean.xml");//ClassPathResource
System.out.println(resource.getDescription()+"===="+resource.getFile().getAbsolutePath());
XmlBeanFactory xmlBeanFactory = new XmlBeanFactory(resource);

System.out.println("########1");
ApplicationContext application1 = new ClassPathXmlApplicationContext("classpath:/com/easeye/conf/applicationContext.xml");
Student stu1 = application1.getBean("student",Student.class);
stu1.ShowInfo();

System.out.println("########2");
ApplicationContext application2 = new FileSystemXmlApplicationContext("file:D:/Software/apache-tomcat-7.0.59/webapps/SpringDemo/WEB-INF/classes/com/easeye/conf/applicationContext.xml");
Student stu2 = application2.getBean("student",Student.class);
stu2.ShowInfo();

System.out.println("########3");
ApplicationContext application3 = new AnnotationConfigApplicationContext("com.easeye.test");
Student stu3 = application3.getBean("student",Student.class);
stu2.ShowInfo();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: