본문 바로가기

emotional developer/detect-Java

[spring] device detction interceptor - DeviceResolverHandlerInterceptor

http://docs.spring.io/spring-mobile/docs/current/reference/html/device.html


유용햇!

DeviceResolverHandlerInterceptor

Spring Mobile ships with a HandlerInterceptor that, on preHandle, delegates to a DeviceResolver. The resolved Device is indexed under a request attribute named 'currentDevice', making it available to handlers throughout request processing.

To enable, add the DeviceResolverHandlerInterceptor to the list of interceptors defined in your DispatcherServlet configuration:

<interceptors>
  <!-- On pre-handle, resolve the device that originated the web request -->
  <bean class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor" />
</interceptors>
                    

Alternatively, you can add the DeviceResolverHandlerInterceptor using Spring's Java-based container configuration:

@Bean
public DeviceResolverHandlerInterceptor deviceResolverHandlerInterceptor() {
    return new DeviceResolverHandlerInterceptor();
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(deviceResolverHandlerInterceptor());
}
                    


반응형