【Spring】——环境搭建


    1.spring的依赖包配置

     选择window下的preferences,找到java下的Build Path,打开User Libraries,使用其中的“New”新建,如下图所示步骤:



    创建成功后,选中所新创建的libraries,通过“Add JARs...”添加jar包,全部添加完成后直接“OK”即可。


    2.将applicationContext.xml文件拷贝到src下

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
	     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	     xmlns:aop="http://www.springframework.org/schema/aop"
	     xmlns:tx="http://www.springframework.org/schema/tx"
	     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
  
</beans>

    如果程序猿你的MyEclipse不会智能提示,这绝对是不能容忍的,怎样对其进行相应的设置呢?

    继续选择window下的preferences,找到MyEclipse—>Files and Editors—>XML—>XML Catalog,随意选中其中一项,添加“Add...”:



    在File System中选择你的spring-beans-2.0.xsd文件

     Location中为spring-beans-2.0.xsd文件所在目录

     Key type:下拉框中选择Schema location

     Key:将Location中文件名(仅仅是文件名)复制,在Key已有的内容后加左斜杠“/”,将文件名粘贴到其后面;如图



    接下来,程序猿们就可以痛快的使用MyEclipse搬代码啦!


    3.提供log4j.prorperties配置文件

    引入到项目中即可,附加下载地址:http://download.csdn.net/download/E_wsq/367614


    4.在UserManager中提供构造函数,让spring将userDao实现注入(DI)过来


    5.spring管理对象的创建和依赖,将依赖关系配置到spring的核心配置文件中

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
	     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	     xmlns:aop="http://www.springframework.org/schema/aop"
	     xmlns:tx="http://www.springframework.org/schema/tx"
	     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
  
  <bean id="userDao4Mysql" class="com.bjpowernode.spring.dao.UserDao4MySqlImpl"/>
  
  <bean id="usrDao4Oracle" class="com.bjpowernode.spring.dao.UserDao4OracleImpl"/>
  
  <bean id="userManager" class="com.bjpowernode.spring.manager.UserManagerImpl">
   	<constructor-arg ref="userDao4Mysql"/>
  </bean>
</beans>




评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值