diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/SessionAttributes.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/SessionAttributes.java index fce8db6e7d54bbb88ab858bdc30b498cb55ded43..4e45978eccbfe238e9d3fc580ae019181a866f85 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/SessionAttributes.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/SessionAttributes.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. @@ -23,11 +23,14 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.core.annotation.AliasFor; + /** - * Annotation that indicates the session attributes that a specific handler - * uses. This will typically list the names of model attributes which should be + * Annotation that indicates the session attributes that a specific handler uses. + * + *
This will typically list the names of model attributes which should be * transparently stored in the session or some conversational storage, - * serving as form-backing beans. Declared at the type level, applying + * serving as form-backing beans. Declared at the type level, applying * to the model attributes that the annotated handler class operates on. * *
NOTE: Session attributes as indicated using this annotation @@ -44,11 +47,12 @@ import java.lang.annotation.Target; * generic {@link org.springframework.web.context.request.WebRequest} interface. * *
NOTE: When using controller interfaces (e.g. for AOP proxying), - * make sure to consistently put all your mapping annotations - such as - * {@code @RequestMapping} and {@code @SessionAttributes} - on + * make sure to consistently put all your mapping annotations — + * such as {@code @RequestMapping} and {@code @SessionAttributes} — on * the controller interface rather than on the implementation class. * * @author Juergen Hoeller + * @author Sam Brannen * @since 2.5 */ @Target({ElementType.TYPE}) @@ -58,18 +62,28 @@ import java.lang.annotation.Target; public @interface SessionAttributes { /** - * The names of session attributes in the model, to be stored in the - * session or some conversational storage. - *
Note: This indicates the model attribute names. The session attribute - * names may or may not match the model attribute names; applications should - * not rely on the session attribute names but rather operate on the model only. + * Alias for {@link #names}. */ + @AliasFor(attribute = "names") String[] value() default {}; /** - * The types of session attributes in the model, to be stored in the - * session or some conversational storage. All model attributes of this - * type will be stored in the session, regardless of attribute name. + * The names of session attributes in the model that should be stored in the + * session or some conversational storage. + *
Note: This indicates the model attribute names. + * The session attribute names may or may not match the model attribute + * names. Applications should therefore not rely on the session attribute + * names but rather operate on the model only. + * @since 4.2 + */ + @AliasFor(attribute = "value") + String[] names() default {}; + + /** + * The types of session attributes in the model that should be stored in the + * session or some conversational storage. + *
All model attributes of these types will be stored in the session,
+ * regardless of attribute name.
*/
Class>[] types() default {};
diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java
index 1848a0001ccc57198ee284fbbdbe8fb1a594f955..9fd25c014f79ca3b0dcf05052918f7534445bf5f 100644
--- a/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.java
+++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/support/HandlerMethodResolver.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.
@@ -107,7 +107,7 @@ public class HandlerMethodResolver {
SessionAttributes sessionAttributes = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
this.sessionAttributesFound = (sessionAttributes != null);
if (this.sessionAttributesFound) {
- this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.value()));
+ this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.names()));
this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
}
}
diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java
index 2430c66d32f3525a16d2a3981fe902e1dbf6bc3c..3ff2b31540cce20b76bbaffa2c8ccd9fa0753683 100644
--- a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.java
+++ b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionAttributesHandler.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.
@@ -70,8 +70,8 @@ public class SessionAttributesHandler {
SessionAttributes annotation = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
if (annotation != null) {
- this.attributeNames.addAll(Arrays.asList(annotation.value()));
- this.attributeTypes.addAll(Arrays.