I did a little more study,

The javadoc says that you must register a PersistFilter for each
module that contains a JPA Module, and to do this you must also create
more than one Servlet module, so we have two servlet module for the
two db, and one more for the Struts2 filter registration.

Nevertheless I did so, but then I can't find the EntityManager
(normally created by the PersistFilter!!!), this is because it seams
that when you have more than one servlet modules only the filters in
the last one get fired (I tested this in practice) and my last one is
the Struts2 one...

Then I found someone using PersistFilter (but it seems useless, I have
the last version of code withot it) but also an eager singleton
startup class... and this seem to work, at least in my very simple
environment.

I'm still doing more tests but this is the last version of my
listener:

public class Struts2DemoListener extends GuiceServletContextListener {

        public Injector getInjector() {
                return Guice.createInjector(new Struts2GuicePluginModule(),
                                new PrivateModule() {
                                        protected void configure() {
                                                install(new 
MyServletModule01());
                                                
expose(UserRegistryService.class);
                                        }
                                },
                                new PrivateModule() {
                                        protected void configure() {
                                                install(new 
MyServletModule02());
                                                expose(AccessLogService.class);
                                        }
                                }
                        );
        }

        class MyServletModule01 extends ServletModule {
                @Override
                protected void configureServlets() {
                        install(new JpaUserRegistryServiceModule());
                        bind(JPAInitializer.class).asEagerSingleton();
                }
        }

        class MyServletModule02 extends ServletModule {
                @Override
                protected void configureServlets() {
                        install(new JpaAccessLogServiceModule());
                        bind(JPAInitializer.class).asEagerSingleton();
                        
bind(StrutsPrepareAndExecuteFilter.class).in(Singleton.class);
                        filter("/*").through(AccessLogFilter.class);
                        
filter("/*").through(StrutsPrepareAndExecuteFilter.class);
                }
        }

        @Singleton
        static class JPAInitializer {
                @Inject
                public JPAInitializer(final PersistService service) {
                        service.start();
                }
        }
}

I don't like this solution a lot because it doesn't use the
PersistFilter... but it seems to work...

Now I started to use the JPA support inside a servlet filter
(AccessLogFilter), there I can run queryes but I cannot commit
changes, I marked the method as Transactional but I cannot have the
changes committed on the DB, every change in the Action classes get
commited!!!!

On 6 Giu, 15:15, bklough <[email protected]> wrote:
> https://groups.google.com/d/topic/google-guice/qYTNDJDoQU4/discussion
>
> Might help.

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to