diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java b/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java index 49019333114..7d8e8a29c8a 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Configuration.java @@ -412,7 +412,7 @@ public @interface Configuration { * component scanning or supplied directly to a {@link AnnotationConfigApplicationContext}. * If the Configuration class is registered as a traditional XML bean definition, * the name/id of the bean element will take precedence. - * @return the specified bean name, if any + * @return the suggested component name, if any (or empty String otherwise) * @see org.springframework.beans.factory.support.DefaultBeanNameGenerator */ String value() default ""; diff --git a/spring-context/src/main/java/org/springframework/stereotype/Component.java b/spring-context/src/main/java/org/springframework/stereotype/Component.java index 8b3c75dffc5..43ca86d4876 100644 --- a/spring-context/src/main/java/org/springframework/stereotype/Component.java +++ b/spring-context/src/main/java/org/springframework/stereotype/Component.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2017 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. @@ -47,7 +47,7 @@ public @interface Component { /** * The value may indicate a suggestion for a logical component name, * to be turned into a Spring bean in case of an autodetected component. - * @return the suggested component name, if any + * @return the suggested component name, if any (or empty String otherwise) */ String value() default ""; diff --git a/spring-context/src/main/java/org/springframework/stereotype/Controller.java b/spring-context/src/main/java/org/springframework/stereotype/Controller.java index 189776d444e..95db8d43b34 100644 --- a/spring-context/src/main/java/org/springframework/stereotype/Controller.java +++ b/spring-context/src/main/java/org/springframework/stereotype/Controller.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2017 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. @@ -46,7 +46,7 @@ public @interface Controller { /** * The value may indicate a suggestion for a logical component name, * to be turned into a Spring bean in case of an autodetected component. - * @return the suggested component name, if any + * @return the suggested component name, if any (or empty String otherwise) */ String value() default ""; diff --git a/spring-context/src/main/java/org/springframework/stereotype/Repository.java b/spring-context/src/main/java/org/springframework/stereotype/Repository.java index 0709b72bfe1..2aa5289e74f 100644 --- a/spring-context/src/main/java/org/springframework/stereotype/Repository.java +++ b/spring-context/src/main/java/org/springframework/stereotype/Repository.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2017 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. @@ -27,7 +27,7 @@ import java.lang.annotation.Target; * Domain-Driven Design (Evans, 2003) as "a mechanism for encapsulating storage, * retrieval, and search behavior which emulates a collection of objects". * - *

Teams implementing traditional J2EE patterns such as "Data Access Object" + *

Teams implementing traditional Java EE patterns such as "Data Access Object" * may also apply this stereotype to DAO classes, though care should be taken to * understand the distinction between Data Access Object and DDD-style repositories * before doing so. This annotation is a general-purpose stereotype and individual teams @@ -62,7 +62,7 @@ public @interface Repository { /** * The value may indicate a suggestion for a logical component name, * to be turned into a Spring bean in case of an autodetected component. - * @return the suggested component name, if any + * @return the suggested component name, if any (or empty String otherwise) */ String value() default ""; diff --git a/spring-context/src/main/java/org/springframework/stereotype/Service.java b/spring-context/src/main/java/org/springframework/stereotype/Service.java index 09307383969..f9dadc382b2 100644 --- a/spring-context/src/main/java/org/springframework/stereotype/Service.java +++ b/spring-context/src/main/java/org/springframework/stereotype/Service.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2017 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. @@ -48,7 +48,7 @@ public @interface Service { /** * The value may indicate a suggestion for a logical component name, * to be turned into a Spring bean in case of an autodetected component. - * @return the suggested component name, if any + * @return the suggested component name, if any (or empty String otherwise) */ String value() default ""; diff --git a/spring-core/src/test/java/org/springframework/stereotype/Component.java b/spring-core/src/test/java/org/springframework/stereotype/Component.java index e0b637f815c..dd610de74f8 100644 --- a/spring-core/src/test/java/org/springframework/stereotype/Component.java +++ b/spring-core/src/test/java/org/springframework/stereotype/Component.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2017 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. @@ -27,17 +27,8 @@ import java.lang.annotation.Target; * Such classes are considered as candidates for auto-detection * when using annotation-based configuration and classpath scanning. * - *

Other class-level annotations may be considered as identifying - * a component as well, typically a special kind of component: - * e.g. the {@link Repository @Repository} annotation or AspectJ's - * {@link org.aspectj.lang.annotation.Aspect @Aspect} annotation. - * * @author Mark Fisher * @since 2.5 - * @see Repository - * @see Service - * @see Controller - * @see org.springframework.context.annotation.ClassPathBeanDefinitionScanner */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @@ -47,8 +38,8 @@ public @interface Component { /** * The value may indicate a suggestion for a logical component name, * to be turned into a Spring bean in case of an autodetected component. - * @return the suggested component name, if any + * @return the suggested component name, if any (or empty String otherwise) */ - public abstract String value() default ""; + String value() default ""; -} \ No newline at end of file +} diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RestController.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RestController.java index 2287f65264f..99f4e1457f6 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RestController.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RestController.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -54,7 +54,7 @@ public @interface RestController { /** * The value may indicate a suggestion for a logical component name, * to be turned into a Spring bean in case of an autodetected component. - * @return the suggested component name, if any + * @return the suggested component name, if any (or empty String otherwise) * @since 4.0.1 */ String value() default ""; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java index 220789ef5ad..5b78a941a1c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -87,7 +87,7 @@ public class HandlerMappingIntrospector * Return the configured HandlerMapping's. */ public List getHandlerMappings() { - return this.handlerMappings; + return (this.handlerMappings != null ? this.handlerMappings : Collections.emptyList()); } @@ -104,44 +104,6 @@ public class HandlerMappingIntrospector } } - private static List initHandlerMappings(ApplicationContext applicationContext) { - Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors( - applicationContext, HandlerMapping.class, true, false); - if (!beans.isEmpty()) { - List mappings = new ArrayList(beans.values()); - AnnotationAwareOrderComparator.sort(mappings); - return Collections.unmodifiableList(mappings); - } - return Collections.unmodifiableList(initFallback(applicationContext)); - } - - private static List initFallback(ApplicationContext applicationContext) { - Properties props; - String path = "DispatcherServlet.properties"; - try { - Resource resource = new ClassPathResource(path, DispatcherServlet.class); - props = PropertiesLoaderUtils.loadProperties(resource); - } - catch (IOException ex) { - throw new IllegalStateException("Could not load '" + path + "': " + ex.getMessage()); - } - - String value = props.getProperty(HandlerMapping.class.getName()); - String[] names = StringUtils.commaDelimitedListToStringArray(value); - List result = new ArrayList(names.length); - for (String name : names) { - try { - Class clazz = ClassUtils.forName(name, DispatcherServlet.class.getClassLoader()); - Object mapping = applicationContext.getAutowireCapableBeanFactory().createBean(clazz); - result.add((HandlerMapping) mapping); - } - catch (ClassNotFoundException ex) { - throw new IllegalStateException("Could not find default HandlerMapping [" + name + "]"); - } - } - return result; - } - /** * Find the {@link HandlerMapping} that would handle the given request and @@ -199,6 +161,45 @@ public class HandlerMappingIntrospector } + private static List initHandlerMappings(ApplicationContext applicationContext) { + Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors( + applicationContext, HandlerMapping.class, true, false); + if (!beans.isEmpty()) { + List mappings = new ArrayList(beans.values()); + AnnotationAwareOrderComparator.sort(mappings); + return Collections.unmodifiableList(mappings); + } + return Collections.unmodifiableList(initFallback(applicationContext)); + } + + private static List initFallback(ApplicationContext applicationContext) { + Properties props; + String path = "DispatcherServlet.properties"; + try { + Resource resource = new ClassPathResource(path, DispatcherServlet.class); + props = PropertiesLoaderUtils.loadProperties(resource); + } + catch (IOException ex) { + throw new IllegalStateException("Could not load '" + path + "': " + ex.getMessage()); + } + + String value = props.getProperty(HandlerMapping.class.getName()); + String[] names = StringUtils.commaDelimitedListToStringArray(value); + List result = new ArrayList(names.length); + for (String name : names) { + try { + Class clazz = ClassUtils.forName(name, DispatcherServlet.class.getClassLoader()); + Object mapping = applicationContext.getAutowireCapableBeanFactory().createBean(clazz); + result.add((HandlerMapping) mapping); + } + catch (ClassNotFoundException ex) { + throw new IllegalStateException("Could not find default HandlerMapping [" + name + "]"); + } + } + return result; + } + + /** * Request wrapper that ignores request attribute changes. */ @@ -210,7 +211,7 @@ public class HandlerMappingIntrospector @Override public void setAttribute(String name, Object value) { - // Ignore attribute change + // Ignore attribute change... } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java index 10ea4028121..d9babd22776 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -47,12 +47,10 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn /** - * Configure one more simple patterns (as described in - * {@link org.springframework.util.PatternMatchUtils#simpleMatch}) to use in order to recognize - * custom redirect prefixes in addition to "redirect:". - *

Note that simply configuring this property will not make a custom - * redirect prefix work. There must be a custom View that recognizes the - * prefix as well. + * Configure one more simple patterns (as described in {@link PatternMatchUtils#simpleMatch}) + * to use in order to recognize custom redirect prefixes in addition to "redirect:". + *

Note that simply configuring this property will not make a custom redirect prefix work. + * There must be a custom {@link View} that recognizes the prefix as well. * @since 4.1 */ public void setRedirectPatterns(String... redirectPatterns) { @@ -60,7 +58,8 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn } /** - * The configured redirect patterns, if any. + * Return the configured redirect patterns, if any. + * @since 4.1 */ public String[] getRedirectPatterns() { return this.redirectPatterns;