灰灰鼠精灵 发表于 2017-12-21 07:25:00

SSM框架下的redis缓存

<beans xmlns="http://www.springframework.org/schema/beans"  xmlns:p
="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:mvc
="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"  xmlns:aop
="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  xsi:schemaLocation
="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  http://www.springframework.org/schema/mvc
  http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring-context-3.2.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx-3.2.xsd "
>  

  <!-- 加载db.properties文件中的内容,db.properties文件中key命名要有一定的特殊规则 -->
  <!-- 引入数据库配置文件 -->
  <bean
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
  <list>
  <value>classpath:db.properties</value>
  <value>classpath:redis.properties</value>
  </list>
  </property>
  </bean>
  <!-- redis数据源 -->
  <bean>
  <property name="maxIdle" value="${redis.maxIdle}" />
  <property name="maxTotal" value="${redis.maxActive}" />
  <property name="maxWaitMillis" value="${redis.maxWait}" />
  <property name="testOnBorrow" value="${redis.testOnBorrow}" />
  </bean>
  <!-- Spring-redis连接池管理工厂 -->
  <bean
  class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
  p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.pass}"
  p:pool-config-ref="poolConfig" />
  <!-- 使用中间类解决RedisCache.jedisConnectionFactory的静态注入,从而使MyBatis实现第三方缓存 -->
  <bean>
  <property name="jedisConnectionFactory" ref="jedisConnectionFactory" />
  </bean>
  <!-- 配置数据源 ,dbcp -->
  

  <bean
  destroy-method="close">
  <property name="driverClassName" value="${jdbc.driver}" />
  <property name="url" value="${jdbc.url}" />
  <property name="username" value="${jdbc.username}" />
  <property name="password" value="${jdbc.password}" />
  <property name="maxActive" value="30" />
  <property name="maxIdle" value="5" />
  </bean>
  <!-- sqlSessionFactory -->
  <bean>
  <!-- 数据库连接池 -->
  <property name="dataSource" ref="dataSource" />
  <!-- 加载mybatis的全局配置文件 -->
  <property name="configLocation" value="classpath:sqlMapConfig.xml" />
  </bean>
  <!-- mapper扫描器 -->
  <bean>
  <!-- 扫描包路径,如果需要扫描多个包,中间使用半角逗号隔开 -->
  <property name="basePackage" value="com.nuo.mapper"></property>
  <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  </bean>
  

  <!-- service -->
  <bean />
  

  

  <!-- 事务管理器 对mybatis操作数据库事务控制,spring使用jdbc的事务控制类 -->
  <bean
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <!-- 数据源 dataSource在applicationContext-dao.xml中配置了 -->
  <property name="dataSource" ref="dataSource" />
  </bean>
  <!-- 通知 -->
  <tx:advice transaction-manager="transactionManager">
  <tx:attributes>
  <!-- 传播行为 -->
  <tx:method name="save*" propagation="REQUIRED" />
  <tx:method name="delete*" propagation="REQUIRED" />
  <tx:method name="insert*" propagation="REQUIRED" />
  <tx:method name="update*" propagation="REQUIRED" />
  <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
  <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
  <tx:method name="select*" propagation="SUPPORTS" read-only="true" />
  </tx:attributes>
  </tx:advice>
  

  <!-- aop -->
  <aop:config>
  <aop:advisor advice-ref="txAdvice"
  pointcut="execution(* com.nuo.service.impl.*.*(..))" />
  </aop:config>
  

  
</beans>
页: [1]
查看完整版本: SSM框架下的redis缓存