struts2.0 spring2.5 hibernate3.3整合

struts2.0 spring2.5 hibernate3.3整合
一、整合jar包
首先下载3个框架
struts2.0 下载地址 http://apache.freelamp.com/struts/binaries/struts-2.0.14-all.zip
spring2.5 下载地址 http://s3.amazonaws.com/dist.springframework.org/release/SPR/spring-framework-2.5.6.SEC01-with-dependencies.zip
hibernate3.3 下载地址 http://downloads.sourceforge.net/project/hibernate/hibernate3/3.3.2.GA/hibernate-distribution-3.3.2.GA-dist.zip



Struts 部分:

struts/lib下 找出以下5个jar文件 它们是使用struts2必须的jar文件
commons-logging-1.0.4.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.11.1.jar
xwork-2.0.4.jar

Spring部分:

再找出 struts2-spring-plugin-2.0.14.jar 它是struts2与spring整合必须的jar文件

spring/dist下
spring.jar

日志部分:
spring/lib/log4j
log4j-1.2.15.jar

Hibernate部分:
spring/lib/aspectj下 在spring中使用aspectj 必须的jar包
aspectjrt.jar
aspectjweaver.jar

hibernate/hibernate3.jar
hibernate/lib/required 下 所有jar文件它们是使用hibernate必须的jar文件
注意其中有slf4j-api-1.5.8.jar 文件 它只是一个规范
我们需要下载它对log4j实现的jar文件
下载地址 http://www.slf4j.org/dist/slf4j-1.5.2.zip
找出其中有一个slf4j-log4j12-1.5.2.jar

以上一共18个jar文件


二、修改配置文件
web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-*.xml</param-value>
</context-param>

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>


<filter>
<filter-name>Spring character encoding filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring character encoding filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

hibernate.cfg.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="format_sql">false</property>
<property name="show_sql">true</property>
<property name="connection.driver_class">
org.gjt.mm.mysql.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/s2sh
</property>
<property name="connection.username">root</property>
<property name="connection.password">password</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="hbm2ddl.auto">none</property>
<mapping resource="com/illu/pojo/User.hbm.xml" />
</session-factory>
</hibernate-configuration>


applicationContext.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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>

<!-- 配置事务管理器 -->

<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

<!-- 配置事物传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>

<!-- 哪些类的哪些方法参与事物, (* com.evan.crm.service.*.*(..))中几个通配符的含义:
第一个 * —— 通配 任意返回值类型
第二个 * —— 通配 包com.evan.crm.service下的任意class
第三个 * —— 通配 包com.evan.crm.service下的任意class的任意方法
第四个 .. —— 通配 方法可以有0个或多个参数
综上:包com.evan.crm.service下的任意class的具有任意返回值类型、任意数目参数和任意名称的方法-->
<aop:config>
<aop:pointcut id="allManagerMethod"
expression_r_r_r="execution(* com.struts2.service.*.*(..))" />
<aop:advisor pointcut-ref="allManagerMethod"
advice-ref="txAdvice" />
</aop:config>
</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值