问题
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