Thanks for the tip Jayr. I got things working without using the
struts plugin from guice at all. I just wrote my own Struts 2 Object
factory and overwrote the buildbean method as follows:
public Object buildBean(Class clazz, Map<String, Object>
extraContext) {
return Struts2GuiceObjectFactory.injector.getInstance(clazz);
}
Basically, I just keep a static reference to my one guice injector
around and build the beans using that. I am still using the guice
servlet plugin to initialized guice in my web tier.
protected Injector getInjector() {
Injector injector =
GuiceInjectorHolder.getInjector().createChildInjector(
new ListenerModule(), ... other modules ....);
Struts2GuiceObjectFactory.setInjector(injector);
return injector;
}
The only annoying thing with this method is that when struts starts up
it validates that every action has a no arg constructor. If you use
constructor injection, this isn't the case. You can obviously add a
no arg constructor that throws an UnsupportedOperationException or use
method injection, but it is an annoyance I will try and work around
after I finish my immediate task and have some time to play with it.
Thanks again,
Scott
On Apr 11, 11:21 am, jMotta <[email protected]> wrote:
> Hi,
>
> I've had the same problem you're having and I solved by doing the follow:
>
> I've just put the guice-struts2-plugin 1.0 (it's pretty important that you
> use the 1.0)
> Then you put your objectFactory on struts as "guice" and setup the module:
>
> <constant name="struts.objectFactory" value="guice"/>
> <constant name="guice.module" value="com.test.ioc.MyModule"/>
>
> It doesn't need any configuration on web.xml, the struts will use
> guiceobjectfactory to instantiate the actions what enable the guice inject,
> but I couldn't use the newest versions of guice with the configurations that
> i've seen on internet and I think you are in the same position once you're
> using sitemesh, probably freemarket / velocity.
>
> If you want more information, feel free to e-mail me.
>
> Atenciosamente,
>
> *Jayr Motta*
> Software Developer
> *
> *
> I'm on
> BlackBeltFactory.com<http://www.blackbeltfactory.com/ui#!User/jmotta/ref=jmotta>
> !
>
>
>
>
>
>
>
> On Mon, Apr 11, 2011 at 12:17 PM, Sam Berlin <[email protected]> wrote:
> > The issues are closed as "Will not fix" or "Duplicate" because we're not
> > sure if the problem is fixable. If you're able to write some test cases &
> > patches and attach them to one of the issues, that would be very helpful.
> > Maybe it is fixable. I'm personally not too familiar with struts2 (and
> > don't use it at all), so I don't have much inclination or ability to fix
> > it.. but someone else probably does.
>
> > sam
>
> > On Mon, Apr 11, 2011 at 10:56 AM, Scott <[email protected]> wrote:
>
> >> Yup, I have the subclassed listener that gets my injector, and it is
> >> in web.xml.
>
> >> On Apr 11, 12:35 am, Michael <[email protected]> wrote:
> >> > Hi Scott,
>
> >> > Have you defined a listener which is a subclass of
> >> > GuiceServletContextListener in your web.xml ?
>
> >> > You could refer tohttp://
> >> code.google.com/p/google-guice/wiki/Struts2Integration
>
> >> --
> >> 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.
>
> > --
> > 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.
--
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.