struts2.1.8 + spring2.5.6 + hibernate3.3.2整合

来源:百度文库 编辑:神马文学网 时间:2024/05/01 11:26:06
此次整合的版本是:struts2.1.8 + spring2.5.6 + hibernate3.3.2
一. 整合hibernate和spring
============================================================
hibernate所需要jar包:
编号
jar包名称
所在位置
功能
1
antlr-2.7.6.jar
hibernate/lib/required
解析HQL
2
commons-collections-3.1.jar
hibernate/lib/required
集合框架
3
dom4j-1.6.1.jar
hibernate/lib/required
解析xml
4
javassist-3.9.0.GA.jar
hibernate/lib/required
5
jta-1.1.jar
hibernate/lib/required
hibernate transaction
6
slf4j-api-1.5.8.jar
hibernate/lib/required
Log
7
slf4j- log4j12-1.5.8.jar
slf4j-1.5.8(单独下载,slf4j接口以log4j形式实现)
Log
8
log4j-1.2.15.jar
apache-log4j-1.2.15(单独下载)
Log
9
hibernate3.jar
hibernate
核心包
10
hibernate-annotations.Jar
hibernate-annotations-3.4
注解
11
hibernate-common-annotations.jar
hibernate-annotation-3.4\lib
注解
12
ejb3-persistence.jar
hibernate-annotations-3.4 \lib
@Entity
注解
13
c3p0-0.9.1.jar
hibernate-distribution-3.3 \lib\optional\c3p0
c3p0数据源
slf4j接口以log4j形式实现,
注解可能还需(annotation3.4的包):hibernate-entitymanager.jar、hibernate-validator.jar、 jboss-archive-browsing.jar ,
采用c3p0连接池。
========================================================================
spring所需要jar包:
编号
jar包名称
所在位置
功能
1
Aspectjrt.jar
spring/lib/aspectj
AOP
2
Aspectjweaver.jar
spring/lib/aspectj
AOP
3
cglib-nodep-2.1_3.jar
spring/lib/cglib
代理,二进制增强
4
common-annotations.jar
spring/lib/j2ee
@Resource
5
spring.jar
spring/dist
核心包
6
commons-logging-1.1.1
在Struts2中加入
spring.jar、commons-logging.jar ,
spring注解需要:common-annotations.jar ,
aop需要:aspectjrt.jar、aspectjweaver.jar、cglib-nodep-2.1_3.jar
hibernate.cfg.xml配置:
1.
2. 3.           "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
4.           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
5.
6.
7.
8.    
9.        
10.             org.hibernate.dialect.MySQLDialect
11.        

12.        
13.             jdbc:mysql://localhost:3306/oa
14.        

15.         root
16.         root
17.        
18.             com.mysql.jdbc.Driver
19.        

20.         mysql5
21.         true
22.         thread
23.         update
24.
25.        
26.        
27.             org.hibernate.connection.C3P0ConnectionProvider
28.        

29.        
30.         20
31.        
32.         2
33.        
34.         5000
35.        
36.         100
37.        
38.         1000
39.        
40.         2
41.        
42.         true
43.
44.        
45.
46.    

47.
48.

==========================================================
applicationContext.xml配置如下:
1.
2. 3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
4.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
5.     xsi:schemaLocation="http://www.springframework.org/schema/beans
6.            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
7.            http://www.springframework.org/schema/context
8.            http://www.springframework.org/schema/context/spring-context-2.5.xsd
9.            http://www.springframework.org/schema/aop
10.            http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
11.            http://www.springframework.org/schema/tx
12.            http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
13.
14.    
15.    
16.     17.         class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
18.        
19.        

20.    

21.    
22.    
23.        
24.    

25.    
26.    
27.
28.

========================================================================
二、再加入struts2:
编号
jar包名称
所在位置
功能
1
commons-fileupload-1.2.1.jar
struts/lib
2
commons-io-1.3.2
struts/lib
3
commons-logging-1.1.1
单独下载,
替换1.0.4(struts/lib)
4
freemarker-2.3.15.jar
struts/lib
5
ognl-2.7.3.jar
struts/lib
6
struts2-core-2.1.8.1.jar
struts/lib
7
xwork-core-2.1.6.jar
struts/lib
8
struts2-spring-plugin-2.1.8.1.jar
struts/lib
web.xml如下设置:
1.
2. 3.     xmlns="http://java.sun.com/xml/ns/javaee"
4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
6.     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
7.
8.    
9.        contextConfigLocation
10.        classpath:applicationContext.xml
11.    

12.
13.    
14.           org.springframework.web.context.ContextLoaderListener
15.    

16.

struts2
org.apache.struts2.dispatcher.FilterDispatcher


struts2
/*

25.
26.    
27.         encoding
28.         org.springframework.web.filter.CharacterEncodingFilter
29.        
30.             encoding
31.             UTF-8
32.        

33.    

34.    
35.         encoding
36.         /*
37.    

38.
39.
40.    
41.             OpenSessionInViewFilter
42.             org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
43.    

44.    
45.             OpenSessionInViewFilter
46.             /*
47.    

48.
49.

struts.xml如下:
1.
2. 3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
4.     "http://struts.apache.org/dtds/struts-2.0.dtd">
5.
6.
7.
8.    
9.    
10.    
11.    
12.    
13.    
14.    
15.    
16.    
17.    
18.    
19.    
20.
21.    
22.        
23.        
24.             /WEB-INF/exceptionPage.jsp
25.            

26.        

27.        
28.            
29.        

30.        
31.             /login.jsp
32.        

33.    

34.
35.    
36.        
37.        
38.             /WEB-INF/user/loginSuccess.jsp
39.             /login.jsp
40.        

41.    

42.
43.