首页>代码>spring框架IoC入门案例>/com.spring.test/src/main/java/com/yyc/a_ioc/Test.java
package com.yyc.a_ioc;

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

public class Test {

	@org.junit.Test
	public void demo(){
		//之前开发
		UserService user = new UserServiceImpl();
		user.addUser();
	}
	
	@org.junit.Test
	public void demo1(){
		//从spring容器中获得
		//1.获得容器
		String xmlPath = "com/yyc/a_ioc/applicationContext_ioc.xml";
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
		//2.获得内容
		UserService user = (UserService) applicationContext.getBean("userSreviceId");
		user.addUser();
	}
}
最近下载更多
yjk1999  LV10 2020年10月11日
pt11100  LV9 2020年7月3日
cz206616  LV10 2020年6月2日
liuwenlong  LV20 2019年12月20日
Silence丶二哈  LV13 2019年4月12日
Devin123  LV5 2018年9月13日
15290653871  LV4 2018年7月8日
1792312911  LV17 2018年6月26日
dagf113225  LV68 2018年1月22日
最代码官方  LV167 2018年1月22日
最近浏览更多
微信网友_6602457430806528  LV6 2023年8月12日
fuyouou  LV5 2023年7月7日
xuthus  LV1 2023年6月29日
微信网友_6465435620184064  LV6 2023年5月19日
guviva  LV6 2023年3月14日
我睡觉时不困  LV7 2022年11月6日
qwertyuiopzxc  LV1 2022年10月14日
梁笑珊  LV4 2022年5月13日
快来救救胡桃  LV6 2022年1月6日
jwfadacai  LV8 2022年1月2日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友