SSH中Spring以及hibernate、Redis的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:tx="http://www.springframework.org/schema/tx"
      xmlns:p="http://www.springframework.org/schema/p"
   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-4.3.xsd
   http://www.springframework.org/schema/tx 
   http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
   http://www.springframework.org/schema/aop 
   http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-4.3.xsd"
   default-autowire="byName" default-lazy-init="false">

   <!-- 定义受环境影响易变的变量 -->
   <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="locations">
         <list>
            <!-- 标准配置 -->
            <value>classpath:jdbc.properties</value>
         </list>
      </property>
   </bean>

   
   <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
   <context:component-scan base-package="com.test.server" />
   <context:annotation-config />

   <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
      <property name="driverClass" value="
                     com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="
                     jdbc:mysql:///test?
                     useUnicode=true&amp;characterEncoding=UTF-8&amp; 
                     1autoReconnect=true" />
<property name="user" value="root" /> <property name="password" value="1234" /> <property name="initialPoolSize" value="10" /> <!--连接空闲时间(秒) --> <property name="maxIdleTime" value="200" /> <property name="maxPoolSize" value="50" /> <property name="minPoolSize" value="10" /> <!--获取新连接的等待时间(毫秒)0一直等待 --> <property name="checkoutTimeout" value="30000" /> <!--检测空闲连接的时间间隔(秒) --> <property name="idleConnectionTestPeriod" value="150" /> <!--<property name="testConnectionOnCheckout" value="true" />--> </bean> <!-- Hibernate配置 --> <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.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.connection.release_mode">auto</prop> <prop key="hibernate.hbm2ddl.auto">update</prop>
</props> </property>
<!-- 配置扫描bean value:配置bean包 -->
 <property name="packagesToScan" value="com.test.server.data" /> </bean> <!--配置Redis--> <bean id="redisPoolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="100"/> <property name="maxTotal" value="300" /> <property name="maxWaitMillis" value="60000" /> <property name="testOnBorrow" value="false" /> <property name="testOnReturn" value="false" /> <property name="timeBetweenEvictionRunsMillis" value="60000" /> <property name="minEvictableIdleTimeMillis" value="120000" /> <property name="numTestsPerEvictionRun" value="-1" /> </bean> <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:hostName="${redis.hostName}" p:port="${redis.port}" p:password="${redis.password}" p:usePool="true" p:poolConfig-ref="redisPoolConfig"/> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connectionFactory-ref="jedisConnectionFactory"/> <!-- 事务管理器配置,单数据源事务 --> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="find*" read-only="true" /> <tx:method name="query*" read-only="true" /> <tx:method name="is*" read-only="true" /> <tx:method name="*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> <!-- 使用annotation定义事务 --> <tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/> <aop:config proxy-target-class="true"> <aop:advisor pointcut="execution(* com.test.server.service..*Manager.*(..))" advice-ref="txAdvice" /> <aop:advisor pointcut="execution(* com.test.server.dao..*Dao.*(..))" advice-ref="txAdvice" /> </aop:config></beans>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值