一、struts框架
Struts版本:采用最新的struts-2.3.24
添加jar文件:
asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
commons-lang3-3.2.jar
freemarker-2.3.22.jar
javassist-3.11.0.GA.jar
log4j-api-2.2.jar
log4j-core-2.2.jar
ognl-3.0.6.jar
struts2-core-2.3.24.jar
xwork-core-2.3.24.jar
aopalliance-1.0.jar
commons-logging-1.1.3.jar
struts2-spring-plugin-2.3.24.jar
aopalliance-1.0.jar、 commons-logging-1.1.3.jar、struts2-spring-plugin-2.3.24.jar集成spring(spring-framework-4.1.6.RELEASE)的时候需要用到,可以在添加spring的jar包的时候拷贝进去,因为spring4.1.6没有这三个。
Struts配置文件:struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="false" />
<constant name="struts.ui.theme" value="simple" />
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<global-results>
<result name="error">/WEB-INF/jsp/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception"
result="error" />
</global-exception-mappings>
<action name="index"class="cn.ssh1.struts.action.Struts2"
method="execute">
<result name="success">/test.jsp</result>
</action>
<action name="ssh_*" class="cn.ssh1.oa.action.ProductAction"
method="{1}">
<result name="list">/WEB-INF/jsp/ssh_list.jsp</result>
<result name="success">/WEB-INF/jsp/ssh_list.jsp</result>
</action>
</package>
</struts>
在web.xml里添加struts的配置:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
二、Spring配置
Spring版本:采用最新的spring-framework-4.1.6.RELEASE
Spring需要的jar包:这里就全部拷贝
spring-aop-4.1.6.RELEASE.jar
spring-aspects-4.1.6.RELEASE.jar
spring-beans-4.1.6.RELEASE.jar
spring-context-4.1.6.RELEASE.jar
spring-context-support-4.1.6.RELEASE.jar
spring-core-4.1.6.RELEASE.jar
spring-expression-4.1.6.RELEASE.jar
spring-instrument-4.1.6.RELEASE.jar
spring-instrument-tomcat-4.1.6.RELEASE.jar
spring-jdbc-4.1.6.RELEASE.jar
spring-jms-4.1.6.RELEASE.jar
spring-messaging-4.1.6.RELEASE.jar
spring-orm-4.1.6.RELEASE.jar
spring-oxm-4.1.6.RELEASE.jar
spring-test-4.1.6.RELEASE.jar
spring-tx-4.1.6.RELEASE.jar
spring-web-4.1.6.RELEASE.jar
spring-webmvc-4.1.6.RELEASE.jar
spring-webmvc-portlet-4.1.6.RELEASE.jar
spring-websocket-4.1.6.RELEASE.jar
Spring配置文件: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:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 1、自动扫描与装配bean -->
<context:component-scan base-package="cn.ssh1"></context:component-scan>
<!-- 导入外部的配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties" />
<!-- 配置sessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<!-- 指定hibernate的配置路径 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"/>
<!-- 配置c3p0数据库连接池 -->
<property name="dataSource">
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 数据库连接信息 -->
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<!-- 其他配置 -->
<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize" value="3"></property>
<!--连接池中保留的最小连接数。Default: 3 -->
<property name="minPoolSize" value="3"></property>
<!--连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize" value="5"></property>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="3"></property>
<!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
<property name="maxStatements" value="8"></property>
<!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
<property name="maxStatementsPerConnection"value="5"></property>
<!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="1800"></property>
</bean>
</property>
</bean>
<!-- 配置声名式事务管理(采用注解的方式) -->
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="txManager" />
</beans>
配置数据源:jdbc.properties
jdbcUrl=jdbc\:mysql\:///ssh3
driverClass=com.mysql.jdbc.Driver
user=root
password=root
三、Hibernate配置
Hibernate版本:hibernate-release-4.3.10.Final
Hibernate需要的jar包:
Required包下的必须添加:
antlr-2.7.7.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-core-4.3.10.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
Jpa文件夹下的
hibernate-entitymanager-4.3.10.Final.jar
可选包下的数据源c3p0,因为spring配置的时候选择c3p0数据连接池
c3p0-0.9.2.1.jar
hibernate-c3p0-4.3.10.Final.jar
mchange-commons-java-0.2.3.4.jar
数据库连接jar
mysql-connector-java-5.1.22-bin.jar
Hibernate配置信息:
<!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="dialect">
org.hibernate.dialect.MySQL5InnoDBDialect
</property>
<!--2、其他配置 -->
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>
<!-- 3、导入映射文件 -->
<mapping resource="cn/ssh1/oa/doman/Product.hbm.xml" />
</session-factory>
</hibernate-configuration>