1

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.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
picard
  • 11
  • 1

1 Answers1

0

Never tried, but:

  1. 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:

    <dependency>
        <groupId>com.google.inject.extensions</groupId>
        <artifactId>guice-struts2</artifactId>
        <version>4.1.0</version>
    </dependency>
    
  2. Then, in your struts.xml, specify that the ObjectFactory is guice:

    <constant name="struts.objectFactory" value="guice" />
    

It should be enough.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243