Skip to content

Commit 77bab95

Browse files
committed
Polishing
1 parent c2438cb commit 77bab95

File tree

9 files changed

+65
-74
lines changed

9 files changed

+65
-74
lines changed

spring-context/src/main/java/org/springframework/context/annotation/Configuration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@
412412
* component scanning or supplied directly to a {@link AnnotationConfigApplicationContext}.
413413
* If the Configuration class is registered as a traditional XML bean definition,
414414
* the name/id of the bean element will take precedence.
415-
* @return the specified bean name, if any
415+
* @return the suggested component name, if any (or empty String otherwise)
416416
* @see org.springframework.beans.factory.support.DefaultBeanNameGenerator
417417
*/
418418
String value() default "";

spring-context/src/main/java/org/springframework/stereotype/Component.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@
4747
/**
4848
* The value may indicate a suggestion for a logical component name,
4949
* to be turned into a Spring bean in case of an autodetected component.
50-
* @return the suggested component name, if any
50+
* @return the suggested component name, if any (or empty String otherwise)
5151
*/
5252
String value() default "";
5353

spring-context/src/main/java/org/springframework/stereotype/Controller.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@
4646
/**
4747
* The value may indicate a suggestion for a logical component name,
4848
* to be turned into a Spring bean in case of an autodetected component.
49-
* @return the suggested component name, if any
49+
* @return the suggested component name, if any (or empty String otherwise)
5050
*/
5151
String value() default "";
5252

spring-context/src/main/java/org/springframework/stereotype/Repository.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
* Domain-Driven Design (Evans, 2003) as "a mechanism for encapsulating storage,
2828
* retrieval, and search behavior which emulates a collection of objects".
2929
*
30-
* <p>Teams implementing traditional J2EE patterns such as "Data Access Object"
30+
* <p>Teams implementing traditional Java EE patterns such as "Data Access Object"
3131
* may also apply this stereotype to DAO classes, though care should be taken to
3232
* understand the distinction between Data Access Object and DDD-style repositories
3333
* before doing so. This annotation is a general-purpose stereotype and individual teams
@@ -62,7 +62,7 @@
6262
/**
6363
* The value may indicate a suggestion for a logical component name,
6464
* to be turned into a Spring bean in case of an autodetected component.
65-
* @return the suggested component name, if any
65+
* @return the suggested component name, if any (or empty String otherwise)
6666
*/
6767
String value() default "";
6868

spring-context/src/main/java/org/springframework/stereotype/Service.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@
4848
/**
4949
* The value may indicate a suggestion for a logical component name,
5050
* to be turned into a Spring bean in case of an autodetected component.
51-
* @return the suggested component name, if any
51+
* @return the suggested component name, if any (or empty String otherwise)
5252
*/
5353
String value() default "";
5454

spring-core/src/test/java/org/springframework/stereotype/Component.java

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,17 +27,8 @@
2727
* Such classes are considered as candidates for auto-detection
2828
* when using annotation-based configuration and classpath scanning.
2929
*
30-
* <p>Other class-level annotations may be considered as identifying
31-
* a component as well, typically a special kind of component:
32-
* e.g. the {@link Repository @Repository} annotation or AspectJ's
33-
* {@link org.aspectj.lang.annotation.Aspect @Aspect} annotation.
34-
*
3530
* @author Mark Fisher
3631
* @since 2.5
37-
* @see Repository
38-
* @see Service
39-
* @see Controller
40-
* @see org.springframework.context.annotation.ClassPathBeanDefinitionScanner
4132
*/
4233
@Target(ElementType.TYPE)
4334
@Retention(RetentionPolicy.RUNTIME)
@@ -47,8 +38,8 @@
4738
/**
4839
* The value may indicate a suggestion for a logical component name,
4940
* to be turned into a Spring bean in case of an autodetected component.
50-
* @return the suggested component name, if any
41+
* @return the suggested component name, if any (or empty String otherwise)
5142
*/
52-
public abstract String value() default "";
43+
String value() default "";
5344

54-
}
45+
}

spring-web/src/main/java/org/springframework/web/bind/annotation/RestController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,7 +54,7 @@
5454
/**
5555
* The value may indicate a suggestion for a logical component name,
5656
* to be turned into a Spring bean in case of an autodetected component.
57-
* @return the suggested component name, if any
57+
* @return the suggested component name, if any (or empty String otherwise)
5858
* @since 4.0.1
5959
*/
6060
String value() default "";

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java

+42-41
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -87,7 +87,7 @@ public HandlerMappingIntrospector(ApplicationContext context) {
8787
* Return the configured HandlerMapping's.
8888
*/
8989
public List<HandlerMapping> getHandlerMappings() {
90-
return this.handlerMappings;
90+
return (this.handlerMappings != null ? this.handlerMappings : Collections.<HandlerMapping>emptyList());
9191
}
9292

9393

@@ -104,44 +104,6 @@ public void afterPropertiesSet() {
104104
}
105105
}
106106

