Using Jedis pool in JAX-RS app running in Quarkus native results in ClassNotFoundException: org.apache.commons.pool2.impl.DefaultEvictionPolicy

落爺英雄遲暮 提交于 2020-06-28 03:54:28

问题


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);

However I'm hitting following error:

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?


回答1:


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
  }
]

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.



来源:https://stackoverflow.com/questions/61797951/using-jedis-pool-in-jax-rs-app-running-in-quarkus-native-results-in-classnotfoun

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!