Is there an equivalient/similar action mapping xml configuration available for SpringMVC just as there is for Struts 2?
e.g. in a Struts2 app I have this:
<action name="index" class="homeAction">
<interceptor-ref name="myAppVarsBasic" />
<interceptor-ref name="defaultStack" />
<result name="input">/WEB-INF/jsp16/home.jsp</result>
<result name="userDisplay">/WEB-INF/jsp16/userDisplay.jsp</result>
<result name="changePassword" type="redirectAction" >passwordReset!changePass.do</result>
</action>
Is there a similar way to configure action mappings, redirects and to where with Spring MVC using xml config?
I'm teaching myself (with help of SO and Google) S2 to SpringMVC but find most resources seem to handle redirect directly from the action (or is that Controller in MVC?) e.g.:
return "redirect:index";
Spring MVC has xml based configuration, annotations, and JavaConfig. It has several namespaces in their xml config files. The most usable is
beansnamespace. There you can define your beans configuration. You can define a path in the bean'snameattribute or use@RequestMappingannotation.When Struts2 is integrated with Spring you can configure actions in
struts.xmland define beans for action classes in theapplicationContext.xml. Instead ofclassin the action config you just place a bean's id.In Spring MVC you can map request path to a method with
@RequestMappingannotation. It's similar like Struts1 mapped their actions. In the Spring MVC 4 It has also support for wildcards and regex to match the request path.Spring has also interceptors but they are just pointcuts in the AOP namespace. Of course you can use them in Spring config.
Results in Struts2 are just another actions that executes when the initial action ends. Spring MVC returns a
Viewobject with theModel. It can return a string, or another object, or nothing. The result in Spring MVC is what actually requested method returns. The result is handled by the view resolver. Spring MVC has many view resolves that you can configure as beans that are capable to handle a servlet dispatcher's request.One of them is
XmlViewResolverthat is similar to the Struts 2 action config. You can read more abour these beans on the Spring site. Using this resolver you define views viaviews.xmlthat you feed to this resolver as property and use the view names mapped to each JSP.