Apache Struts 2 Documentation > Home > FAQs > How can we create our Action objects from the Spring configuration
Added by Ted Husted, last edited by Don Brown on Dec 29, 2006  (view change)

Each time

  1. Configure the bean in the Spring configuration file (usually applicationContext.xml)
  2. Change the "class" attribute in the struts.xml action mapping to use the bean name defined in Spring instead of the actual class name.

One time

  1. Add struts.objectFactory = spring to the struts.properties.
  2. Add the Spring listener to the web.xml.
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
  3. Add the Spring configiuration file to the WEB-INF folder.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans default-autowire="autodetect">
        <bean id="personManager" class="com.acme.PersonManager"/>
        ...
    </beans>

For details, see Initializing Actions from Spring.