首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Spring 注脚 方式配制的小demo

2012-08-24 
Spring 注解 方式配制的小demo1、新建一个Web程序在程序中引入Spring所需要的jar包,我以前有弄好的包,包含

Spring 注解 方式配制的小demo
1、新建一个Web程序
   在程序中引入Spring所需要的jar包,我以前有弄好的包,包含了以下几个jar包

2、在src下新建Person.java的实例bean.



6 junit进行测试
package junit.test;import org.junit.AfterClass;import org.junit.BeforeClass;import org.junit.Test;import org.springframework.context.support.AbstractApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import cn.ehoo.bean.Person;import cn.ehoo.service.PersonService;/** *@author whp *@Email whp@ehoo.cn *@Dec 30, 2010 * */public class SpringTest {public static PersonService personService;@BeforeClasspublic static void setUpBeforeClass() throws Exception {AbstractApplicationContext cxt = new ClassPathXmlApplicationContext("beans.xml");personService =(PersonService)cxt.getBean("personServiceBean");}@Testpublic void save(){Person person = new Person();personService.save(person);}public static void main(String[] args) {try {setUpBeforeClass();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}/** *@author whp *@Email whp@ehoo.cn *@Dec 30, 2010 * */@AfterClasspublic static void tearDownAfterClass() throws Exception {}}







热点排行