Java JedisPoolConfig 不可分配给 GenericObjectPoolConfig

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22704518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 17:23:46  来源:igfitidea点击:

JedisPoolConfig is not assignable to GenericObjectPoolConfig

javaspringcachingredisjedis

提问by user3089280

I have a Spring based java web application hosted on Heroku. I am attempting to utilize the Spring Caching abstraction using the Redis implementation. When the server starts, I get an error saying:

我在 Heroku 上托管了一个基于 Spring 的 Java Web 应用程序。我正在尝试使用 Redis 实现来利用 Spring Caching 抽象。当服务器启动时,我收到一条错误消息:

Type 'redis/clients/jedis/JedisPoolConfig' (current frame, stack[3]) is not assignable to 'org/apache/commons/pool2/impl/GenericObjectPoolConfig'

Here is my configuration:

这是我的配置:

@Bean
     RedisConnectionFactory jedisConnectionFactory() throws Exception {
         URI redisUri =  new URI(System.getenv("REDISCLOUD_URL"));
         JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
         redisConnectionFactory.setHostName(redisUri.getHost());
         redisConnectionFactory.setPort(redisUri.getPort());
         redisConnectionFactory.setPassword(redisUri.getUserInfo().split(":",2)[1]);
         redisConnectionFactory.setUsePool(true);
         return redisConnectionFactory;
     }

 @Bean
 RedisTemplate<Object, Object> redisTemplate()  {
     RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<Object, Object>();
     try {
        redisTemplate.setConnectionFactory(jedisConnectionFactory());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     return redisTemplate;
 }
@Override
@Bean
public CacheManager cacheManager() {
    // configure and return an implementation of Spring's CacheManager SPI
    RedisCacheManager manager = new RedisCacheManager(redisTemplate());
    List<String> caches = new ArrayList<String>();
    caches.add("Suppliers");
    caches.add("Manufacturer");
    caches.add("Sheeting");
    caches.add("SignTypeFlat");
    manager.setCacheNames(caches);
    return manager;
}

Here is the entire Error Message:

这是整个错误消息:

 Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory m ethod [org.springframework.data.redis.connection.RedisConnectionFactory com.signInventory.config.ProdDataSourceConfiguration.jedisConnectionFactory() throws java.lang.Exception] threw exception; nested exception is java.lang.VerifyError: Bad type on operand stack Exception Details:   Location:
    org/springframework/data/redis/connection/jedis/JedisConnectionFactory.afterPropertiesSet()V @109: invokespecial   Reason:
    Type 'redis/clients/jedis/JedisPoolConfig' (current frame, stack[3]) is not assignable to 'org/apache/commons/pool2/impl/GenericObjectPoolConfig'   Current Frame:
    bci: @109
    flags: { }
    locals: { 'org/springframework/data/redis/connection/jedis/JedisConnectionFactory' }
    stack: { 'org/springframework/data/redis/connection/jedis/JedisConnectionFactory', uninitialized 73, uninitialized 73, 'redis/clients/jedis/JedisPoolConfig', 'java/lang/String', integer, integer, 'java/lang/String' }   Bytecode:
    0000000: 2ab4 000d c700 3d2a bb00 1759 2ab4 0003
    0000010: 2ab4 0004 b700 18b5 000d 2ab4 0019 b800
    0000020: 1a99 000e 2ab4 000d 2ab4 0019 b600 1b2a
    0000030: b400 059e 000e 2ab4 000d 2ab4 0005 b600
    0000040: 1c2a b400 0699 002e 2abb 001d 592a b400
    0000050: 0a2a b400 0db6 001e 2ab4 000d b600 1f2a
    0000060: b400 0db6 0020 2ab4 000d b600 21b7 0022
    0000070: b500 07b1   Stackmap Table:
    same_frame(@47)
    same_frame(@65)
    same_frame(@115) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:181) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:578) ... 36 more Caused by: java.lang.VerifyError: Bad type on operand stack Exception Details:   Location:
    org/springframework/data/redis/connection/jedis/JedisConnectionFactory.afterPropertiesSet()V @109: invokespecial   Reason:
    Type 'redis/clients/jedis/JedisPoolConfig' (current frame, stack[3]) is not assignable to 'org/apache/commons/pool2/impl/GenericObjectPoolConfig'   Current Frame:
    bci: @109
    flags: { }
    locals: { 'org/springframework/data/redis/connection/jedis/JedisConnectionFactory' }
    stack: { 'org/springframework/data/redis/connection/jedis/JedisConnectionFactory', uninitialized 73, uninitialized 73, 'redis/clients/jedis/JedisPoolConfig', 'java/lang/String', integer, integer, 'java/lang/String' }   Bytecode:
    0000000: 2ab4 000d c700 3d2a bb00 1759 2ab4 0003
    0000010: 2ab4 0004 b700 18b5 000d 2ab4 0019 b800
    0000020: 1a99 000e 2ab4 000d 2ab4 0019 b600 1b2a
    0000030: b400 059e 000e 2ab4 000d 2ab4 0005 b600
    0000040: 1c2a b400 0699 002e 2abb 001d 592a b400
    0000050: 0a2a b400 0db6 001e 2ab4 000d b600 1f2a
    0000060: b400 0db6 0020 2ab4 000d b600 21b7 0022
    0000070: b500 07b1   Stackmap Table:
    same_frame(@47)
    same_frame(@65)
    same_frame(@115) at com.signInventory.config.ProdDataSourceConfiguration.jedisConnectionFactory(ProdDataSourceConfiguration.java:46) at com.signInventory.config.ProdDataSourceConfiguration$$EnhancerByCGLIB$8faa2b.CGLIB$jedisConnectionFactory(<generated>) at com.signInventory.config.ProdDataSourceConfiguration$$EnhancerByCGLIB$8faa2b$$FastClassByCGLIB$$b4f3aedd.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:286) at com.signInventory.config.ProdDataSourceConfiguration$$EnhancerByCGLIB$8faa2b.jedisConnectionFactory(<generated>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160) ... 37 more

