I'm trying to integrate Guice 3 into my Struts application.
This is what I did :
Interface:
public interface PersonDAO{
void addPerson(String username);
}
Implementation:
@Singleton
public Class PersonDAOImpl implements PersonDAO{
void addPerson(String username){
// Implementation
}
}
I created the Guice module :
public class ServiceInjector extends AbstractModule {
@Override
protected void configure() {
bind(PersonDAO.class).to(PersonDAOImpl.class);
}
}
Then I use it like this in my Action:
@Inject
private PersonDAO personDAO;
The problem is that personDAO is always null.
Question : how can I properly integrate Guice to my application ?
Regards.
Never tried, but:
include in your project a Struts2 plugin written to interact with Guice (the Guice-Struts2 plugin);
for example, with Guice 4 and Maven, in your pom.xml it would be:
Then, in your struts.xml, specify that the ObjectFactory is
guice:It should be enough.