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./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./schema/beans" 3. xmlns:xsi="http://www./2001/XMLSchema-instance" xmlns:context="http://www./schema/context" 4. xmlns:aop="http://www./schema/aop" xmlns:tx="http://www./schema/tx" 5. xsi:schemaLocation="http://www./schema/beans 6. http://www./schema/beans/spring-beans-2.5.xsd 7. http://www./schema/context 8. http://www./schema/context/spring-context-2.5.xsd 9. http://www./schema/aop 10. http://www./schema/aop/spring-aop-2.5.xsd 11. http://www./schema/tx 12. http://www./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./xml/ns/javaee" 4. xmlns:xsi="http://www./2001/XMLSchema-instance" 5. xsi:schemaLocation="http://java./xml/ns/javaee 6. http://java./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./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
|
|