spring环境搭建测试

package junit.test;

import static org.junit.Assert.*;

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

import businessbeans.PersonService;

public class SpringTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Test
public void instanceSpring(){
   //实例化spring容器
   ApplicationContext ctx =new ClassPathXmlApplicationContext("beans.xml");
   //从已经实例化的容器中获得交给容器管理的类
   PersonService personService=(PersonService)ctx.getBean("personServiceBean");
   //调用接口的方法
   personService.save();
}
}

PS:在spring的开发应用时建议使用的是面向接口编程,对方法最好抽取出相应的接口。接口和实现类最好放在不同的包中。

posted on 2010-08-17 09:13  基斯盐  阅读(172)  评论(0编辑  收藏  举报

导航