Configuring Stripes-Guice 3.x

Basic

Configure your web.xml to use the GuiceContextListener provided in Stripes-Guice.

<listener>
    <listener-class>
        com.silvermindsoftware.sg.context.GuiceContextListener
    </listener-class>
</listener>
                        

After the listener is configured add a context-param named Guice.Modules and provide a comma-delimited fully qualified guice module class names.

                    
<context-param>
    <param-name>Guice.Modules</param-name>
    <param-value>com.myapp.guice.MyServiceModule,com.myapp.guice.MyWebModule</param-value>
</context-param>
                    
                    

Finally you need to configure stripes to make use of the GuiceActionResolver, GuiceActionBeanContextFactory, and GuiceRuntimeConfiguration. This will provide your ActionBeans, ActionBeanContext, Interceptors, and ConfigurableComponents with full Guice constructor and member injection support. All you need to do is add the following configurations to Stripes and annotate your classes as you would any other Guice injectable class.

NOTE: If you already have an implementation of these classes you can change the classes your implementation extend to extend the Stripes-Guice implementations. This is not an ideal approach. But, it will maintain the most consistent feature support across Stripes 1.5 and 1.6.

<filter>
    <display-name>Stripes Filter</display-name>
    <filter-name>StripesFilter</filter-name>
    <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
    ...
    <init-param>
        <param-name>Configuration.Class</param-name>
        <param-value>com.silvermindsoftware.sg.config.GuiceRuntimeConfiguration</param-value>
    </init-param>
    <init-param>
        <param-name>ActionBeanContextFactory.Class</param-name>
        <param-value>com.silvermindsoftware.sg.controller.GuiceActionBeanContextFactory</param-value>
    </init-param>
    <init-param>
        <param-name>ActionResolver.Class</param-name>
        <param-value>com.silvermindsoftware.sg.controller.GuiceActionResolver</param-value>
    </init-param>
    <init-param>
        <param-name>Extension.Packages</param-name>
        <param-value>com.silvermindsoftware.sg.extension</param-value>
    </init-param>
    ...
</filter>
                    

Implement Custom GuiceInjectorFactory

If you do not want to use the Default means of creating the Guice Injector you can override it by implementing your own GuiceInjectorFactory.
First, write your own implementation of the GuiceInjectorFactory. In the following example the implementation hard codes the Modules instead of using the default mechanism of Guice.Modules context-param. It also passes the created injector into a static context that can be exposed to non-stripes components. This should be an unusual case. But, the need may arise.
public class CustomInjectorFactory implements GuiceInjectorFactory {
    @Override
    public Injector getInjector(ServletContext servletContext) {
        Injector injector = Guice.createInjector(new MyServiceModule(), new MyWebModule());
        SomeStaticContextToExposeToSomewhereElse.init(injector);
        return injector;
    }
}
                
Next and finally, specify your custom implementation in a GuiceInjectorFactory.Class context-param.
                
<context-param>
    <param-name>GuiceInjectorFactory.Class</param-name>
    <param-value>com.myapp.guice.CustomInjectorFactory</param-value>
</context-param>