1、开发环境:MyEclipse、MySQL、jdk1.7.0_79、Tomcat 7.x
2、创建数据库
3、创建数据库链接配置文件(db.properties)
datasource.driverClassName=com.mysql.jdbc.Driver
#数据库链接地址
datasource.url=jdbc\:mysql\:///empmanage
datasource.username=数据库链接用户
datasource.password=数据库链接密码
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.cache.class=org.hibernate.cache.EhCacheProvider
hibernate.cache.query=false
c3p0.maxPoolSize=2000
c3p0.minPoolSize=500
c3p0.initialPoolSize=500
c3p0.maxIdleTime=200
c3p0.acquireIncrement=3
c3p0.acquireRetryAttempts=30
c3p0.acquireRetryDelay=1000
c3p0.autoCommitOnClose=false
dbcp.initialSize=15
dbcp.maxIdle=10
dbcp.minIdle=1
dbcp.maxActive=1000
dbcp.logAbandoned=true
dbcp.removeAbandoned=true
dbcp.removeAbandonedTimeout=2000
dbcp.maxWait=15000
#set to 'SELECT 1'
dbcp.validationQuery = "SELECT 1"
#set to 'true'
dbcp.testWhileIdle = true
#some positive integer
dbcp.timeBetweenEvictionRunsMillis = 300000
#set to something smaller than 'wait_timeout'
dbcp.minEvictableIdleTimeMillis = 320000
#if you don't mind a hit for every getConnection(), set to "true"
dbcp.testOnBorrow = "true"
scheduler.Manager = false
date=60000
4、struts.properties 文件
struts.action.extension=do,tg,action
struts.objectFactory=spring
#struts.enable.DynamicMethodInvocation=false
struts.devMode=false
struts.locale=zh_CN
struts.i18n.encoding=utf-8
struts.multipart.maxSize=10240000
5、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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-lazy-init="true">
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.user.**"></context:component-scan>
<!-- 导入资源文件 -->
<context:property-placeholder location="classpath:db.properties"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${datasource.driverClassName}"></property>
<property name="url" value="${datasource.url}"></property>
<property name="username" value="${datasource.username}" />
<property name="password" value="${datasource.password}" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="300" />
<property name="timeBetweenEvictionRunsMillis" value="86400" />
<property name="testWhileIdle" value="true" />
<property name="validationQuery" value="SELECT 1 FROM dual" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan">
<list>
<value>com.user.**.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.query.substitutions">true 1, false 0</prop>
<prop key="hibernate.default_batch_fetch_size">4</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="advice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="alter*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="set*" propagation="REQUIRED"/>
<tx:method name="register" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="create*" propagation="REQUIRED"/>
<tx:method name="process*" propagation="REQUIRED"/>
<tx:method name="restore*" propagation="REQUIRED"/>
<tx:method name="backup*" propagation="REQUIRED"/>
<tx:method name="log*" propagation="REQUIRED"/>
<tx:method name="giving*" propagation="REQUIRED"/>
<tx:method name="auth*" propagation="REQUIRED"/>
<tx:method name="sendMessage*" propagation="REQUIRED"/>
<tx:method name="cust*" propagation="REQUIRED"/>
<tx:method name="make*" propagation="REQUIRED"/>
<tx:method name="inq*" propagation="REQUIRED"/>
<tx:method name="list*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="(execution(* com.user..*Service.*(..)))" id="pointcut"/>
<aop:advisor advice-ref="advice" pointcut-ref="pointcut"/>
</aop:config>
</beans>
6、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">
<display-name></display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>openSessionInViewerFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewerFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<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>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
增、删、查、改的实现参考(http://blog.csdn.net/qq_39189632/article/details/78404536)
到这里我们的框架配置结束了,如果对你有帮助,请关注我。有不明白的可以留言…..