在Quarkus本机中运行的JAX-RS应用程序中使用Jedis池会导致ClassNotFoundException:org.apache.commons.pool2.impl.DefaultEvictionPolicy [英] Using Jedis pool in JAX-RS app running in Quarkus native results in ClassNotFoundException: org.apache.commons.pool2.impl.DefaultEvictionPolicy

查看:244
本文介绍了在Quarkus本机中运行的JAX-RS应用程序中使用Jedis池会导致ClassNotFoundException:org.apache.commons.pool2.impl.DefaultEvictionPolicy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在以Quarkus纯模式运行的应用程序中使用JedisPool(在JVM模式下可以正常工作).
我已经禁用了池的JMX功能,该功能在纯模式下不可用,例如:

I'm trying to use JedisPool in application run in Quarkus native mode (works fine in JVM mode).
I've already disabled JMX feature of the pool, which is not avaliable in native mode, like this:

  JedisPoolConfig jedisConfiguration = new JedisPoolConfig();
  jedisConfiguration.setJmxEnabled(false);
  jedisPool = new JedisPool(jedisConfiguration, jedisURI);

但是我遇到以下错误:

2020-04-29 17:35:37,724 INFO  [test.StockQuote] (main) java.lang.IllegalArgumentException: Unable to create org.apache.commons.pool2.impl.EvictionPolicy instance of type org.apache.commons.pool2.impl.DefaultEvictionPolicy
    at org.apache.commons.pool2.impl.BaseGenericObjectPool.setEvictionPolicyClassName(BaseGenericObjectPool.java:662)
    at org.apache.commons.pool2.impl.BaseGenericObjectPool.setEvictionPolicyClassName(BaseGenericObjectPool.java:687)
    at org.apache.commons.pool2.impl.BaseGenericObjectPool.setConfig(BaseGenericObjectPool.java:235)
    at org.apache.commons.pool2.impl.GenericObjectPool.setConfig(GenericObjectPool.java:302)
    at org.apache.commons.pool2.impl.GenericObjectPool.<init>(GenericObjectPool.java:115)
    at redis.clients.jedis.util.Pool.initPool(Pool.java:45)
    ...
 Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool2.impl.DefaultEvictionPolicy
    at com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:60)
    at java.lang.Class.forName(DynamicHub.java:1197)

作为一个临时解决方案,我切换为创建直接连接而不是使用池,但仍在寻找使用池的可能性.

as a temporary solution, I switched to create direct connection instead of using pool, but still looking for possibility of using pool.

有什么建议或解决方法吗?

Any suggestions or workarounds?

推荐答案

好吧,我进一步挖掘了一下,并在以下页面上找到了有关Class.forName的更多信息:

Ok, I dug a little more and found this more info about Class.forName on these pages: Reflection on Substrate VM and Quarkus - Tips for writing native applications and found a solution via reflection-config.json file which contains:

[
  {
    "name" : "org.apache.commons.pool2.impl.DefaultEvictionPolicy",
    "allDeclaredConstructors" : true,
    "allPublicConstructors" : true,
    "allDeclaredMethods" : true,
    "allPublicMethods" : true,
    "allDeclaredFields" : true,
    "allPublicFields" : true
  }
]

您还需要在application.properties文件中添加以下行:

You need also add following line to your application.properties file:

quarkus.native.additional-build-args =-H:ReflectionConfigurationFiles=reflection-config.json

然后我的应用程序成功运行.

Then my application runs successfully.

这篇关于在Quarkus本机中运行的JAX-RS应用程序中使用Jedis池会导致ClassNotFoundException:org.apache.commons.pool2.impl.DefaultEvictionPolicy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