strust2+hibernate+spring maven spring 集成redis-2

<?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:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"

xmlns:lang="http://www.springframework.org/schema/lang" xmlns:oxm="http://www.springframework.org/schema/oxm"

xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:util="http://www.springframework.org/schema/util"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.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-3.0.xsd   

        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd   

        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd   

        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd   

        http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd   

        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd   

        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd   

        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"

default-autowire="byName">

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">

<!-- 用户名 -->

<property name="user" value="${jdbc.username}"></property>

<!-- 密码 -->

<property name="password" value="${jdbc.password}"></property>

<property name="driverClass" value="com.mysql.jdbc.Driver" />

<property name="jdbcUrl" value="${jdbc.url}" />

<!--连接池中保留的最大连接数。默认值: 15 -->

<property name="maxPoolSize" value="20" />

<!-- 连接池中保留的最小连接数,默认为:3 -->

<property name="minPoolSize" value="2" />

<!-- 初始化连接池中的连接数,取值应在minPoolSize与maxPoolSize之间,默认为3 -->

<property name="initialPoolSize" value="2" />

<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。默认值: 0 -->

<property name="maxIdleTime" value="60" />

<!-- 当连接池连接耗尽时,客户端调用getConnection()后等待获取新连接的时间,超时后将抛出SQLException,如设为0则无限期等待。单位毫秒。默认: 

0 -->

<!-- aliyun 的网络属于极端网络情况 所以注释掉 但不建议这么干 -->

<!--  <property name="checkoutTimeout" value="3000" />

 -->

<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。默认值: 3 -->

<property name="acquireIncrement" value="2" />

<!--定义在从数据库获取新连接失败后重复尝试的次数。默认值: 30 ;小于等于0表示无限次 -->

<property name="acquireRetryAttempts" value="0" />

<!--重新尝试的时间间隔,默认为:1000毫秒 -->

<property name="acquireRetryDelay" value="1000" />

<!--关闭连接时,是否提交未提交的事务,默认为false,即关闭连接,回滚未提交的事务 -->

<property name="autoCommitOnClose" value="false" />

<!--c3p0将建一张名为Test的空表,并使用其自带的查询语句进行测试。如果定义了这个参数那么属性preferredTestQuery将被忽略。你不能在这张Test表上进行任何操作,它将只供c3p0测试使用。默认值: 

null -->

<property name="automaticTestTable" value="Test" />

<!--如果为false,则获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常,但是数据源仍有效保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试获取连接失败后该数据源将申明已断开并永久关闭。默认: 

false -->

<property name="breakAfterAcquireFailure" value="false" />

<!--每60秒检查所有连接池中的空闲连接。默认值: 0,不检查 -->

<property name="idleConnectionTestPeriod" value="60" />

<!--c3p0全局的PreparedStatements缓存的大小。如果maxStatements与maxStatementsPerConnection均为0,则缓存不生效,只要有一个不为0,则语句的缓存就能生效。如果默认值: 

0 -->

<property name="maxStatements" value="100" />

<!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。默认值: 0 -->

<property name="maxStatementsPerConnection" value="0" />

</bean>

<bean id="sessionFactory"

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

<property name="dataSource" ref="dataSource" />

<property name="hibernateProperties">

<props>

<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>

<prop key="hibernate.show_sql">${jdbc.showsql}</prop>

<prop key="hibernate.format_sql">true</prop>

<prop key="hibernate.generate_statistics">true</prop>

<prop key="hibernate.jdbc.batch_size">5</prop>

<!--  <prop key="hibernate.query.factory_class">org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory</prop>

 --> <prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>

<prop key="hibernate.cglib.use_reflection_optimizer">true</prop>

</props>

</property>

<property name="namingStrategy">

  <bean class="org.hibernate.cfg.ImprovedNamingStrategy" />

  </property>

<property name="packagesToScan" value="com.xcy.*" />

</bean>

<bean id="transactionManager"

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

<property name="sessionFactory" ref="sessionFactory" />

</bean>

<context:component-scan base-package="com.xcy" />

<!-- 使用annotation定义事务 -->

<tx:annotation-driven transaction-manager="transactionManager"

proxy-target-class="true" />

</beans>

<?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:cache="http://www.springframework.org/schema/cache"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"

xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  

    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd  

    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd

    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">

    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> 

        <property name="maxIdle" value="${redis.pool.maxIdle}" />  

        <property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />  

    </bean>  

    

     <bean id="jedis.shardInfo" class="redis.clients.jedis.JedisShardInfo">  

        <constructor-arg index="0" value="${redis.pool.host}" />  

    </bean>  

   

   

    <bean id="shardedJedisPool" class="redis.clients.jedis.ShardedJedisPool">  

        <constructor-arg index="0" ref="jedisPoolConfig" />  

        <constructor-arg index="1">  

            <list>  

                <ref bean="jedis.shardInfo" />  

            </list>  

        </constructor-arg>  

    </bean> 

   

   

    </beans>

