Spring mobile documentation suggest adding the following configuration:
<mvc:annotation-driven>
<mvc:argument-resolvers>
<beans:bean class="org.springframework.mobile.device.DeviceWebArgumentResolver" />
</mvc:argument-resolvers>
</mvc:annotation-driven>
to pass the current Device object as an argument to @Controller
methods.
Yet, one can use:
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
}
and bypass <mvc:annotation-driven>
configuration.
Then, how to add a DeviceWebArgumentResolver
programmatically?
Solution (Luciano):
@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addArgumentResolvers(
List<HandlerMethodArgumentResolver> argumentResolvers) {
// Adding Spring mobile argument resolvers
argumentResolvers.add(
new ServletWebArgumentResolverAdapter(
new DeviceWebArgumentResolver()));
argumentResolvers.add(
new ServletWebArgumentResolverAdapter(
new SitePreferenceWebArgumentResolver()));
}
// ...
}
DeviceHandlerMethodArgumentResolver
to support Java-based configuration. – Lindblad