【问题标题】:Methods of JedisConnectionFactory is deprecated. Which XML configuations to used in Spring Batch?JedisConnectionFactory 的方法已被弃用。在 Spring Batch 中使用哪些 XML 配置?
【发布时间】:2018-12-24 05:59:11
【问题描述】:

我正在Spring batch 开发一个实用程序,它将从 Mysql/Oracle 读取数据并将其写入 Redis 数据库。

目前我们仍在使用 Spring Batch 基于 XML 的配置(我们仍然喜欢基于 XML - 几乎没有控制权:))

当我配置以下内容时,我发现大多数方法都已弃用。

<bean id="redisDataSource" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name=""></property>
</bean>

使用以下版本的依赖项:

<properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring-batch-vesion>4.0.1.RELEASE</spring-batch-vesion>
        <mysql.version>8.0.11</mysql.version>
        <logback.version>1.2.3</logback.version>
        <jcl.slf4j.version>1.7.25</jcl.slf4j.version>
        <quartz.version>2.2.1</quartz.version>
        <spring.version>5.0.0.RELEASE</spring.version>
        <lombok.version>1.18.0</lombok.version>
        <jedis.version>2.9.0</jedis.version>
</properties>

谁能建议我应该用来配置数据源的基于 XML 的配置?

我从链接中获取了参考:https://docs.spring.io/spring-data/redis/docs/2.0.8.RELEASE/reference/html/,但我不清楚。

STS sn-p:

【问题讨论】:

    标签: spring redis spring-batch spring-jdbc spring-data-redis


    【解决方案1】:

    经过大量研究和谷歌搜索发现以下有用的链接:

    1. Weird redis key with spring data Jedis
    2. Spring Data RedisTemplate: Serializing the Value and HashValue
    3. https://github.com/hantsy/spring-sandbox/blob/master/spring-cache/src/main/java/com/hantsylabs/example/spring/config/applicationContext-jpa-redis.xml
    4. Get Set value from Redis using RedisTemplate

    这里是sn-p的代码:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" 
        xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task" 
        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="  http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans.xsd  
          http://www.springframework.org/schema/util  http://www.springframework.org/schema/util/spring-util.xsd     
          http://www.springframework.org/schema/tx  http://www.springframework.org/schema/tx/spring-tx.xsd     
          http://www.springframework.org/schema/task  http://www.springframework.org/schema/task/spring-task.xsd">
    
       <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
          <property name="maxTotal" value="200" />
          <property name="maxIdle" value="50" />
          <property name="maxWaitMillis" value="3000" />
          <property name="testOnBorrow" value="true" />
       </bean>
    
       <bean id="jedisFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
          <property name="hostName" value="${redis_ip}" />
          <property name="port" value="${redis_port}" />
          <property name="poolConfig" ref="jedisPoolConfig" />
          <property name="usePool" value="true" />
       </bean>
    
       <bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
       <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisFactory" p:valueSerializer-ref="stringRedisSerializer"          
             p:keySerializer-ref="stringRedisSerializer" />
    </beans>
    

    或者简单地使用https://docs.spring.io/spring-integration/reference/html/redis.html

    【讨论】:

      猜你喜欢
      • 2018-08-07
      • 2019-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-27
      • 2016-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多