Struts2, or more precisely XWork, uses an early version of Guice.
I was wondering about doing the same thing on a current project, and my
initial thought was that you would need to define the beans being
injected via the struts.xml configuration file or to provide a way to
supply the managed beans in to the Guice container. I'm not sure that
it will automatically find annotation on application code.
Bob?
/Ian
Will Smith wrote:
Hi, I have an action that I've been injecting with Guice. I just noticed
that there is an @Inject annotation defined in
com.opensymphony.xwork2.inject. I'm assuming that this allows you to use
struts 2 as the di provider. So I tried removing my
com.google.inject.*imports that bring in the @Inject annotation, to
see if struts would pick
this up. It didn't, and I get an error in my netbeans tomcat window. I
was
unable to find any @Singleton type annotation so that I could apply the
correct scope to my class being injected, so I left the Guice one.
Am I correct in assuming that the @Inject annotation provided by
struts2 is
to allow struts to do the di? If so, is there any documentation on this?
Also, while troubleshooting, I tried both specifiying Guice as the
objectFactory, and not specifying it. It didn't matter either way.
Thanks,
Will
This is the error:
1) Error at
com.bugnthecode.blog.actions.BlogService.<init>(BlogService.java
:32):
Could not find a suitable constructor in
com.bugnthecode.blog.actions.BlogService. Classes must have either one
(and
only one) constructor annotated with @Inject or a zero-argument
constructor.
1 error[s]
at
com.google.inject.BinderImpl.createInjector(BinderImpl.java:277)
at com.google.inject.Guice.createInjector(Guice.java:79)
at com.google.inject.Guice.createInjector(Guice.java:53)
at com.google.inject.Guice.createInjector(Guice.java:43)
at com.google.inject.struts2.GuiceObjectFactory.buildBean(
GuiceObjectFactory.java:101)
at com.opensymphony.xwork2.ObjectFactory.buildBean(
ObjectFactory.java:152)
at com.opensymphony.xwork2.ObjectFactory.buildBean(
ObjectFactory.java:141)
at com.opensymphony.xwork2.ObjectFactory.buildAction(
ObjectFactory.java:111)
at com.opensymphony.xwork2.DefaultActionInvocation.createAction(
DefaultActionInvocation.java:270)
at com.opensymphony.xwork2.DefaultActionInvocation.init(
DefaultActionInvocation.java:360)
at com.opensymphony.xwork2.DefaultActionInvocation.access$000(
DefaultActionInvocation.java:38)
at com.opensymphony.xwork2.DefaultActionInvocation$1.doProfiling(
DefaultActionInvocation.java:78)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(
UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.<init>(
DefaultActionInvocation.java:70)
at com.opensymphony.xwork2.DefaultActionInvocation.<init>(
DefaultActionInvocation.java:66)
at com.opensymphony.xwork2.DefaultActionProxy.prepare(
DefaultActionProxy.java:189)
at
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(
StrutsActionProxyFactory.java:41)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(
Dispatcher.java:497)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(
FilterDispatcher.java:421)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
ApplicationFilterChain.java:173)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(
MonitorFilter.java:368)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(
StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(
StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(
StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(
ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(
StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(
CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(
Http11Processor.java:869)
at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection
(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(
PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(
LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(
ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:619)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]