Help! java.lang.NoSuchMethodError: redis.clients.jedis.JedisPool.<init>(Lorg/apache/commons/pool2/impl/GenericObjectPoolConfig..)

3,539 views
Skip to first unread message

Arvind Kalyan

unread,
Nov 17, 2015, 5:34:19 AM11/17/15
to Jedis
Hi, I'm getting the following Exception when trying to run a java webapp on an ec2 instance.. I have the following dependency added to pom.xml.

dependency>
   <groupId>redis.clients</groupId>
   <artifactId>jedis</artifactId>
   <version>2.4.2</version>
</dependency>

I have redis-server 3.0.5 installed as mentioned here: http://redis.io/download

I'm initializing the pool object by making this call: 
private static JedisPool pool = new JedisPool(new GenericObjectPoolConfig(), "localhost", 6379,0,null,5); and then use pool.getResource() and pool.returnResource()..
I also tried these: 
private static JedisPool pool = new JedisPool(new JsonPoolConfig(), "localhost", 6379,0,null,5);
private final JedisPool pool = new JedisPool("redis://localhost:6379");

Still no luck.

Everything is working fine in my local, but not in the remote server.
Is it happening because I have two conflicting jedis and redis versions?

Exception:

Nov 17, 2015 2:34:44 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet / threw load() exception
java.lang.NoSuchMethodError: redis.clients.jedis.JedisPool.<init>(Lorg/apache/commons/pool2/impl/GenericObjectPoolConfig;Ljava/lang/String;IILjava/lang/String;I)V
at com.xyz.core.web.RestController.<clinit>(RestController.java:53)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:121)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1045)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:949)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:505)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1267)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1084)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5027)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Marcos Lilljedahl

unread,
Nov 18, 2015, 12:23:15 PM11/18/15
to Jedis
Arvind, 


Jedis uses apache commons-pool2 in the background. I'd recommend to check that the proper commons-pool2 jar is being included in the webapp.

Marcos.

--
You received this message because you are subscribed to the Google Groups "Jedis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jedis_redis...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sushil Mittal

unread,
Nov 19, 2015, 4:23:23 AM11/19/15
to Jedis
I too have faced same problem some time back,Jedis uses apache commons-pool2 in the background but jedis jar doesn't includes apache commons-pool2 in it so you have to add it externally.

Arvind Kalyan

unread,
Nov 19, 2015, 5:46:14 AM11/19/15
to Jedis
Hi, 

Solved this issue!! Here is the solution in case anyone else faces this issue:

I was using webapp-runner jar to deploy this webapp. I changed it's version to the latest one. (7.0.35 to 8.0.24.1 at the time of this post, scope set to provided - because it's given in the command line when deploying)
Also, excluded the commons-pool2 used in redis 2.4.2 dependency, changed redis version to latest one, and added the latest commons-pool2 as a separate maven dependency. 

Changes here:

OLD:

         <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.4.2</version>
         </dependency>

NEW:

         <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.7.3</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-pool2</artifactId>
                </exclusion>
            </exclusions>
         </dependency>
         <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
            <version>2.4.2</version>
         </dependency>

Thanks! 



On Tuesday, November 17, 2015 at 4:04:19 PM UTC+5:30, Arvind Kalyan wrote:
Reply all
Reply to author
Forward
0 new messages