struts2.1.8 + spring2.5.6 + hibernate3.3.2整合的登陆 带 jar包

此次整合的版本是:struts2.1.8 + spring2.5.6 + hibernate3.3.2
一.先整合hibernate和spring:

============================================================

hibernate所需要jar包:

antlr- 2.7.6.jar、commons-collections-3.1.jar、dom4j-1.6.1.jar、hibernate3.jar、 javassist-3.9.0.GA.jar、jta-1.1.jar、slf4j-api-1.5.8.jar、log4j.jar、slf4j- log4j12-1.5.8.jar (slf4j接口以log4j形式实现),因为采用了注解的方式所以还需(annotation3.4的包):ejb3- persistence.jar、hibernate-annotations.jar、hibernate-commons- annotations.jar、hibernate-entitymanager.jar、hibernate-validator.jar、 jboss-archive-browsing.jar ,采用了c3p0连接池,还需要:c3p0-0.9.1.2.jar

========================================================================

spring所需要jar包:spring.jar、commons-logging.jar ,spring注解需要:common-annotations.jar ,aop需要:aspectjrt.jar、aspectjweaver.jar、cglib-nodep-2.1_3.jar

hibernate.cfg.xml配置:

1. <?xml version='1.0' encoding='UTF-8'?> 
2. <!DOCTYPE hibernate-configuration PUBLIC 
3.           "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
4.           "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
5.  
6. <hibernate-configuration> 
7.  
8.     <session-factory> 
9.         <property name="dialect"> 
10.             org.hibernate.dialect.MySQLDialect 
11.         </property> 
12.         <property name="connection.url"> 
13.             jdbc:mysql://localhost:3306/oa 
14.         </property> 
15.         <property name="connection.username">root</property> 
16.         <property name="connection.password">root</property> 
17.         <property name="connection.driver_class"> 
18.             com.mysql.jdbc.Driver 
19.         </property> 
20.         <property name="myeclipse.connection.profile">mysql5</property> 
21.         <property name="show_sql">true</property> 
22.         <property name="current_session_context_class">thread</property> 
23.         <property name="hbm2ddl.auto">update</property> 
24.  
25.         <!-- 首先说明我是使用c3p0连接池的方式 --> 
26.         <property name="connection.provider_class"> 
27.             org.hibernate.connection.C3P0ConnectionProvider 
28.         </property> 
29.         <!-- 最大连接数 --> 
30.         <property name="hibernate.c3p0.max_size">20</property> 
31.         <!-- 最小连接数 --> 
32.         <property name="hibernate.c3p0.min_size">2</property> 
33.         <!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 --> 
34.         <property name="hibernate.c3p0.timeout">5000</property> 
35.         <!-- 最大的PreparedStatement的数量 --> 
36.         <property name="hibernate.c3p0.max_statements">100</property> 
37.         <!-- 每隔1000秒检查连接池里的空闲连接 ,单位是秒--> 
38.         <property name="hibernate.c3p0.idle_test_period">1000</property> 
39.         <!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 --> 
40.         <property name="hibernate.c3p0.acquire_increment">2</property> 
41.         <!-- 每次都验证连接是否可用 --> 
42.         <property name="hibernate.c3p0.validate">true</property> 
43.          
44.         <mapping class="com.fsj.model.User" /> 
45.  
46.     </session-factory> 
47.  
48. </hibernate-configuration>

==========================================================
applicationContext.xml配置如下:

1. <?xml version="1.0" encoding="UTF-8"?> 
2. <beans xmlns="http://www.springframework.org/schema/beans
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.     <context:component-scan base-package="com.fsj" /><!-- 启用自动扫描 --> 
15.     <!-- 基于hibernate注解的sessionFactory --> 
16.     <bean id="sessionFactory" 
17.         class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
18.         <property name="configLocation" value="classpath:hibernate.cfg.xml"> 
19.         </property> 
20.     </bean> 
21.     <!-- 基于hibernate的事务管理器 --> 
22.     <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
23.         <property name="sessionFactory" ref="sessionFactory" /> 
24.     </bean> 
25.     <!-- 采用注解形式的声明式事务管理 --> 
26.     <tx:annotation-driven transaction-manager="txManager"/> 
27.      
28. </beans>

