Polishing

This commit is contained in:
Juergen Hoeller 2017-10-16 19:59:34 +02:00
parent c2438cb932
commit 77bab959a3
9 changed files with 65 additions and 74 deletions

View File

@ -412,7 +412,7 @@ public @interface Configuration {
* component scanning or supplied directly to a {@link AnnotationConfigApplicationContext}. * component scanning or supplied directly to a {@link AnnotationConfigApplicationContext}.
* If the Configuration class is registered as a traditional XML bean definition, * If the Configuration class is registered as a traditional XML bean definition,
* the name/id of the bean element will take precedence. * 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 * @see org.springframework.beans.factory.support.DefaultBeanNameGenerator
*/ */
String value() default ""; String value() default "";

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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, * The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component. * 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 ""; String value() default "";

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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, * The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component. * 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 ""; String value() default "";

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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, * Domain-Driven Design (Evans, 2003) as "a mechanism for encapsulating storage,
* retrieval, and search behavior which emulates a collection of objects". * retrieval, and search behavior which emulates a collection of objects".
* *
* <p>Teams implementing traditional J2EE patterns such as "Data Access Object" * <p>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 * 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 * understand the distinction between Data Access Object and DDD-style repositories
* before doing so. This annotation is a general-purpose stereotype and individual teams * 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, * The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component. * 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 ""; String value() default "";

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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, * The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component. * 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 ""; String value() default "";

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * Such classes are considered as candidates for auto-detection
* when using annotation-based configuration and classpath scanning. * when using annotation-based configuration and classpath scanning.
* *
* <p>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 * @author Mark Fisher
* @since 2.5 * @since 2.5
* @see Repository
* @see Service
* @see Controller
* @see org.springframework.context.annotation.ClassPathBeanDefinitionScanner
*/ */
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ -47,8 +38,8 @@ public @interface Component {
/** /**
* The value may indicate a suggestion for a logical component name, * The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component. * 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 "";
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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, * The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in case of an autodetected component. * 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 * @since 4.0.1
*/ */
String value() default ""; String value() default "";

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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. * Return the configured HandlerMapping's.
*/ */
public List<HandlerMapping> getHandlerMappings() { public List<HandlerMapping> getHandlerMappings() {
return this.handlerMappings; return (this.handlerMappings != null ? this.handlerMappings : Collections.<HandlerMapping>emptyList());
} }
@ -104,44 +104,6 @@ public class HandlerMappingIntrospector
} }
} }
private static List<HandlerMapping> initHandlerMappings(ApplicationContext applicationContext) {
Map<String, HandlerMapping> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
applicationContext, HandlerMapping.class, true, false);
if (!beans.isEmpty()) {
List<HandlerMapping> mappings = new ArrayList<HandlerMapping>(beans.values());
AnnotationAwareOrderComparator.sort(mappings);
return Collections.unmodifiableList(mappings);
}
return Collections.unmodifiableList(initFallback(applicationContext));
}
private static List<HandlerMapping> 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<HandlerMapping> result = new ArrayList<HandlerMapping>(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 * Find the {@link HandlerMapping} that would handle the given request and
@ -199,6 +161,45 @@ public class HandlerMappingIntrospector
} }
private static List<HandlerMapping> initHandlerMappings(ApplicationContext applicationContext) {
Map<String, HandlerMapping> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
applicationContext, HandlerMapping.class, true, false);
if (!beans.isEmpty()) {
List<HandlerMapping> mappings = new ArrayList<HandlerMapping>(beans.values());
AnnotationAwareOrderComparator.sort(mappings);
return Collections.unmodifiableList(mappings);
}
return Collections.unmodifiableList(initFallback(applicationContext));
}
private static List<HandlerMapping> 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<HandlerMapping> result = new ArrayList<HandlerMapping>(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. * Request wrapper that ignores request attribute changes.
*/ */
@ -210,7 +211,7 @@ public class HandlerMappingIntrospector
@Override @Override
public void setAttribute(String name, Object value) { public void setAttribute(String name, Object value) {
// Ignore attribute change // Ignore attribute change...
} }
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * Configure one more simple patterns (as described in {@link PatternMatchUtils#simpleMatch})
* {@link org.springframework.util.PatternMatchUtils#simpleMatch}) to use in order to recognize * to use in order to recognize custom redirect prefixes in addition to "redirect:".
* custom redirect prefixes in addition to "redirect:". * <p>Note that simply configuring this property will not make a custom redirect prefix work.
* <p>Note that simply configuring this property will not make a custom * There must be a custom {@link View} that recognizes the prefix as well.
* redirect prefix work. There must be a custom View that recognizes the
* prefix as well.
* @since 4.1 * @since 4.1
*/ */
public void setRedirectPatterns(String... redirectPatterns) { 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() { public String[] getRedirectPatterns() {
return this.redirectPatterns; return this.redirectPatterns;