Any help would be greatly appreciated.

任何帮助将不胜感激。

Thanks!

谢谢!

回答by spilio

Had exactly the same problem when I upgraded to Spring Data Redis v1.2.1-RELEASE. I solved the problem after upgrading Jedis to the latest version - v2.4.2. If you are using Maven, check the following dependencies.

当我升级到 Spring Data Redis v1.2.1-RELEASE 时遇到了完全相同的问题。我将 Jedis 升级到最新版本 - v2.4.2 后解决了这个问题。如果您使用的是 Maven,请检查以下依赖项。

<properties>
    <spring.data.redis>1.2.1.RELEASE</spring.data.redis>
    <jedis>2.4.2</jedis>
</properties>

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-redis</artifactId>
    <version>${spring.data.redis}</version>
</dependency>
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>${jedis}</version>
</dependency>

Hope this helps :)

希望这可以帮助 :)

回答by Mike Goatly

You need to add a reference to the apache commons-pool2 library. I had the same problem in a Scala project - we were using sbt, so it was just a case of adding:

您需要添加对 apache commons-pool2 库的引用。我在 Scala 项目中遇到了同样的问题——我们使用的是 sbt,所以这只是一个添加的情况:

"org.apache.commons" % "commons-pool2" % "2.0"

As you're using Java, you might be using Maven, so I would expect it's probably more like this (untested - take it with a pinch of salt!):

当您使用 Java 时,您可能正在使用 Maven,所以我希望它可能更像这样(未经测试 - 加一点盐!):

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
    <version>2.0</version>
</dependency>

回答by Oleg Kuts

In case someone facing it due to migration from Spring Boot 1.5.x to 2.x.x here is threadthat explains it. Also please see this link

如果有人因为从 Spring Boot 1.5.x 迁移到 2.xx 而面临它,这里是解释它的线程。另请参阅此链接

Lettuce is now used instead of Jedis as the Redis driver when you use spring-boot-starter-data-redis. If you are using higher level Spring Data constructs you should find that the change is transparent.

We still support Jedis. Switch dependencies if you prefer Jedis by excluding io.lettuce:lettuce-core and adding redis.clients:jedis instead.

Connection pooling is optional and, if you are using it, you now need to add commons-pool2 yourself as Lettuce, contrary to Jedis, does not bring it transitively.

当您使用 spring-boot-starter-data-redis 时,现在使用 Lettuce 而不是 Jedis 作为 Redis 驱动程序。如果您使用更高级别的 Spring Data 构造,您应该会发现更改是透明的。

我们仍然支持 Jedis。如果您更喜欢 Jedis,请通过排除 io.lettuce:lettuce-core 并添加 redis.clients:jedis 来切换依赖项。

连接池是可选的,如果您正在使用它,您现在需要自己添加 commons-pool2,因为 Lettuce 与 Jedis 不同,它不会传递。