SHARE
TWEET

Untitled

a guest Feb 20th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Retention(RetentionPolicy.RUNTIME)
  2. @Target(ElementType.PARAMETER)
  3. public @interface Version {
  4. }
  5.      
  6. public class HeaderVersionArgumentResolver implements HandlerMethodArgumentResolver {
  7.  
  8. @Override
  9. public boolean supportsParameter(MethodParameter methodParameter) {
  10.     return methodParameter.getParameterAnnotation(Version.class) != null;
  11. }
  12.  
  13. @Override
  14. public Object resolveArgument(
  15.   MethodParameter methodParameter,
  16.   ModelAndViewContainer modelAndViewContainer,
  17.   NativeWebRequest nativeWebRequest,
  18.   WebDataBinderFactory webDataBinderFactory) throws Exception {
  19.  
  20.     HttpServletRequest request
  21.       = (HttpServletRequest) nativeWebRequest.getNativeRequest();
  22.  
  23.     return request.getHeader("Version");
  24. }
  25. }
  26.      
  27. @Configuration
  28. public class WebConfig implements WebMvcConfigurer {
  29.  
  30. @Override
  31. public void addArgumentResolvers(
  32.   List<HandlerMethodArgumentResolver> argumentResolvers) {
  33.     argumentResolvers.add(new HeaderVersionArgumentResolver());
  34. }
  35. }
  36.      
  37. public ResponseEntity findByVersion(@PathVariable Long id, @Version String version)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top