Spring环境的搭建与测试 (spring2.5.6)

来源:互联网 发布:c语言解惑 微盘 编辑:程序博客网 时间:2024/05/29 07:47

这里是采用的视频里面的spring版本

 

下载spring2.5.6, 然后进行解压缩,在解压目录中找到下面jar文件,拷贝到类路径下

dist\spring.jar

lib\jakarta-commons\commons-logging.jar

上边两个是基本的jar包。。

 

如果使用了切面编程(AOP),还需要下列jar文件

lib/aspectj/aspectjweaver.jar和aspectjrt.jar

lib/cglib/cglib-nodep-2.1_3.jar

 

如果使用了JSR-250中的注解,如@Resource/@PostConstruct/@PreDestroy,还需要下列jar文件

lib\j2ee\common-annotations.jar

 

1:  建立java工程,导入外部包

dist\spring.jar

lib\jakarta-commons\commons-logging.jar

2:写spring的配置模板

1
2
3
4
5
6
7
<?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">
     
</beans>

  

3: 建立测试类,Junit类。

4:在beans.xml中配置bean的信息:

1
<bean id="personService"class="cn.gbx.serviceimpl.PersonServiceImpl"></bean>

5: 在Junit类中写测试方法,运行观察

1
2
3
4
5
6
7
8
9
public class SpringTest {
    @Test
    publicvoid instanceSpring() {
        ApplicationContext ctx =new ClassPathXmlApplicationContext("beans.xml");
        PersonService ps = (PersonService)ctx.getBean("personService");
        ps.save();
    }
 
}
0 0
原创粉丝点击