========================================================================
再加入struts2:

加入包:xwork-core-2.1.6.jar、 struts2-core-2.1.8.jar、ognl-2.7.3.jar、freemarker-2.3.15.jar、commons-io- 1.3.2.jar、commons-fileupload-1.2.1.jar、struts2-spring-plugin-2.1.8.jar

web.xml如下设置:

1. <?xml version="1.0" encoding="UTF-8"?> 
2. <web-app version="2.5"  
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.     <context-param> 
9.        <param-name>contextConfigLocation</param-name> 
10.        <param-value>classpath:applicationContext.xml</param-value> 
11.     </context-param> 
12.      
13.     <listener> 
14.           <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
15.     </listener> 
16.          
<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>
25.          
26.     <filter> 
27.         <filter-name>encoding</filter-name> 
28.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
29.         <init-param> 
30.             <param-name>encoding</param-name> 
31.             <param-value>UTF-8</param-value> 
32.         </init-param> 
33.     </filter> 
34.     <filter-mapping> 
35.         <filter-name>encoding</filter-name> 
36.         <url-pattern>/*</url-pattern> 
37.     </filter-mapping> 
38.          
39.                          
40.     <filter> 
41.             <filter-name>OpenSessionInViewFilter</filter-name> 
42.             <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> 
43.     </filter> 
44.     <filter-mapping> 
45.             <filter-name>OpenSessionInViewFilter</filter-name> 
46.             <url-pattern>/*</url-pattern> 
47.     </filter-mapping> 
48.      
49. </web-app>

struts.xml如下:

1. <?xml version="1.0" encoding="UTF-8" ?> 
2. <!DOCTYPE struts PUBLIC 
3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
4.     "http://struts.apache.org/dtds/struts-2.0.dtd"> 
5.  
6. <struts> 
7.  
8.     <!-- 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 --> 
9.     <constant name="struts.i18n.encoding" value="UTF-8" /> 
10.     <!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 --> 
11.     <constant name="struts.serve.static.browserCache" value="false" /> 
12.     <!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 --> 
13.     <constant name="struts.configuration.xml.reload" value="true" /> 
14.     <!-- 开发模式下使用,这样可以打印出更详细的错误信息 --> 
15.     <constant name="struts.devMode" value="true" /> 
16.     <!-- 默认的视图主题 --> 
17.     <constant name="struts.ui.theme" value="simple" /> 
18.     <!-- 把action对象交给spring创建 --> 
19.     <constant name="struts.objectFactory" value="spring" /> 
20.  
21.     <package name="myDefault" extends="struts-default"> 
22.         <default-action-ref name="indexPage" /> 
23.         <global-results> 
24.             <result name="exceptionPage">/WEB-INF/exceptionPage.jsp 
25.             </result> 
26.         </global-results> 
27.         <global-exception-mappings> 
28.             <exception-mapping result="exceptionPage" exception="java.lang.Exception" /> 
29.         </global-exception-mappings>       
30.         <action name="indexPage"> 
31.             <result>/login.jsp</result> 
32.         </action> 
33.     </package> 
34.  
35.     <package name="user" namespace="/user" extends="myDefault"> 
36.         <!-- 这里面的class不是指完整类路径,而是指在spring中定义的bean的名称 --> 
37.         <action name="*UserAction" class="userAction" method="{1}"> 
38.             <result name="success">/WEB-INF/user/loginSuccess.jsp</result> 
39.             <result name="input">/login.jsp</result> 
40.         </action> 
41.     </package> 
42.  
43. </struts>


=======================================
**********************************************************************
使用的技术:spring2.0+struts2.0+hibernate3.0
spring2.0的JAR包:
1、spring-2.0.jar、
Struts2.0的JAR包:
1、struts2-core-2.0.11.1.jar;
2、struts2-spring-plugin-2.0.11.1.jar;
3、xwork-2.0.4.jar;
4、ognl-2.6.11.jar
5、freemarker-2.3.8.jar
hibernate3.0的JAR包:
1、hibernate3.jar
2、hibernate-annotations.jar
3、antlr-2.7.6.jar;
4、cglib-nodep-2.1_3.jar
5、commons-beanutils-1.7.0.jar

另外:连接数据库的两个Jar包:
1、commons-dbcp.jar;
2、commons-pool.jar

做事务的Jar包:
1、jta.jar;
解析XML文件:
1.dom4j.xml

====================================================================
**********************************************************************************************
ssh:Struts1.2 + Hibernate3.2 + Spring2.0

antlr-2.7.6rc1.jar
asm.jar
asm-attrs.jar
cglib-2.1.3.jar
commons-attributes-api.jar
commons-beanutils.jar
commons-codec.jar
commons-collections-2.1.1.jar
commons-dbcp.jar
commons-digester.jar
commons-discovery.jar
commons-fileupload.jar
commons-httpclient.jar
commons-io.jar
commons-lang.jar
commons-logging-1.0.4.jar
commons-pool.jar
commons-validator.jar
dom4j-1.6.1.jar
ehcache-1.1.jar
hibernate3.jar
jaas.jar
jaxen-1.1-beta-7.jar
jdbc2_0-stdext.jar
jstl.jar
jta.jar
junit-4.1.jar
log4j-1.2.11.jar
mysql-connector-java-5.1.7-bin.jar
spring.jar
spring-webmvc-struts.jar
standard.jar
struts.jar
xerces-2.6.2.jar
xml-apis.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>
           /WEB-INF/applicationContext*.xml,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>
   <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
   <listener>
       <listener-class>
           org.springframework.web.context.ContextLoaderListener
       </listener-class>
   </listener>
</web-app>
 
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
   <constant name="struts.objectFactory" value="spring" />
   <constant name="struts.enable.DynamicMethodInvocation"
       value="false" />
   <constant name="struts.devMode" value="false" />
   <!-- Add packages here -->
   <package name="com.pet.action" extends="struts-default">
       <action name="Hello" class="hello">
           <result name="succ">/index.jsp</result>
       </action>
   </package>
</struts>

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"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
   <import resource="Struts2Action.xml"/>
   <import resource="database.xml"/>
   </beans>

database.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">
   <bean id="DataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
    <property name="url" value="jdbc:mysql://localhost:3306"></property>
    <property name="username" value="root"></property>
    <property name="password" value="root"></property>
   </bean>
   <bean id="SessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
        <ref bean="DataSource" />
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.MySQLDialect
            </prop>
        </props>
    </property>
    <property name="mappingResources">
        <list>
            <value>com/pet/hibernate/pojo/Hksres.hbm.xml</value></list>
    </property></bean>
   <bean id="HksresDAO" class="com.pet.hibernate.pojo.HksresDAO">
    <property name="sessionFactory">
        <ref bean="SessionFactory" />
    </property>
   </bean></beans>

Struts2Action.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">

   <bean id="hello" class="com.pet.action.Hello" >
      
   </bean>
</beans>
1.去掉类路径上的关于Hibernate的3个lib
asm.jar
asm-attrs.jar
cglib-2.1.3.jar
2.加入Spring中的以下4个lib
asm-2.2.2.jar
asm-commons-2.2.2.jar
asm-util-2.2.2.jar
cglib-nodep-2.1_3.jar

加上一个

commons-pool-1.3.jar

Struts2使用的包:

freemarker-2.3.8.jar

ognl-2.6.11.jar

struts2-core-2.0.11.2.jar

xwork-2.0.5.jar

commons-logging-1.0.4.jar


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/syh202/archive/2011/02/09/6175496.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

forestsea

你的打赏是我精心创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值