-
Jun 1st, 2009, 12:02 PM
#1
Can SPRING MVC and STRUTS coexist in the same web application?
I am relatively new to SPRING and am a newbie to this forum. I need assistance with the following dilema:
I inherited a web application that utilizes the following frameworks: STRUTS, SPRING and iBATIS.
This web application utilizes STRUTS actions instead of SPRING controllers. The application contexts are loaded via a STRUTS plug-in in the struts-config.xml (STRUTS-SPRING integration) as opposed to the SPRING ContextLoaderListener in the web.xml:
<plug-in className="org.springframework.web.struts.ContextL oaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/dataAccessContext-jta.xml /WEB-INF/applicationContext.xml /WEB-INF/action-servlet.xml"/>
</plug-in>
Now I have a few new features that I'd like to implement via new modules and I'd prefer to use SPRING MVC for the web tier exclusively. Preliminary analysis led me to conclude that to replace existing STRUTS web tier with SPRING MVC would be too time consuming. So, I would very much prefer to keep the existing functionality in tact (STRUTS web tier). I tried to load the above contexts with a combination of both the ContextLoaderListener and the struts ContextLoaderPlugin to no avail - some to the contexts were getting loaded twice which in turn would break SPRING Timer Task feature.
What is the best way to go about doing this [writing a SPRING MVC new module without negatively impacting the exsiting STRUTS-SPRING modules]?
-
Jun 16th, 2009, 08:30 PM
#2
OK, I was able to figure this out a while ago, and moved on to other work....but here is a solution.
I used the DispatcherServlet (in the web.xml) to load the SPRING MVC resouces / relevant contexts and left the ContextLoaderPlugIn intact in the struts-config.xml which loads its own contexts for the STRUTS-SPRING integration. Made sure to keep bean names in the contexts unique.
------web.xml-------------------
...
<servlet>
<servlet-name>springDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dataAccessContext-xxx.xml, /WEB-INF/applicationContext-xxx.xml, /WEB-INF/springDispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
....
------web.xml-------------------
------struts-config.xml-------------------
....
<plug-in className="org.springframework.web.struts.ContextL oaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/dataAccessContext-yyy.xml /WEB-INF/applicationContext-yyy.xml /WEB-INF/action-servlet.xml"/>
</plug-in>
......
------struts-config.xml------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules