Results 1 to 3 of 3

Thread: Using spring with struts and plain servlets

  1. #1
    Join Date
    Apr 2005
    Posts
    6

    Default Using spring with struts and plain servlets

    Hi

    I've got a web application which uses both plain servlets and struts; and that causes me some headache.

    First I tried to strap up spring in struts-config.xml as described in http://struts.sourceforge.net/struts-spring/#usage. Then my servlets does'nt work. I used the WebApplicationContextUtils to get the application context, but only got null values from it. Appearently the servlet context in struts is not the same as used in plain servlets.

    Then I tried to strap up spring from web.xml. Now the DelegatingActionProxy, which delegates to and injects my actions, got cranky and gave me this exception:
    java.lang.IllegalStateException: Could not find ContextLoaderPlugIn's WebApplicationContext as ServletContext attribute [org.springframework.web.struts.ContextLoaderPlugIn .CONTEXT.] - did you register [org.springframework.web.struts.ContextLoaderPlugIn]?
    at org.springframework.web.struts.DelegatingActionUti ls.getRequiredWebApplicationContext(DelegatingActi onUtils.java:71)
    at org.springframework.web.struts.DelegatingActionPro xy.getWebApplicationContext(DelegatingActionProxy. java:136)
    at org.springframework.web.struts.DelegatingActionPro xy.getDelegateAction(DelegatingActionProxy.java:11 9)
    at org.springframework.web.struts.DelegatingActionPro xy.execute(DelegatingActionProxy.java:104)
    at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:484)
    at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:274)
    at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1482)
    at org.apache.struts.action.ActionServlet.doGet(Actio nServlet.java:507)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:697)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:810)

    I expect that setting up spring in both web.xml and struts-config.xml would not be a good idea.

    So I ended setting spring up from web.xml and manually using WebApplicationContextUtils to get access to spring beans from both plain servlets and struts. Why this work I don't know :-(.

    Does anyone know a better solution?

    have a nice day
    ThorÅgeEldby
    --

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Appearently the servlet context in struts is not the same as used in plain servlets.
    It should be the same. This is puzzling. Can you check that however you're loading Spring (listener or load-on-startup servlet) is actually being run by your server before Struts is started? You can turn on more verbose logging for this, for example through log4j config.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Apr 2005
    Posts
    6

    Default

    Quote Originally Posted by Rod Johnson

    It should be the same. This is puzzling. Can you check that however you're loading Spring (listener or load-on-startup servlet) is actually being run by your server before Struts is started? You can turn on more verbose logging for this, for example through log4j config.
    Origionally I thought that using both spring listener loading and struts spring plug-in would initiate two spring containers. Now I tried to declare it like that and everything worked .

    I guess I should declare the context config location only one place; and that should be in the listener. Is that correct?

    ThorÅge
    --

Similar Threads

  1. Spring Framework 1.1.3 released
    By Alef Arendsen in forum Announcements
    Replies: 0
    Last Post: Dec 12th, 2004, 12:10 PM
  2. Hivemind?
    By ndijkstra in forum Container
    Replies: 6
    Last Post: Sep 27th, 2004, 01:07 PM

Posting Permissions

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