playframework / play-plugins

CachePlugin
444 stars 161 forks source link

JedisPool injection giving exception for Play with java 2.4.x #156

Open guptamitesh opened 9 years ago

guptamitesh commented 9 years ago

Hi, I am using play for java 2.4.x. I followed all the steps to step the redis plugin and it worked out pretty well. However, while using the injected dependency for jedis pool:

import javax.inject.Inject; import redis.clients.jedis.JedisPool; @Inject JedisPool jedisPool;

I am getting the following error:

Unexpected exception

ProvisionException: Unable to provision, see the following errors:

1) Could not find a suitable constructor in redis.clients.jedis.JedisPool. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private. at redis.clients.jedis.JedisPool.class(JedisPool.java:10) while locating redis.clients.jedis.JedisPool for field at controllers.AdminLoginController.jedisPool(AdminLoginController.java:22) while locating controllers.AdminLoginController for parameter 13 at router.Routes.(Routes.scala:76) while locating router.Routes while locating play.api.inject.RoutesProvider while locating play.api.routing.Router

1 error at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025) ~[guice-4.0.jar:na] at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051) ~[guice-4.0.jar:na] at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:321) ~[play_2.11-2.4.0.jar:2.4.0] at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:316) ~[play_2.11-2.4.0.jar:2.4.0] at play.api.Application$class.routes(Application.scala:111) ~[play_2.11-2.4.0.jar:2.4.0] at play.api.DefaultApplication.routes(Application.scala:240) ~[play_2.11-2.4.0.jar:2.4.0] at play.api.Play$.start(Play.scala:89) ~[play_2.11-2.4.0.jar:2.4.0] at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:156) ~[play-server_2.11-2.4.0.jar:2.4.0] ... 15 common frames omitted

ronaldwidha commented 9 years ago

I'm getting the same issue too. I can see that the plugin is based on Jedis 2.4.2 which doesn't have a zero-argument constructor. 2.7 and above have that. I suspect this isn't the root issue though. It almost look as if I may have not configured the redis.host or url properly so that it doesn't get injected through. Is this correct?

ronaldwidha commented 9 years ago

I'm hitting my head against a wall, cannot seem to work out the solution. Any ideas what we may have done wrong? or is it a genuine bug?

ronaldwidha commented 9 years ago

Worked out what it is for me. readme.md is outdated. the module version is 2.4.1 not 2.4.0

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs,
  "com.typesafe.play.modules" %% "play-modules-redis" % "2.4.1"
)

tested on Play 2.4.2

MiteshSharma commented 9 years ago

nice, it worked fine with 2.4.1 play-module-redis. Are you able to get JedisPool injected in Akka Actor or in model class? JedisPool injection is working only for controller class.

ronaldwidha commented 9 years ago

@MiteshSharma yes I get that to work, see this post for more info