Spring、Hello Spring

1、引入Spring jar包

2、新建一个Person 接口和Person Bean

public interface PersonIService {
	public void helloSpring();
}

import cn.server.PersonIService;

public class PersonServiceImpl implements PersonIService {

	@Override
	public void helloSpring() {
		System.out.println("Hello Spring!");
	}
}

3、将PersonBean在beans.xml中注入:

<bean id="personIService" class="cn.server.impl.PersonServiceImpl" />

4、使用ClassPathXmlApplicationContext 解析beans.xml  并得到PersonBean对象

@Test
	public void test() {
		ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
		PersonIService personIService=(PersonIService)ac.getBean("personIService");
		personIService.helloSpring();
	}



posted @ 2015-11-05 15:12  Bodi  阅读(195)  评论(0编辑  收藏  举报