Announcement Announcement Module
Collapse
No announcement yet.
Spring and Struts web.xml vs. struts-config.xml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring and Struts web.xml vs. struts-config.xml

    Hi,

    Just to clarify, there looks to be two ways of introducing Spring into an existing Struts app (Struts 1.1 in my case).

    The "traditional" approach appears to be via the ContextLoaderListener in web.xml:

    <listener>
    <description></description>
    <display-name>Spring ContextLoaderListener</display-name>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/fooContext.xml</param-value>
    </context-param>

    But there appears to be another way, as described in Spring in Action 2nd edition using the ContextLoaderPlugIn in struts-config.xml:

    <plug-in className="org.springframework.web.struts.ContextL oaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/fooContext.xml"/>
    </plug-in>

    Or have I misunderstood something? Is one approach recommended over the other now?

    Thanks,
    Andy
    Last edited by ayang_ca; Jul 4th, 2008, 02:35 PM.

  • #2
    Re: Spring and Struts web.xml vs. struts-config.xml

    Hi,

    I just tried your ways, but unfortunately, it failed. I did in two ways:

    1. I just remove spring listener from web.xml, when I restart tomcat, an exception will be thrown:

    18:12:54,312 FATAL StrutsSpringObjectFactory:67 - ********** FATAL ERROR STARTING UP STRUTS-SPRING INTEGRATION **********
    Looks like the Spring listener was not configured for your web app!
    Nothing will work until WebApplicationContextUtils returns a valid ApplicationContext.
    You might need to add the following to web.xml:
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>
    18:12:54,859 ERROR [/]:3639 - Exception starting filter struts2
    java.lang.NullPointerException
    at com.opensymphony.xwork2.spring.SpringObjectFactory .getClassInstance(SpringObjectFactory.java:188)
    at com.opensymphony.xwork2.config.providers.XmlConfig urationProvider.verifyResultType(XmlConfigurationP rovider.java:479)
    at com.opensymphony.xwork2.config.providers.XmlConfig urationProvider.addResultTypes(XmlConfigurationPro vider.java:450)
    at com.opensymphony.xwork2.config.providers.XmlConfig urationProvider.addPackage(XmlConfigurationProvide r.java:407)
    at com.opensymphony.xwork2.config.providers.XmlConfig urationProvider.loadPackages(XmlConfigurationProvi der.java:239)
    at org.apache.struts2.config.StrutsXmlConfigurationPr ovider.loadPackages(StrutsXmlConfigurationProvider .java:111)
    at com.opensymphony.xwork2.config.impl.DefaultConfigu ration.reload(DefaultConfiguration.java:152)
    at com.opensymphony.xwork2.config.ConfigurationManage r.getConfiguration(ConfigurationManager.java:52)
    at org.apache.struts2.dispatcher.Dispatcher.init_Prel oadConfiguration(Dispatcher.java:395)
    at org.apache.struts2.dispatcher.Dispatcher.init(Disp atcher.java:452)
    at org.apache.struts2.dispatcher.FilterDispatcher.ini t(FilterDispatcher.java:201)
    at org.apache.catalina.core.ApplicationFilterConfig.g etFilter(ApplicationFilterConfig.java:221)
    at org.apache.catalina.core.ApplicationFilterConfig.s etFilterDef(ApplicationFilterConfig.java:302)
    at org.apache.catalina.core.ApplicationFilterConfig.< init>(ApplicationFilterConfig.java:78)
    at org.apache.catalina.core.StandardContext.filterSta rt(StandardContext.java:3635)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4222)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1014)
    at org.apache.catalina.core.StandardHost.start(Standa rdHost.java:736)
    at org.apache.catalina.core.ContainerBase.start(Conta inerBase.java:1014)
    at org.apache.catalina.core.StandardEngine.start(Stan dardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(Sta ndardService.java:448)
    at org.apache.catalina.core.StandardServer.start(Stan dardServer.java:700)
    at org.apache.catalina.startup.Catalina.start(Catalin a.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:64)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:615)
    at org.apache.catalina.startup.Bootstrap.start(Bootst rap.java:295)
    at org.apache.catalina.startup.Bootstrap.main(Bootstr ap.java:433)
    2008-7-7 18:12:55 org.apache.catalina.core.StandardContext start

    2. I tried to add plugin element, but got compiler error.

    That's all.

    Comment

    Working...
    X