title: Spring Mobile: how to add DeviceWebArgumentResolver programmatically?
body: <p>Spring mobile <a href="http://static.springsource.org/spring-mobile/docs/1.0.x/reference/htmlsingle/" rel="nofollow noreferrer">documentation</a> suggest adding the following configuration:</p>
  
  <pre><code>&lt;mvc:annotation-driven&gt;
      &lt;mvc:argument-resolvers&gt;
          &lt;beans:bean class="org.springframework.mobile.device.DeviceWebArgumentResolver" /&gt;
      &lt;/mvc:argument-resolvers&gt;
  &lt;/mvc:annotation-driven&gt;
  </code></pre>
  
  <p>to pass the current Device object as an argument to <code>@Controller</code> methods.</p>
  
  <p>Yet, one can use:</p>
  
  <pre><code>@EnableWebMvc
  @Configuration
  public class WebConfig extends WebMvcConfigurerAdapter {
  
  }
  </code></pre>
  
  <p>and bypass <code>&lt;mvc:annotation-driven&gt;</code> configuration. </p>
  
  <p>Then, how to add a <code>DeviceWebArgumentResolver</code> programmatically?</p>
  
  <p><strong>Solution (Luciano):</strong></p>
  
  <pre><code>@EnableWebMvc
  @Configuration
  public class WebConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addArgumentResolvers(
          List&lt;HandlerMethodArgumentResolver&gt; argumentResolvers) {
  
          // Adding Spring mobile argument resolvers
          argumentResolvers.add(
              new ServletWebArgumentResolverAdapter(
                  new DeviceWebArgumentResolver()));
  
          argumentResolvers.add(
              new ServletWebArgumentResolverAdapter(
                  new SitePreferenceWebArgumentResolver()));
  
      }
  
      // ...
  
  }
  </code></pre>