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

这里是采用的视频里面的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
     public void instanceSpring() {
         ApplicationContext ctx = new ClassPathXmlApplicationContext( "beans.xml" );
         PersonService ps = (PersonService)ctx.getBean( "personService" );
         ps.save();
     }
 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值