一.简单案例 打印hello spring
1.导包
org.springframework spring-beans 4.2.3.RELEASE org.springframework spring-context 4.2.2.RELEASE
2.创建HappyService类
public class HappyService { private String info; public void work(){ System.out.println("Hello "+info); } public String getInfo() { return info; } public void setInfo(String info) { this.info = info; }}
3.创建applicationContext.xml文件
4.测试类
@Test public void test01(){ ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml"); HappyService service=(HappyService)ac.getBean("HappyService"); service.work(); }