Spring Framework : A Framework from SpringSource :: Spring with Struts2
Spring framework with Struts2 |
Like Struts, Spring can also function as an MVC implementation. Both frameworks have their merits and drawbacks, although most would agree that Struts is still king when it comes to MVC.
With so much momentum behind Struts, even development teams that would like to integrate features of the Spring framework don’t want to switch to Spring MVC. The good news is that you do not have to.
The Spring architecture allows you to connect Struts as your Web framework to Spring-based business and persistence layers. The end result is that you can have your cake and eat it too!
It will also provide you with a broad range of options for dealing with various scenarios. The details are as follows:
- Use Spring’s ActionSupport class to integrate Struts
- Override the Struts RequestProcessor with Spring’s DelegatingRequestProcessor
- Delegate Struts Action management to the Spring framework
Using Spring’s ActionSupport to integrate Struts is quick and easy but couples your Struts actions to the Spring framework. If you ever needed to port the application to a different framework you would need to rewrite the code. The second solution of delegating the RequestProcessor cleverly decouples your code, but it doesn’t necessarily scale well and may not last long if the Struts RequestProcessor is revised to a chain of command. The third approach is the best of the three: delegating Struts actions to the Spring framework results in decoupled code that lets you utilize Spring’s features (such as logging interceptors) in your Struts applications.
Loading the application context
you need to use the Spring ContextLoaderPlugin to load the Spring application context for the Struts ActionServlet. Simply add the plug-in to your struts-config.xml file as you would any other plug-in, as shown here
<plug-in className="org.springframework.Web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/MyBeans.xml"/>
</plug-in>
Click Below to download the Examples
Recent Comments