Hi, 

I'm still pretty new to Guice and I feel like I'm missing something very 
basic. I have an annotated object Foo that I need constructed with an 
injected dependency Bar. The Bar object requires some construction on my 
part that is usually handled with a Builder or Factory because of the 
parameters needed for it's contractor. My simple hypothetical example might 
look like the following: 

public class Foo {
   private Bar bar;

   @Inject
   public Foo( Bar bar ) { this.bar = bar; }
}

public class Bar {

   public Bar( int x, int y, int z ) {
      // Bar is initialized via the parameters passed to this constructor. 
No default constructor provided. Normally a builder knows how to construct 
Bar, but I want Guice to do it.
   }
}

Now here is my Module: 

public class FooModule implements Module
{
   public void configure(final Binder binder)
   {
      binder.bind(Foo.class);
   }
      
   @Provides
   public Bar provideBar() {
      return new Bar( 1, 2, 3 );
   }   
}

The problem is that when I start up my app, I get the following error: 

SEVERE: Exception sending context initialized event to listener instance of 
class 
org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener

java.lang.RuntimeException: Unable to find a public constructor for class 
Foo

at 
org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory.registered(
POJOResourceFactory.java:35)

at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(
ResourceMethodRegistry.java:120)

at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(
ResourceMethodRegistry.java:106)

at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(
ResourceMethodRegistry.java:83)

at org.jboss.resteasy.core.ResourceMethodRegistry.addPerRequestResource(
ResourceMethodRegistry.java:72)


It appears to me that it is trying to locate a default no-args constructor 
and is ignoring the constructor in Foo that takes a Bar as a parameter. And 
finally, it doesn't appear to now how to map that to the @Provides defined 
in the module that builds the object when requested. 


Am I missing something? Could this simply be a problem in the Resteasy 
Guice implementation? Or is it just something basic about Guice that I'm 
not understanding? All the examples I've downloaded and scanned seem to 
always use very simple objects with default constructors. I know there's a 
way to do this. I've tried adding @Named("Bar") to my @Provides method and 
the corresponding @Inject method parameter. Still does not work.


Any help would be greatly appreciated.


Thanks,


Michael

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to