Apache Struts 2 Plugin Registry > 2008 > 03 > 09 > Resin-IoC 3.1.5 plugin
Added by Scott Ferguson, last edited by Scott Ferguson on Mar 09, 2008

Resin 3.1.5 now contains a Struts2 ObjectFactory plugin, enabling Resin-IoC capabilities for any Struts2 action. Documentation is available at http://wiki.caucho.com/Struts2.

Resin-IoC capabilities for Struts2 actions

  • WebBeans dependency injection with @In, @Named, etc.
  • Scoped components including @SessionScoped, @RequestScoped, @ApplicationScoped
  • EJB annotations like @TransactionAttribute
  • Interception using @InterceptorType
  • WebBeans event listening with @Observes

Adding the Object Factory

To enable Resin-IoC with Struts, you'll need to copy the resin/ext/resin-support.jar to either WEB-INF/lib or resin/ext-webapp. And you'll need to create or modify WEB-INF/classes/struts.properties as follows:

# Tell struts to ask Resin for new action instances
 struts.objectFactory = com.caucho.xwork2.ResinObjectFactory

Implementation details

public class ResinObjectFactory extends ObjectFactory {
    private WebBeansContainer _webBeans = WebBeansContainer.create();

   @Override
   public Object buildBean(Class clazz, Map extraContext)
   {
     return _webBeans.getObject(clazz);
   }
 }