Results 1 to 3 of 3

Thread: Spring managed Struts Actions

  1. #1
    Join Date
    Apr 2005
    Posts
    18

    Default Spring managed Struts Actions

    Hi,

    I'm putting togther a proof of concept to try to prove that converting our web-app to Spring 1.2 is a worthwhile investment. Anway, I'm having trouble making my Struts actions Spring managed, (note that it works fine if my struts actions extends ActionSupport).

    In order to make my struts actions Spring managed I have:
    1) defined the action-servlet.xml being:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>
    <bean name="/setup" class="MyAction">
    <property name="dao">
    <ref bean="dao"/>
    </property>
    </bean>
    </beans>

    2) added the following to struts-config.xml:
    <plug-in className="org.springframework.web.struts.ContextL oaderPlugIn">
    <set-property property="contextConfigLocation"
    value="/WEB-INF/action-servlet.xml, /WEB-INF/applicationContext.xml"/>
    </plug-in>

    3) Changed my struts-config.xml so that the actions point to DelegatingActionProxy, ie:

    <action path="/setup" name="setupForm" type="org.springframework.web.struts.DelegatingAct ionProxy" scope="request">
    <forward name="success" path="findings"></forward>
    </action>

    4) The outline of my struts action is:
    public class MyAction extends Action {

    private Dao dao;


    ...

    public ActionForward execute(...) {
    ...
    }

    public void setDao(Dao dao) {
    this.dao = dao;
    }


    However, when I start Tomcat I get the following stack trace:

    2005-07-05 16:27:30 StandardContext[/test]Loading Spring root WebApplicationContext
    2005-07-05 16:28:56 StandardContext[/test]Initializing WebApplicationContext for Struts ActionServlet 'action', module ''
    2005-07-05 16:29:23 StandardContext[/test]action: null
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name '/setup' defined in ServletContext resource [/WEB-INF/action-servlet.xml]: Can't resolve reference to bean 'dao' while setting property 'dao'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Can't resolve reference to bean 'sessionFactory' while setting property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: null
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'findingDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Can't resolve reference to bean 'sessionFactory' while setting property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: null
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.OutOfMemoryError: null
    java.lang.OutOfMemoryError

    2005-07-05 16:29:23 StandardContext[/test]Marking servlet action as unavailable
    2005-07-05 16:29:23 StandardContext[/test]Servlet /test threw load() exception
    javax.servlet.UnavailableException
    at org.apache.struts.action.ActionServlet.initModuleP lugIns(ActionServlet.java:1169)
    at org.apache.struts.action.ActionServlet.init(Action Servlet.java:473)
    at javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
    at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1029)
    at org.apache.catalina.core.StandardWrapper.load(Stan dardWrapper.java:862)
    at org.apache.catalina.core.StandardContext.loadOnSta rtup(StandardContext.java:4013)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4357)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1083)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:789)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1083)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:478)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:480)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:2313)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:556)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:287)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:425)

    2005-07-05 16:29:27 StandardContext[/balancer]org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRul e: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterR ule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingR ule: Redirect URL: http://jakarta.apache.org]]
    2005-07-05 16:29:28 StandardContext[/jsp-examples]ContextListener: contextInitialized()
    2005-07-05 16:29:28 StandardContext[/jsp-examples]SessionListener: contextInitialized()
    2005-07-05 16:29:28 StandardContext[/servlets-examples]ContextListener: contextInitialized()
    2005-07-05 16:29:28 StandardContext[/servlets-examples]SessionListener: contextInitialized()

  2. #2

    Default

    Can you show your /WEB-INF/applicationContext.xml also... seems like the nested exception is when its trying to resolve your dao, sessionfactory ,etc.

    Also the fact that you are getting an OutOfMemoryException is slightly odd / concerning.

  3. #3
    Join Date
    Apr 2005
    Posts
    18

    Default

    Mark,

    the out of memory was due to the session factory being created twice. So, I increased the heap size and removed the reference to applicationContext.xml from the struts-plugin so the hibernate session factory is only created once.


    many thanks!

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Spring Managed Struts Action
    By etnot in forum Web
    Replies: 4
    Last Post: Jul 26th, 2005, 12:57 PM
  3. Auto-injecting Struts Actions
    By steve_molitor in forum Web
    Replies: 0
    Last Post: Apr 21st, 2005, 04:03 PM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Replies: 10
    Last Post: Nov 2nd, 2004, 09:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •