Ok thanks, let's take one example that doesn't work for me with
guice-persist. In fact I need to inject an entity manager into my realm so
that I can use JPA queries.

I don't know if you're familiar with guice-persist but it's normally quite
easy to use it by only adding a module (by the way, this new module extends
AbstractModule, so it's not a PrivateModule)
Here is the short doc :
http://code.google.com/p/google-guice/wiki/JPA

As ShiroWebModule doesn't extend ServletModule i can't use this code :
filter("/*").through(PersistFilter.class);
so I will use "MyInitializer" method described in the doc


So here is what I have in MyServletContextListener
******************
@Override
protected Injector getInjector() {
    Injector injector = Guice.createInjector(
        new JpaPersistModule("mydb"), 
        new MyShiroWebModule(servletContext), 
        new ShiroAopModule(),
        new myModule()
 );
    injector.getInstance(MyInitializer.class);
    return injector;
}
******************


in MyInitializer
******************
public class MyInitializer {
        @Inject MyInitializer(PersistService service) {
                service.start(); 
        }
}
******************


in my ShiroRealm
******************
public class MyShiroRealm extends AuthorizingRealm {

        @Inject EntityManager em; 
        
        @Override
        protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken
token) throws AuthenticationException {
        .....
        }

        @Override
        protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection
principals) {
        ...
        }
}
******************

in MyShiroWebModule
******************
protected void configureShiroWeb() {    
        bind(MyShiroRealm.class);
        bindRealm().to(MyShiroRealm.class).in(Singleton.class);
        expose(MyShiroRealm.class);
        ...
}
******************

So my problem is that the injection work for class located in MyModule which
is extending an AbstractModule but not for MyShiroRealm binded in
MySHiroWebModule.

Thanks in advance for your help.

--
View this message in context: 
http://shiro-user.582556.n2.nabble.com/Guice-shiro-jersey-tp6673315p6706207.html
Sent from the Shiro User mailing list archive at Nabble.com.

Reply via email to