diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/CookieValue.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/CookieValue.java index 6af1c621dea..0eedccc7469 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/CookieValue.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/CookieValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,14 +22,18 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.core.annotation.AliasFor; + /** * Annotation which indicates that a method parameter should be bound to an HTTP cookie. - * Supported for annotated handler methods in Servlet and Portlet environments. + * + *

Supported for annotated handler methods in Servlet and Portlet environments. * *

The method parameter may be declared as type {@link javax.servlet.http.Cookie} * or as cookie value type (String, int, etc). * * @author Juergen Hoeller + * @author Sam Brannen * @since 3.0 * @see RequestMapping * @see RequestParam @@ -45,10 +49,18 @@ import java.lang.annotation.Target; public @interface CookieValue { /** - * The name of the cookie to bind to. + * Alias for {@link #name}. */ + @AliasFor(attribute = "name") String value() default ""; + /** + * The name of the cookie to bind to. + * @since 4.2 + */ + @AliasFor(attribute = "value") + String name() default ""; + /** * Whether the header is required. *

Default is {@code true}, leading to an exception being thrown diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java index 57490c5d2bd..5b3f22a957b 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodInvoker.java @@ -278,7 +278,7 @@ public class HandlerMethodInvoker { } else if (CookieValue.class.isInstance(paramAnn)) { CookieValue cookieValue = (CookieValue) paramAnn; - cookieName = cookieValue.value(); + cookieName = cookieValue.name(); required = cookieValue.required(); defaultValue = parseDefaultValueAttribute(cookieValue.defaultValue()); annotationsFound++; diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java index be22df6889f..aa724396615 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/AbstractCookieValueMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,7 +70,7 @@ public abstract class AbstractCookieValueMethodArgumentResolver extends Abstract private static class CookieValueNamedValueInfo extends NamedValueInfo { private CookieValueNamedValueInfo(CookieValue annotation) { - super(annotation.value(), annotation.required(), annotation.defaultValue()); + super(annotation.name(), annotation.required(), annotation.defaultValue()); } } diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/CookieValueMethodArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/CookieValueMethodArgumentResolverTests.java index 0d7309654d7..0181b63a5da 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/CookieValueMethodArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/CookieValueMethodArgumentResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -99,7 +99,7 @@ public class CookieValueMethodArgumentResolverTests { } public void params(@CookieValue("name") Cookie param1, - @CookieValue(value = "name", defaultValue = "bar") String param2, + @CookieValue(name = "name", defaultValue = "bar") String param2, String param3) { } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java index 4bab43c21b5..0e2cb272a85 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java @@ -1657,7 +1657,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl @RequestMapping("/myPath2.do") public void myHandle(@RequestParam("param1") String p1, @RequestParam("param2") int p2, - @RequestHeader("header1") long h1, @CookieValue("cookie1") Cookie c1, + @RequestHeader("header1") long h1, @CookieValue(name = "cookie1") Cookie c1, HttpServletResponse response) throws IOException { response.getWriter().write("test-" + p1 + "-" + p2 + "-" + h1 + "-" + c1.getValue()); } diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java index 427066408cf..cd18d1e959e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolverTests.java @@ -79,7 +79,7 @@ public class ServletCookieValueMethodArgumentResolverTests { } public void params(@CookieValue("name") Cookie cookie, - @CookieValue(value = "name", defaultValue = "bar") String cookieString) { + @CookieValue(name = "name", defaultValue = "bar") String cookieString) { } } \ No newline at end of file