[原]搭建与测试Spring的开发环境
搭建与测试Spring的开发环境
1. 导入类库
distspring.jar
libjakarta-commonscommons-logging.jar
如果使用了切面编程AOP 还需要导入如下:
libaspectj
aspectjrt.jar
aspectjweaver.jar
如果使用了jsr-250中的注解,如@Resource/@Postconstruct/@PreDestroy,还需要下列jar文件:
libj2eecommon-annotations.jar
2. Beans.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <bean id="personService" class="cn.kevin.service.impl.PersonServiceBean"></bean> </beans> |
3. PersonService.java
package cn.kevin.service;
public interface PersonService {
public abstract void save();
} |
4. PersonServiceBean.java
package cn.kevin.service.impl;
import cn.kevin.service.PersonService;
public class PersonServiceBean implements PersonService { public void save(){ System.out.println("我是save方法.."); } } |
5. Test.java
@Test public void test(){ ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); PersonService personSerivce = (PersonService)ctx.getBean("personService"); personSerivce.save(); } |