title: Struts 2 migration to spring mvc
body: <p>I'm in the very early stages of migrating a Struts 2 application to the spring mvc framework. I've already added several spring modules to the project including spring core, spring security and now I'll be trying to move off of struts in favor of spring mvc.</p>
  
  <p>I'm running into difficulties though - I'm trying to re-map some of my struts actions to beans. Here's an example :</p>
  
  <p>I have an action configured in my struts.xml file :</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;package name="default" extends="struts-default"&gt;
      &lt;result-types&gt;
              &lt;result-type name="json" class="org.apache.struts2.json.JSONResult" /&gt;
      &lt;/result-types&gt;
      ...
      &lt;action name="tools" class="com.carfax.pb.dashboard.processing.action.RerunEventsAction" method="getAllRerunEvents"&gt;
          &lt;result name="success"&gt;/WEB-INF/jsp/tools/home.jsp&lt;/result&gt;
      &lt;/action&gt;
      ...
  &lt;/package&gt;
  </code></pre>
  
  <p>So basically I have a tools.home jsp page which is the view for the action defined above it. I've created a controller class for this view (basically just took the implementation out of the action and moved it into a groovy controller class) :</p>
  
  <pre class="lang-java prettyprint-override"><code>@Controller
  @RequestMapping("/tools")
  class RerunEventsController {
  
  ...
  
      public String getAllRerunEvents() {
  
          ...
          return ActionSupport.SUCCESS;
      }    
  
  
  ...
  }
  </code></pre>
  
  <p>Now I'm trying to figure out how to wire up these two and that's where I'm having difficulties.</p>
  
  <ol>
  <li><p>I don't know how to make struts defer from the mapping defined in my struts.xml (I still want the remaining struts actions to be supported as I'll be moving the actions into controllers one by one.</p></li>
  <li><p>I don't know how to correctly configure the mapping from namespace to controller to view.</p></li>
  </ol>
  
  <p>Here's what I tried -</p>
  
  <p>web.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;servlet&gt;
      &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;
          org.springframework.web.servlet.DispatcherServlet
      &lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/PBDashboard/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>servlet.xml:</p>
  
  <p>// Spring should automatically find my controller as it exists inside this package</p>
  
  <pre><code>&lt;context:component-scan base-package="com.carfax.pb.dashboard.processing.action" /&gt;
  
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix"&gt;
          &lt;value&gt;/WEB-INF/jsp/&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="suffix"&gt;
          &lt;value&gt;.jsp&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>My web.xml has both a Struts2 filter and filter mapping set up as follows :</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;filter&gt;
      &lt;filter-name&gt;struts2&lt;/filter-name&gt;
      &lt;filter-class&gt;org.apache.struts2.dispatcher.FilterDispatcher&lt;/filter-class&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
    &lt;filter-name&gt;struts2&lt;/filter-name&gt;
    &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>When I navigate to appname/tools I get a struts error saying that "There is no Action mapped for namespace / and action name tools"</p>
  
  <p>This is obviously correct but I feel like I've set up a mapping that spring mvc should pick up.</p>
  
  <p>Could anyone point me to some information regarding how to correctly do this / be even nicer and point out my mistakes?</p>