Announcement Announcement Module
Collapse
No announcement yet.
Using spring with struts and plain servlets Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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
      --

      Comment

      Working...
      X