Struts2.3 spring3.1 hibernate4.0.1 搭建SSH框架

更新时间:2023-08-29 00:40:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Struts2.3+spring3.1+hibernate4.0.1 搭建SSH框架 所谓的框架:就是把一些常用的功能封装好,省去重复的开发;

损失惨重啊,一个不小心,把硬盘分区表丢了,以前的数据全丢了,重头来,做个框架出来,留着以后用吧。

预计的功能:

1. 用户管理

2. 组织机构管理

3. 模块管理

4. 权限管理

5. 工作流,jbpm,

6. cxf服务

7. oscache缓存

struts

(一) jar包

1. xwork-core-2.3.1.1.jar

2. struts2-json-plugin-2.3.1.1.jar

3. struts2-core-2.3.1.1.jar

4. struts2-convention-plugin-2.3.1.1.jar

5. struts2-config-browser-plugin-2.3.1.1.jar

6. ognl-3.0.3.jar

7. javassist-3.11.0.GA.jar

8. freemarker-2.3.18.jar

9. commons-logging-api-1.1.jar

10. commons-lang-2.5.jar

11. commons-io-2.0.1.jar

12. commons-fileupload-1.2.2.jar

13. asm-commons-3.3.jar

14. asm-3.3.jar

说明:

struts2-convention-plugin-2.3.1.1.jar为struts零配置所需的包;

struts2-config-browser-plugin-2.3.1.1.jar为struts协助开发需要的包:可以输入

http://127.0.0.1:8686/config-browser/actionNames.action查看系统所有已经存在的action,配置不正确就可以在这里看出来;

freemarker-2.3.18.jar:模板需要的支持包;

struts2-json-plugin-2.3.1.1.jar:json插件包

(二) 配置文件

/src/default.properties

web.xml

(三) 测试

/struts/TestAction.java

/src/struts.xml

/web/test-content/test1.jsp

以上是有配置文件的测试,以下是无配置action测试

struts2-convention 测试、JSON返回测试:

Freemarker返回测试:

spring + hibernate

(一) jar包

增加spring 和Hibernate让我小折腾了一下,既然是新配置框架,就全用最新的,Hibernate我用的4.x,Spring 用的是3.1 ;Hibernate4.x的包是加进去了,但数据源配置等,还是用的3.x的,所以,狂报错,最后把hibernate3改成hibernate4就可以了,具体有两个地方需要调整:

第一个就是:

<bean id="sessionFactory"

class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

第二个:

<bean id="transactionManager"

class="org.springframework.orm.hibernate4.HibernateTransactionManager" 完整配置文件,下面会贴出来。

Hibernate的jar包还是差不多,把hibernate-release-4.0.1.Final\lib\required目录的jar 包,还有c3p0加进去;

spring就稍麻烦点:

org.springframework.aop-3.1.0.RELEASE.jar

org.springframework.asm-3.1.0.RELEASE.jar

org.springframework.aspects-3.1.0.RELEASE.jar

org.springframework.beans-3.1.0.RELEASE.jar

org.springframework.context-3.1.0.RELEASE.jar

org.springframework.core-3.1.0.RELEASE.jar

org.springframework.expression-3.1.0.RELEASE.jar

org.springframework.instrument-3.1.0.RELEASE.jar

org.springframework.jdbc-3.1.0.RELEASE.jar

org.springframework.jms-3.1.0.RELEASE.jar

org.springframework.orm-3.1.0.RELEASE.jar

org.springframework.oxm-3.1.0.RELEASE.jar

org.springframework.transaction-3.1.0.RELEASE.jar

org.springframework.web-3.1.0.RELEASE.jar

另外还有

ojdbc14.jar -- oracle数据库驱动

mysql-connector-java-5.1.8-bin.jar -- mysql驱动

aopalliance-1.0.jar

aspectjweaver.jar

asm-commons-3.3.jar

及spring测试需要的:

org.springframework.test-3.1.0.RELEASE.jar

可能还缺包,不过小事,这个时候缺包会有明确的提示的:一般都是NoClassDefFoundError: XXX按名称添加就可以了,详细稍后上传;

(一) Spring配置文件:

<property name="location"> <value>classpath:com/gwtjs/config/hibernate.properties</value> </property> </bean> <bean id="dataSource" class="http://www.77cn.com.cnboPooledDataSource" destroy-method="close"> <!-- 安全的路径 jdbc:mysql://127.0.0.1:3306/va66?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding =utf-8&amp;mysqlEncoding=utf8 --> <property name="jdbcUrl" value="${hibernate.connection.url}" /> <property name="driverClass" value="${hibernate.connection.driver_class}" /> <property name="user" value="${http://www.77cn.com.cnername}" /> <property name="password" value="${hibernate.connection.password}" /> <property name="acquireIncrement" value="${c3p0.acquireIncrement}" /> <property name="initialPoolSize" value="${c3p0.initialPoolSize}" /> <property name="minPoolSize" value="${c3p0.minPoolSize}" /> <property name="maxPoolSize" value="${c3p0.maxPoolSize}" /> <property name="maxStatements" value="${c3p0.maxStatements}" /> <property name="numHelperThreads" value="${c3p0.numHelperThreads}" /> <property name="maxIdleTime" value="${c3p0.maxIdleTime}" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource">

<ref local="dataSource" /> </prop

erty> <!--<property name="mappingResources"> <list> <value>com/gwtjs/model/ACL.hbm.xml</value> </list> </property> --><property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> <prop key="hibernate.generate_statistics">true</prop> <prop key="hibernate.connection.release_mode">auto</prop> <prop key="hibernate.autoReconnect">true</prop> <prop key="http://www.77cn.com.cne_sql_comments">false</prop> <prop key="http://www.77cn.com.cne_reflection_optimizer">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.format_sql">${hibernate.format_sql}</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"

p:sessionFactory-ref="sessionFactory" /> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" no-rollback-for="http://www.77cn.com.cnng.Throwable" /> <!-- <tx:method name="*" read-only="true" /> --> </tx:attributes> </tx:advice> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* com.gwtjs.dao.impl.*.*(..))" advice-ref="txAdvice" /> </aop:config> <context:annotation-config /> <context:component-scan base-package="com.gwtjs" /> </beans> hibernate.properties ###################### ### Query Language ### ###################### ## define query language constants / function names hibernate.query.substitutions yes 'Y', no 'N' hibernate.show_sql true ## select the classic query parser #hibernate.query.factory_class org.hibernate.hql.classic.ClassicQueryTranslatorFactory ## MySQL

hibernate.dialect org.hibernate.dialect.MySQLDialect hibernate.connection.driver_class com.mysql.jdbc.Driver hibernate.connection.url jdbc\:mysql\://127.0.0.1\:3306/NewTest http://www.77cn.com.cnername root hibernate.connection.password 860748 ## Oracle ## hibernate.dialect org.hibernate.dialect.OracleDialect ## hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver ## http://www.77cn.com.cnername FoundationDB ## hibernate.connection.password FoundationDBPwd ## hibernate.connection.url jdbc:oracle:thin:@localhost:1521:orcl ## set the maximum depth of the outer join fetch tree hibernate.connection.pool_size 1 hibernate.proxool.pool_alias pool1 hibernate.format_sql false ## add comments to the generated SQL http://www.77cn.com.cne_sql_comments true ## set the maximum depth of the outer join fetch tree hibernate.max_fetch_depth 1 hibernate.jdbc.batch_versioned_data true http://www.77cn.com.cne_streams_for_binary true hibernate.cache.region_prefix hibernate.test hibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider

(二) web.xml

本文来源:https://www.bwwdw.com/article/35di.html

Top