• Spring整合Redis(spring-data-redis)之配置文件


    spring-config.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:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    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.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

    <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <!-- 对于读取一个配置文件采取的方案 -->
    <!-- <property name="location" value="classpath:cfg.properties"></property> -->
    <!-- 对于读取两个以上配置文件采取的处理方案 ,如下-->
    <property name="locations">
    <list>
    <value>file:config/conf.properties</value>
    <value>file:config/redis.properties</value>
    </list>
    </property>
    </bean>

    <!-- 扫描注解Bean -->
    <context:component-scan base-package="com.yy.miniprogram.*">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!-- jedis 连接池配置参数: -->
    <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <!--设置最大连接数 -->
    <property name="maxTotal" value="${redis.maxActive}"></property>
    <!-- 设置最大空闲数-->
    <property name="maxIdle" value="${redis.maxIdle}"></property>
    <!--设置超时时间-->
    <property name="maxWaitMillis" value="${redis.maxWait}"></property>
    <property name="testOnBorrow" value="${redis.testOnBorrow}"></property>
    </bean>

    <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
    p:host-name="${redis.host}"
    p:port="${redis.port}"
    p:pool-config-ref="poolConfig"
    p:use-pool="true">
    </bean>

    <!-- <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
    <property name="connectionFactory" ref="jedisConnectionFactory"></property>
    </bean> -->
    <!-- redis template definition -->
    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
    <property name="connectionFactory" ref="jedisConnectionFactory" />
    <property name="keySerializer">
    <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
    </property>
    <property name="valueSerializer">
    <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
    </property>
    <property name="hashKeySerializer">
    <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
    </property>
    <property name="hashValueSerializer">
    <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
    </property>
    </bean>
    <!--自定义redis工具类,在需要缓存的地方注入此类 -->
    <!-- <bean id="redisrCacheManager" class="com.phil.common.redis.RedisCacheManager">
    <property name="redisTemplate" ref="redisTemplate" />
    </bean>
    -->
    </beans>

    ---------------------------------------------------------------------------------------------------------------------------------

    pom.xml

    <properties>
        <!-- redis 版本 -->
        <redis.version>2.9.0</redis.version>
        <spring.redis.version>1.8.4.RELEASE</spring.redis.version>
    </properties>
    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>${redis.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-redis</artifactId>
        <version>${spring.redis.version}</version>
    </dependency>

     <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>4.3.10.RELEASE</version>
     </dependency>

  • 相关阅读:
    Linux Ubuntu系统的安装||grub启动字符界面
    linux 第一个qt程序 以及 linux qt cannotfind lgL的解决
    linux ftp 文件传输的搭建 以qt上传为例
    linux gcc 安装和第一个hello world脚本
    python bug debug
    python 元组的概念以及 math 模块
    移动端调试
    移动终端学习2:触屏原生js事件及重力感应
    input file 类型为excel表格
    gulp构建工具的安装
  • 原文地址:https://www.cnblogs.com/--Candice/p/9630468.html
Copyright © 2020-2023  润新知