SSH框架搭建配置

来源:互联网 发布:数据分析之量化投资 编辑:程序博客网 时间:2024/06/06 01:43

1、开发环境:MyEclipse、MySQL、jdk1.7.0_79、Tomcat 7.x

这里写图片描述

2、创建数据库

这里写图片描述

3、创建数据库链接配置文件(db.properties)

datasource.driverClassName=com.mysql.jdbc.Driver#数据库链接地址datasource.url=jdbc\:mysql\:///empmanagedatasource.username=数据库链接用户datasource.password=数据库链接密码hibernate.dialect=org.hibernate.dialect.MySQLDialecthibernate.show_sql=truehibernate.cache.class=org.hibernate.cache.EhCacheProviderhibernate.cache.query=falsec3p0.maxPoolSize=2000c3p0.minPoolSize=500c3p0.initialPoolSize=500c3p0.maxIdleTime=200c3p0.acquireIncrement=3c3p0.acquireRetryAttempts=30c3p0.acquireRetryDelay=1000c3p0.autoCommitOnClose=falsedbcp.initialSize=15dbcp.maxIdle=10dbcp.minIdle=1dbcp.maxActive=1000dbcp.logAbandoned=truedbcp.removeAbandoned=truedbcp.removeAbandonedTimeout=2000dbcp.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 = falsedate=60000

4、struts.properties 文件

struts.action.extension=do,tg,actionstruts.objectFactory=spring#struts.enable.DynamicMethodInvocation=falsestruts.devMode=falsestruts.locale=zh_CNstruts.i18n.encoding=utf-8struts.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)
到这里我们的框架配置结束了,如果对你有帮助,请关注我。有不明白的可以留言…..

原码下载:http://download.csdn.net/download/qq_39189632/10046918

原创粉丝点击