Sruts2.1+JPA(Hibernate3.0)+Spring2.5整合详解

4 篇文章 0 订阅
2 篇文章 0 订阅

第一步、新建一个Web项目:SSJ


************************配置Spring************************************

第二步、选择项目SSJ然后右击选择Add Spring capabilities----》进入到Add Spring capabilities页面中,去掉MyEclipse Libraries 勾选User Libraries选项,然后单击下一步




第三步、默认选项,然后单击Finish:



**************************Spring配置完成后代码结构如下:*****************************


************************************配置JPA*************************************

第四步、选择项目SSJ然后右击选择Add JPA capabilities----》进入到Add JPA  capabilities页面中,Persistence provider选择Hibernate,去掉MyEclipse Libraries 勾选User Libraries选项,然后单击下一步



第五步、配置dataSource:



第六步、配置Spring-jpa支持,然后单击完成:

******************配置JPA后的代码结构,你会看见在SRC目录下多了一个META-INF文件文件中有个persistence.xml****************************


第七步、当配置好JPA后你会发现applicationContext.xml中有错误,那是因为我们还没有把相应的jar包给导入进来,先别等把Struts配置好了后,再把响应的jar包给导入进来:

*************************************配置Struts*********************

第八步、选择项目SSJ然后右击选择Add Struts capabilities----》进入到Add Struts  capabilities页面中,选择struts的版本以及URL Pattern ,单击下一步





第九步、选择类库到项目路径中,去掉MyEclipse Libraries 勾选User Libraries选项,然后单击Finish



*******************Struts配置好之后的代码结构***************************


第十步、填加JAR包到项目路径中来所需jar包如下:

第十一步、当把这些jar包放入项目中来后那Application.xml还是要报错,那么怎么办把下面的代码覆盖原有的代码,然后进行刷新就OK:

<?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:context="http://www.springframework.org/schema/context"
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.5.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

第十二步、配置web.xml:
在web.xml中加入以下代码:



<!-- 指定Spring的配置文件,指定在类路径下去需找  -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>


<!-- 对spring容器进行实例化   -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值