首页>代码>spring IOC控制反转各种方法实例>/SpringIocDemo/src/cn/spring/b_create_obj/App.java
package cn.spring.b_create_obj;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {

	@Test
	public void testApp() {
		// 创建容器对象
//		ApplicationContext ac = new ClassPathXmlApplicationContext("cn/spring/b_create_obj/applicationContext.xml");
		
		
		// 从当前包下面  找applicationContext.xml
		ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml",this.getClass());
	/*	
		String  str  = (String) ac.getBean("str");
		
		System.out.println("-----------"+str);
		*/
		
		User user  = (User) ac.getBean("user");
		
		System.out.println(""+ user);
	}
	
	@Test
	public void testUserFactory() {
		// 创建容器对象
		ApplicationContext ac = new ClassPathXmlApplicationContext("cn/spring/b_create_obj/bean2.xml");
		
		User user  = (User) ac.getBean("user");
		
//		user.toString();
//		System.out.println(user.toString());
		
	}
	
}
最近下载更多
liuwenlong  LV20 2019年12月28日
whywhywhy  LV10 2019年8月20日
13734993  LV7 2019年8月7日
苏乐池  LV2 2019年7月22日
1065908163  LV4 2019年6月9日
蚂蚁呀嘿  LV3 2019年5月20日
hellozui  LV10 2019年5月9日
不期而遇则缘  LV9 2019年5月1日
you1234  LV8 2019年3月12日
1529860026  LV24 2019年1月16日
最近浏览更多
小白jmhuang  LV12 2023年5月30日
19878648897  LV1 2022年6月28日
aqin_qin  LV1 2022年6月5日
yuyiyuyi  LV6 2022年3月8日
QQ353251504 2022年2月24日
暂无贡献等级
admin22222  LV2 2022年1月17日
jwfadacai  LV8 2022年1月4日
joelal  LV1 2021年12月27日
444105047  LV6 2021年5月13日
与你同行2019  LV11 2021年2月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友