环境的搭建

 烤包  spring.jar  commons-logging.jar 

写配置文件  application.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" ><!--主要针对这一行-->

<!--

最后一行是在有网的情况下,这样就行了,但是在没有网 的情况下   怎么办了

1:window--myeclipse--file and editors --xm--xml catalog

 2:选择user  specified  entries  点击add  点击file system 选择 spring-beans-2.5.xsd 这个文件

3:将Key Type选为 Schema Location

4:把/spring-beans-2.5.xsd  加到key的后面  点击ok 

 

或者把spring-beans-2.5.xsd  这个文件拷到src下面  把那一行改成文件名就行

->

</bean>

 


 实例化spring容器
  一:在类路径下寻找配置文件来实例化容器 (开发更好)
  ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"beans.xml","beans2.xml"});
  二是:在文件系统路径下寻找配置文件来实例化容器
  ApplicationContext ctx=new FileSystemXmlApplicationContext(new String[]{"d:\\beads.xml"});//路径不是很好
 检验环境配置的正确性
  利用在junit.test包下面写入SpringTest.java,里面的instanceSpring()实例化spring容器来检验
 再写业务bean(com.service.impl.PersonServiceBean),在里面的方法(save())抽出接口(PersonService.java)并放在   com.service下面,

 将业务bean交给spring管理容器<bean id="personService" class="com.service.impl.PersonServiceBean"></bean>
 在Test类中,接口指向实现这个接口的对象实例,调用这个对  象中的方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值