title: Customizing Hybris accelerator storefront controllers in an addon
body: <p>I'm using <strong>Hybris 6.3</strong> and would like to follow the best practice of customizing the accelerator storefront controllers using an addon.  This is done to make upgrading to a newer storefront much easier.</p>
  
  <p>For example, the accelerator defines a Minicart controller similar to</p>
  
  <pre class="lang-java prettyprint-override"><code>package com.custom.storefront.controllers.misc;
  
  @Controller
  public class MiniCartController extends AbstractController
  {
      @RequestMapping(value = "/cart/miniCart/{totalDisplay:.*}", method = RequestMethod.GET)
      public String getMiniCart(@PathVariable final String totalDisplay, final Model model)
      {
          //default functionality
      }
  }
  </code></pre>
  
  <p>In my addon, I would like to map that same URL pattern to a new controller that will override the functionality.</p>
  
  <pre class="lang-java prettyprint-override"><code>package com.custom.storefrontaddon.controllers.misc;
  
  @Controller
  public class MyCustomMiniCartController extends AbstractController
  {
      @RequestMapping(value = "/cart/miniCart/{totalDisplay:.*}", method = RequestMethod.GET)
      public String getMiniCart(@PathVariable final String totalDisplay, final Model model)
      {
          //overriding functionality, different from the default accelerator storefront
      }
  }
  </code></pre>
  
  <p>This question has been asked <a href="https://stackoverflow.com/questions/46993565/how-can-customize-addons-in-hybris">here</a>, and the accepted advice was to do as follows:  </p>
  
  <ul>
  <li>In <em>addon-web-spring.xml</em>, override the controller bean like</li>
  </ul>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;bean name="miniCartController" class="com.custom.storefrontaddon.controllers.misc.MyCustomMiniCartController"/&gt;
  </code></pre>
  
  <ul>
  <li>In <em>addon-web-spring.xml</em>, add a <code>SimpleUrlHandlerMapping</code> like</li>
  </ul>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;
          &lt;property name="mappings"&gt;
              &lt;props&gt;
                  &lt;prop key="/cart/miniCart/**"&gt;miniCartController&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <ul>
  <li>The addon controller will now be called instead of the default accelerator controller for the target URL.</li>
  </ul>
  
  <h1>My Question</h1>
  
  <p>How does this mechanism work when the <a href="https://docs.spring.io/spring-framework/docs/4.3.x/spring-framework-reference/htmlsingle/#mvc-ann-requestmapping-31-vs-30" rel="nofollow noreferrer">Spring documentation</a> explicitly says that  </p>
  
  <blockquote>
    <p>There are also several things no longer possible:<br>
    - Select a controller first with a <code>SimpleUrlHandlerMapping</code> or <code>BeanNameUrlHandlerMapping</code> and then narrow the method based on <code>@RequestMapping</code> annotations.</p>
  </blockquote>
  
  <p>Spring is using <code>RequestMappingHandlerMapping</code> by default in the accelerator storefront, and in the addon we are introducing <code>SimpleUrlHandlerMapping</code>. I want to understand why this works, when every other forum post I've read says that you cannot override <code>@RequestMapping</code> URLs in a different controller, or you will get an exception thrown for the duplicate URL.</p>