Hello :).
I would really love to use IoC in my struts project. Has anyone any
experiences with integration Struts and Guice.
Mine are unfortunatelly unpleasant.
I would appreciate any help. I looked at this problem for a couple of days
but I guess I can't handle this myself. I wrote on guice groups twice, but
no one answered me. I even wrote to Bob Lee, which is the google guy who
build it, but I got no answer. I guess this group is my last hope, if I
wont find help here I guess I am gonna abandon Guice.
1. The documentation is really poor, I dont even know very well how to
start. This is what I did:
a) I added this libs to my tomcat/common/lib directory
guice-struts2-plugin-1.0.jar
guice-1.0.jar
guice-servlet-1.0.jar
b) I edited my struts.xml by adding this lines
<constant name="struts.objectFactory" value="guice" /> (this line may be
redundand so I tried with and without it)
<constant name="guice.module" value="gguice.GuiceModule" />
(I made sure the spelling is correct and tried different names and
packages)
c) I added in web.xml this filter (I tried both with this filter and
without it and with the same poor result)
<filter>
<filter-name>guice</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>guice</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
d)
I created class in package gguice
public class GuiceModule extends AbstractModule{
/** Creates a new instance of GuiceModule */
public GuiceModule() {
}
@Override
protected void configure() {
bind(CatalogService.class).to(CatalogDAO.class);
}
}
The same happens when I just implement Module interface.
So I annotate method in my action
@Inject
public void setCatalogService(CatalogService catalogService) {
this.catalogService = catalogService;
}
And I get the following message (this is the most important part I
guess):
Caused by: java.lang.RuntimeException:
java.lang.ClassNotFoundException: gguice.GuiceModule
at
com.google.inject.struts2.GuiceObjectFactory.setModule(GuiceObjectFactory.java:
58)
... 54 more
Caused by: java.lang.ClassNotFoundException: gguice.GuiceModule
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at
com.google.inject.struts2.GuiceObjectFactory.setModule(GuiceObjectFactory.java:
54)
... 54 more
I dont understand how Guice can claim it can't find GuiceModule class
while it is there.
And one more thing, when I annotated my class with
@ImplementedBy(CatalogDAO.class)
public interface CatalogService
and I deleted from struts.xml the line
<constant name="guice.module" value="gguice.GuiceModule" />
everything works fine. (Using only annotations which are available works
fine, but it is limiting I guess). This might suggest that all the
libraries and configuration should be correct?
--
Kind regards,
Łukasz Łapiński
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]