spring - JedisConnectionFactory 的方法已弃用。在 Spring Batch 中使用哪些 XML 配置?

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

我正在用 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 片段:

enter image description here

最佳答案

经过大量研究和谷歌搜索后,找到了以下有用的链接:

  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

这是代码片段:

<?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

关于spring - JedisConnectionFactory 的方法已弃用。在 Spring Batch 中使用哪些 XML 配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51366028/

相关文章:

redis - 如何使用 ServiceStack Redis impl 自定义序列化

java - Spring Batch 限制跨多个服务器的单个作业实例

security - Grails Spring Security 插件 - 修改登录用户的权限

java - 这段代码使用(Mockito 和 JUnit)是测试我的 @Service 中的 getById 方法的好方法吗?

java - 如果要从需要 api key 的 Web 服务检索数据,如何使用 Spring?

python - 使用 GET 和 INCR 对 Redis 进行乐观锁定

redis - 在 Redis 中是否可以更新部分值?

java - 需要重新设置oracle中sequence的值

java - 尝试运行 Spring Batch Hello World 3 示例

spring - 无法在 Spring Batch 中的 afterStep 中清理文件夹