5.配置struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

  <constant name="struts.convention.actionConfigBuilder" value="convention"/>

  <constant name="struts.convention.actionNameBuilder" value="convention"/>

  <constant name="struts.convention.resultMapBuilder" value="convention"/>

  <constant name="struts.convention.interceptorMapBuilder" value="convention"/>

  <constant name="struts.convention.conventionsService" value="convention"/>

  <!-- 设置Convention插件定位视图资源的根路径。默认值为/WEB-INF/content/ -->

  <constant name="struts.convention.result.path" value="/WEB-INF/content/"></constant>

  <!-- 如果设置为false,则可以将视图页面放置Action对应的目录下(无需放入/WEB-INF/content/下) -->

  <constant name="struts.convention.result.flatLayout" value="true"></constant>

  <!-- Convention搜索Action类的类名后缀。默认值为Action -->

  <constant name="struts.convention.action.suffix" value="Action"></constant>

  <!-- 是否通过禁止包扫描Action。默认值是false -->

  <constant name="struts.convention.action.disableScanning" value="false"></constant>

  <!-- 设置即使没有@Action注释,依然创建Action映射。默认值是false -->

  <constant name="struts.convention.action.mapAllMatches" value="false"></constant>

  <!-- 设置是否实现了Action接口的类映射成Action。默认值是ture -->

  <constant name="struts.convention.action.checkImplementsAction" value="true"></constant>

  <!-- 设置Convention映射的Action所在包的默认父包。默认值是convention-default -->

  <!--  <constant name="struts.convention.default.parent.package" value="default-package"></constant>-->

  <!-- 设置映射Action时,是否将Action的name属性值转为所有字母小写。默认值是true -->

  <constant name="struts.convention.action.name.lowercase" value="true"></constant>

  <!-- 设置映射Action时指定name属性值个单词之间的分隔符。默认值是中画线 -->

  <constant name="struts.convention.action.name.separator" value="_"></constant>

  <!--  -->

  <constant name="struts.convention.package.locators" value="action,actions,struts,struts2"/>

  <!--  -->

  <constant name="struts.convention.package.locators.disable" value="false"/>

  <constant name="struts.convention.package.locators.basePackage" value=""/>

  <constant name="struts.convention.exclude.packages" value="org.apache.struts.*,org.apache.struts2.*,org.springframework.web.struts.*,org.springframework.web.struts2.*,org.hibernate.*"/>

  <constant name="struts.convention.relative.result.types" value="dispatcher,velocity,freemarker"/>

  <constant name="struts.convention.redirect.to.slash" value="true"/>

  <constant name="struts.convention.action.alwaysMapExecute" value="true"/>

  <constant name="struts.mapper.alwaysSelectFullNamespace" value="true"/>

  <!-- <constant name="struts.convention.action.includeJars"  /> -->

  <constant name="struts.convention.action.fileProtocols" value="jar" />

  

  <constant name="struts.convention.classes.reload" value="false" />

  <constant name="struts.convention.exclude.parentClassLoader" value="true" />

  

  <constant name="struts.devMode" value="false" />

  <constant name="struts.i18n.encoding" value="UTF-8"/>

  <constant name="struts.locale" value="zh_CN" />

  <constant name="struts.custom.i18n.resources" value="global" /> 

  <constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true" />

  <constant name="struts.objectFactory"

value="org.apache.struts2.spring.StrutsSpringObjectFactory" />

<constant name="struts.multipart.maxSize" value="50000000" />

<package name="globalResult" extends="struts-default" abstract="true">

  <global-results>

<result name="error">myError.jsp</result>

<result name="input">/404.jsp</result>

<!-- <result name="crash">/jsp/crash.jsp</result> <result name="needsLogin">/jsp/needsLogin.jsp</result> 

<result name="input">/jsp/needsInit.jsp</result> -->

<result name="login">/login</result>

<result name="exception" >/500.jsp</result>

</global-results>

</package>

<package name="struts-interceptor" extends="globalResult">

<interceptors>

<interceptor name="refererInterceptor"

class="com.xcy.football.legend.common.interceptors.RefererInterceptor" />

<interceptor name="loginInterceptor"

class="com.xcy.football.legend.common.interceptors.LoginInterceptor" />

<!--   <interceptor name="refererInterceptor"

class="com.cctechhk.module.common.interceptors.RefererInterceptor" />

<interceptor name="urlRightInterceptor"

class="com.cctechhk.module.common.interceptors.UserResourceTreeInterceptor" />

<interceptor name="uniqueLoginInterceptor"

class="com.cctechhk.module.common.interceptors.UniqueLoginInterceptor" />

<interceptor name="xssInterceptor"

class="com.cctechhk.module.common.interceptors.XSSInterceptor" />

<interceptor name="timeSpendInterceptor"

class="com.cctechhk.module.common.interceptors.TimeSpendInterceptor" />

<interceptor name="i18n"

class="org.apache.struts2.interceptor.I18nInterceptor" />

-->

<interceptor-stack name="checkLoginStack">

<interceptor-ref name="refererInterceptor" />

<interceptor-ref name="loginInterceptor" />

<!-- <interceptor-ref name="uniqueLoginInterceptor" />

<interceptor-ref name="urlRightInterceptor" />

<interceptor-ref name="xssInterceptor" />

<interceptor-ref name="timeSpendInterceptor" /> -->

<interceptor-ref name="defaultStack">

<param name="exception.logEnabled">true</param>

<param name="exception.logLevel">debug</param>

</interceptor-ref>

<interceptor-ref name="i18n" />

</interceptor-stack>

</interceptors>

<default-interceptor-ref name="checkLoginStack" />

</package> 

<!--  <package name="interface-interceptor" extends="struts-default">

<interceptors>

 <interceptor name="timeSpendInterceptor"

                class="com.cctechhk.module.common.interceptors.TimeSpendInterceptor" />

<interceptor name="interfaceInterceptor"

class="com.cctechhk.module.common.interceptors.InterfaceInterceptor" />

<interceptor-stack name="checkSourceStack">

<interceptor-ref name="interfaceInterceptor" />

<interceptor-ref name="timeSpendInterceptor" />

<interceptor-ref name="defaultStack" />

</interceptor-stack>

</interceptors>

<default-interceptor-ref name="checkSourceStack" />

</package> -->

</struts>


转载于:https://my.oschina.net/u/1789682/blog/485426

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值