Can _at_QueryParam be used in resource constructor along with Guice injection?

From: ycx4321 <>
Date: Sat, 30 Jan 2010 12:16:30 -0800


Is it possible to use @QueryParam in the resource constructor? In other
words, I found that I couldn't do this with Jersey integration of Guice:

public class MyResource {
   private final GuiceService myGuiceService;
   private final String query;

   public MyResource(@MyGuiceService GuiceService guiceServiceImpl,
                                     @QueryParam("q") String query)
      this.myGuiceService = guiceServiceImpl;
      this.query = query;

   public String hello() {
      return "hello";

When I ran it in Jersey, I got this error from Guice:
java.lang.ClassCastException: $java.lang.String$$FastClassByGuice$$473e3665
cannot be cast to

But the program would run fine if I change the resource definition to:

/** Shortened class definition for illustration */
public class MyResource {
    @QueryParam("q") String query;

    public MyResource(@MyGuiceService GuiceService guiceServiceImpl) {
         this.myGuiceService = guiceServiceImpl;

So why can't I put @QueryParam in the parameter list of the constructor? I
prefer the constructor injection to the field injection. I read about the
AssistedInjection in Guice but how do I use it in Jersey?