107-
private static List<HandlerMapping> initHandlerMappings(ApplicationContext applicationContext) {
108-
Map<String, HandlerMapping> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
109-
applicationContext, HandlerMapping.class, true, false);
110-
if (!beans.isEmpty()) {
111-
List<HandlerMapping> mappings = new ArrayList<HandlerMapping>(beans.values());
112-
AnnotationAwareOrderComparator.sort(mappings);
113-
return Collections.unmodifiableList(mappings);
114-
}
115-
return Collections.unmodifiableList(initFallback(applicationContext));
116-
}
117-
118-
private static List<HandlerMapping> initFallback(ApplicationContext applicationContext) {
119-
Properties props;
120-
String path = "DispatcherServlet.properties";
121-
try {
122-
Resource resource = new ClassPathResource(path, DispatcherServlet.class);
123-
props = PropertiesLoaderUtils.loadProperties(resource);
124-
}
125-
catch (IOException ex) {
126-
throw new IllegalStateException("Could not load '" + path + "': " + ex.getMessage());
127-
}
128-
129-
String value = props.getProperty(HandlerMapping.class.getName());
130-
String[] names = StringUtils.commaDelimitedListToStringArray(value);
131-
List<HandlerMapping> result = new ArrayList<HandlerMapping>(names.length);
132-
for (String name : names) {
133-
try {
134-
Class<?> clazz = ClassUtils.forName(name, DispatcherServlet.class.getClassLoader());
135-
Object mapping = applicationContext.getAutowireCapableBeanFactory().createBean(clazz);
136-
result.add((HandlerMapping) mapping);
137-
}
138-
catch (ClassNotFoundException ex) {
139-
throw new IllegalStateException("Could not find default HandlerMapping [" + name + "]");
140-
}
141-
}
142-
return result;
143-
}
144-
145107

146108
/**
147109
* Find the {@link HandlerMapping} that would handle the given request and
@@ -199,6 +161,45 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
199161
}
200162

201163

164+
private static List<HandlerMapping> initHandlerMappings(ApplicationContext applicationContext) {
165+
Map<String, HandlerMapping> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
166+
applicationContext, HandlerMapping.class, true, false);
167+
if (!beans.isEmpty()) {
168+
List<HandlerMapping> mappings = new ArrayList<HandlerMapping>(beans.values());
169+
AnnotationAwareOrderComparator.sort(mappings);
170+
return Collections.unmodifiableList(mappings);
171+
}
172+
return Collections.unmodifiableList(initFallback(applicationContext));
173+
}
174+
175+
private static List<HandlerMapping> initFallback(ApplicationContext applicationContext) {
176+
Properties props;
177+
String path = "DispatcherServlet.properties";
178+
try {
179+
Resource resource = new ClassPathResource(path, DispatcherServlet.class);
180+
props = PropertiesLoaderUtils.loadProperties(resource);
181+
}
182+
catch (IOException ex) {
183+
throw new IllegalStateException("Could not load '" + path + "': " + ex.getMessage());
184+
}
185+
186+
String value = props.getProperty(HandlerMapping.class.getName());
187+
String[] names = StringUtils.commaDelimitedListToStringArray(value);
188+
List<HandlerMapping> result = new ArrayList<HandlerMapping>(names.length);
189+
for (String name : names) {
190+
try {
191+
Class<?> clazz = ClassUtils.forName(name, DispatcherServlet.class.getClassLoader());
192+
Object mapping = applicationContext.getAutowireCapableBeanFactory().createBean(clazz);
193+
result.add((HandlerMapping) mapping);
194+
}
195+
catch (ClassNotFoundException ex) {
196+
throw new IllegalStateException("Could not find default HandlerMapping [" + name + "]");
197+
}
198+
}
199+
return result;
200+
}
201+
202+
202203
/**
203204
* Request wrapper that ignores request attribute changes.
204205
*/
@@ -210,7 +211,7 @@ public RequestAttributeChangeIgnoringWrapper(HttpServletRequest request) {
210211

211212
@Override
212213
public void setAttribute(String name, Object value) {
213-
// Ignore attribute change
214+
// Ignore attribute change...
214215
}
215216
}
216217

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewMethodReturnValueHandler.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,20 +47,19 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn
4747

4848

4949
/**
50-
* Configure one more simple patterns (as described in
51-
* {@link org.springframework.util.PatternMatchUtils#simpleMatch}) to use in order to recognize
52-
* custom redirect prefixes in addition to "redirect:".
53-
* <p>Note that simply configuring this property will not make a custom
54-
* redirect prefix work. There must be a custom View that recognizes the
55-
* prefix as well.
50+
* Configure one more simple patterns (as described in {@link PatternMatchUtils#simpleMatch})
51+
* to use in order to recognize custom redirect prefixes in addition to "redirect:".
52+
* <p>Note that simply configuring this property will not make a custom redirect prefix work.
53+
* There must be a custom {@link View} that recognizes the prefix as well.
5654
* @since 4.1
5755
*/
5856
public void setRedirectPatterns(String... redirectPatterns) {
5957
this.redirectPatterns = redirectPatterns;
6058
}
6159

6260
/**
63-
* The configured redirect patterns, if any.
61+
* Return the configured redirect patterns, if any.
62+
* @since 4.1
6463
*/
6564
public String[] getRedirectPatterns() {
6665
return this.redirectPatterns;

0 commit comments

Comments
 (0)