On 22.12.11 13:53, Stanton Sievers wrote:
Hi,

How is your UserDb class being injected?  Make sure it's not being
injected before the PropertiesModule, which by default is injected via the
web.xml.
The thing is I am not very comfortable with Guice injection mechanism.
So I do not know if it is injected or not. This I have currently

1. In web.xml (JPA module is after Properties)
      org.apache.shindig.common.PropertiesModule:
      org.apache.shindig.gadgets.DefaultGuiceModule:
      org.apache.shindig.social.core.config.SocialApiGuiceModule:
      org.apache.shindig.graaasp.jpa.spi.JPASocialModule:

2. In JPA I have explicit injection
bind(PersonService.class).to(PersonServiceDb.class).in(Scopes.SINGLETON);

3. In PersonServiceDb I import the class UserDb.java:
import org.apache.shindig.social.core.model.UserDb;

So, I believe it does not do any injection for UserDb this way.
Then the question is how do I inject UserDb or how do I pass the data from PropertiesModule
to my UserDb.java class.

If your class isn't being injected at all you can request a static
injection in an existing guice module (or your own).
requestStaticInjection(UserDb.class)
I tried to add it in JPASocialModule, but it does not seem to be working. The field CALLBACK_URL is still null.

I also prefer method injection to field injection for setting values.  I'm
not sure if one is preferred over the other in the broader community or
not.
Could you give a small example how you do it.

-Stanton



From:   Evgeny Bogdanov<evgeny.bogda...@epfl.ch>
To:     dev@shindig.apache.org,
Date:   12/22/2011 06:30
Subject:        Guice problem in persistence



Hi

I have small problem, maybe somebody can point out where it is.

I have this line in shindig.properties:
shindig.signing.global-callback-url=http://localhost:8080/gadgets/oauthcallback
I want to access it from my db class.

Properties file is read in PropertiesModule.java and Guice's Named
annotation is created with
Names.bindProperties(this.binder(), getProperties());

Then I try to access it as following in my UserDb.java class
    @Transient
    @Inject @Named("shindig.signing.global-callback-url") String
CALLBACK_URL;

For some reason, it is always null.
Could somebody explain why I can't do it? What is the workaround. I
don't want to read properties file again,
since it's done in PropertiesModule.java already.

Any suggestions?

Best
Evgeny



Reply via email to