summaryrefslogtreecommitdiff
path: root/spring-context/src/main/java
diff options
context:
space:
mode:
authorEmmanuel Bourg <ebourg@apache.org>2016-08-02 11:51:52 +0200
committerEmmanuel Bourg <ebourg@apache.org>2016-08-02 11:51:52 +0200
commit9eaca6a06af3cbceb3754de19d477be770614265 (patch)
tree66e994251c7f0b375772be30bdedd383d082c357 /spring-context/src/main/java
parentf69f2a4b8ea697b3a631c0dc7a470e3c9793fee3 (diff)
Imported Upstream version 4.2.7
Diffstat (limited to 'spring-context/src/main/java')
-rw-r--r--spring-context/src/main/java/org/springframework/context/annotation/Bean.java7
-rw-r--r--spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java28
-rw-r--r--spring-context/src/main/java/org/springframework/context/annotation/Import.java4
-rw-r--r--spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java28
-rw-r--r--spring-context/src/main/java/org/springframework/context/weaving/AspectJWeavingEnabler.java19
-rw-r--r--spring-context/src/main/java/org/springframework/format/support/FormatterPropertyEditorAdapter.java19
-rw-r--r--spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java4
-rw-r--r--spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java2
-rw-r--r--spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java6
-rw-r--r--spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java2
-rw-r--r--spring-context/src/main/java/org/springframework/validation/beanvalidation/package-info.java2
11 files changed, 79 insertions, 42 deletions
diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Bean.java b/spring-context/src/main/java/org/springframework/context/annotation/Bean.java
index 27635600..8cbaa0da 100644
--- a/spring-context/src/main/java/org/springframework/context/annotation/Bean.java
+++ b/spring-context/src/main/java/org/springframework/context/annotation/Bean.java
@@ -198,6 +198,13 @@ public @interface Bean {
/**
* Are dependencies to be injected via convention-based autowiring by name or type?
+ * <p>Note that this autowire mode is just about externally driven autowiring based
+ * on bean property setter methods by convention, analogous to XML bean definitions.
+ * <p>The default mode does allow for annotation-driven autowiring. "no" refers to
+ * externally driven autowiring only, not affecting any autowiring demands that the
+ * bean class itself expresses through annotations.
+ * @see Autowire#BY_NAME
+ * @see Autowire#BY_TYPE
*/
Autowire autowire() default Autowire.NO;
diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
index c0541652..023371b4 100644
--- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
+++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
@@ -295,15 +295,7 @@ class ConfigurationClassParser {
}
// Process default methods on interfaces
- for (SourceClass ifc : sourceClass.getInterfaces()) {
- beanMethods = ifc.getMetadata().getAnnotatedMethods(Bean.class.getName());
- for (MethodMetadata methodMetadata : beanMethods) {
- if (!methodMetadata.isAbstract()) {
- // A default method or other concrete method on a Java 8+ interface...
- configClass.addBeanMethod(new BeanMethod(methodMetadata, configClass));
- }
- }
- }
+ processInterfaces(configClass, sourceClass);
// Process superclass, if any
if (sourceClass.getMetadata().hasSuperClass()) {
@@ -321,8 +313,6 @@ class ConfigurationClassParser {
/**
* Register member (nested) classes that happen to be configuration classes themselves.
- * @param sourceClass the source class to process
- * @throws IOException if there is any problem reading metadata from a member class
*/
private void processMemberClasses(ConfigurationClass configClass, SourceClass sourceClass) throws IOException {
for (SourceClass memberClass : sourceClass.getMemberClasses()) {
@@ -345,6 +335,22 @@ class ConfigurationClassParser {
}
/**
+ * Register default methods on interfaces implemented by the configuration class.
+ */
+ private void processInterfaces(ConfigurationClass configClass, SourceClass sourceClass) throws IOException {
+ for (SourceClass ifc : sourceClass.getInterfaces()) {
+ Set<MethodMetadata> beanMethods = ifc.getMetadata().getAnnotatedMethods(Bean.class.getName());
+ for (MethodMetadata methodMetadata : beanMethods) {
+ if (!methodMetadata.isAbstract()) {
+ // A default method or other concrete method on a Java 8+ interface...
+ configClass.addBeanMethod(new BeanMethod(methodMetadata, configClass));
+ }
+ }
+ processInterfaces(configClass, ifc);
+ }
+ }
+
+ /**
* Process the given <code>@PropertySource</code> annotation metadata.
* @param propertySource metadata for the <code>@PropertySource</code> annotation found
* @throws IOException if loading a property source failed
diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Import.java b/spring-context/src/main/java/org/springframework/context/annotation/Import.java
index e70c68ef..6c9fa7cd 100644
--- a/spring-context/src/main/java/org/springframework/context/annotation/Import.java
+++ b/spring-context/src/main/java/org/springframework/context/annotation/Import.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 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 @@ import java.lang.annotation.Target;
public @interface Import {
/**
- * @{@link Configuration}, {@link ImportSelector}, {@link ImportBeanDefinitionRegistrar}
+ * {@link Configuration}, {@link ImportSelector}, {@link ImportBeanDefinitionRegistrar}
* or regular component classes to import.
*/
Class<?>[] value();
diff --git a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java
index d551d509..e24cac8d 100644
--- a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java
+++ b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -41,6 +41,7 @@ import org.springframework.core.MethodIntrospector;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.Assert;
+import org.springframework.util.CollectionUtils;
/**
* Register {@link EventListener} annotated method as individual {@link ApplicationListener}
@@ -124,14 +125,23 @@ public class EventListenerMethodProcessor implements SmartInitializingSingleton,
protected void processBean(final List<EventListenerFactory> factories, final String beanName, final Class<?> targetType) {
if (!this.nonAnnotatedClasses.contains(targetType)) {
- Map<Method, EventListener> annotatedMethods = MethodIntrospector.selectMethods(targetType,
- new MethodIntrospector.MetadataLookup<EventListener>() {
- @Override
- public EventListener inspect(Method method) {
- return AnnotationUtils.findAnnotation(method, EventListener.class);
- }
- });
- if (annotatedMethods.isEmpty()) {
+ Map<Method, EventListener> annotatedMethods = null;
+ try {
+ annotatedMethods = MethodIntrospector.selectMethods(targetType,
+ new MethodIntrospector.MetadataLookup<EventListener>() {
+ @Override
+ public EventListener inspect(Method method) {
+ return AnnotationUtils.findAnnotation(method, EventListener.class);
+ }
+ });
+ }
+ catch (Throwable ex) {
+ // An unresolvable type in a method signature, probably from a lazy bean - let's ignore it.
+ if (logger.isDebugEnabled()) {
+ logger.debug("Could not resolve methods for bean with name '" + beanName + "'", ex);
+ }
+ }
+ if (CollectionUtils.isEmpty(annotatedMethods)) {
this.nonAnnotatedClasses.add(targetType);
if (logger.isTraceEnabled()) {
logger.trace("No @EventListener annotations found on bean class: " + targetType);
diff --git a/spring-context/src/main/java/org/springframework/context/weaving/AspectJWeavingEnabler.java b/spring-context/src/main/java/org/springframework/context/weaving/AspectJWeavingEnabler.java
index ab78f5c3..e93e500b 100644
--- a/spring-context/src/main/java/org/springframework/context/weaving/AspectJWeavingEnabler.java
+++ b/spring-context/src/main/java/org/springframework/context/weaving/AspectJWeavingEnabler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -16,7 +16,6 @@
package org.springframework.context.weaving;
-
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;
@@ -44,12 +43,13 @@ import org.springframework.instrument.classloading.LoadTimeWeaver;
public class AspectJWeavingEnabler
implements BeanFactoryPostProcessor, BeanClassLoaderAware, LoadTimeWeaverAware, Ordered {
+ public static final String ASPECTJ_AOP_XML_RESOURCE = "META-INF/aop.xml";
+
+
private ClassLoader beanClassLoader;
private LoadTimeWeaver loadTimeWeaver;
- public static final String ASPECTJ_AOP_XML_RESOURCE = "META-INF/aop.xml";
-
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
@@ -71,6 +71,12 @@ public class AspectJWeavingEnabler
enableAspectJWeaving(this.loadTimeWeaver, this.beanClassLoader);
}
+
+ /**
+ * Enable AspectJ weaving with the given {@link LoadTimeWeaver}.
+ * @param weaverToUse the LoadTimeWeaver to apply to (or {@code null} for a default weaver)
+ * @param beanClassLoader the class loader to create a default weaver for (if necessary)
+ */
public static void enableAspectJWeaving(LoadTimeWeaver weaverToUse, ClassLoader beanClassLoader) {
if (weaverToUse == null) {
if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) {
@@ -80,8 +86,8 @@ public class AspectJWeavingEnabler
throw new IllegalStateException("No LoadTimeWeaver available");
}
}
- weaverToUse.addTransformer(new AspectJClassBypassingClassFileTransformer(
- new ClassPreProcessorAgentAdapter()));
+ weaverToUse.addTransformer(
+ new AspectJClassBypassingClassFileTransformer(new ClassPreProcessorAgentAdapter()));
}
@@ -108,4 +114,5 @@ public class AspectJWeavingEnabler
return this.delegate.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
}
}
+
}
diff --git a/spring-context/src/main/java/org/springframework/format/support/FormatterPropertyEditorAdapter.java b/spring-context/src/main/java/org/springframework/format/support/FormatterPropertyEditorAdapter.java
index c5db9ecd..7d490f5d 100644
--- a/spring-context/src/main/java/org/springframework/format/support/FormatterPropertyEditorAdapter.java
+++ b/spring-context/src/main/java/org/springframework/format/support/FormatterPropertyEditorAdapter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 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,6 +23,7 @@ import java.text.ParseException;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.format.Formatter;
import org.springframework.util.Assert;
+import org.springframework.util.StringUtils;
/**
* Adapter that bridges between {@link Formatter} and {@link PropertyEditor}.
@@ -60,17 +61,23 @@ public class FormatterPropertyEditorAdapter extends PropertyEditorSupport {
@Override
public void setAsText(String text) throws IllegalArgumentException {
- try {
- setValue(this.formatter.parse(text, LocaleContextHolder.getLocale()));
+ if (StringUtils.hasText(text)) {
+ try {
+ setValue(this.formatter.parse(text, LocaleContextHolder.getLocale()));
+ }
+ catch (ParseException ex) {
+ throw new IllegalArgumentException("Parse attempt failed for value [" + text + "]", ex);
+ }
}
- catch (ParseException ex) {
- throw new IllegalArgumentException("Parse attempt failed for value [" + text + "]", ex);
+ else {
+ setValue(null);
}
}
@Override
public String getAsText() {
- return this.formatter.print(getValue(), LocaleContextHolder.getLocale());
+ Object value = getValue();
+ return (value != null ? this.formatter.print(value, LocaleContextHolder.getLocale()) : "");
}
}
diff --git a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java
index 276f8706..e65e4fbd 100644
--- a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java
+++ b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -194,7 +194,7 @@ public class FormattingConversionService extends GenericConversionService
result = this.parser.parse(text, LocaleContextHolder.getLocale());
}
catch (ParseException ex) {
- throw new IllegalArgumentException("Unable to parse '" + text + "'", ex);
+ throw new IllegalArgumentException("Parse attempt failed for value [" + text + "]", ex);
}
if (result == null) {
throw new IllegalStateException("Parsers are not allowed to return null");
diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
index a0ac5d48..bacd01b5 100644
--- a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
+++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
@@ -64,7 +64,7 @@ import org.springframework.util.StringValueResolver;
*
* <p>This post-processor is automatically registered by Spring's
* {@code <task:annotation-driven>} XML element, and also by the
- * @{@link EnableScheduling} annotation.
+ * {@link EnableScheduling @EnableScheduling} annotation.
*
* <p>Autodetects any {@link SchedulingConfigurer} instances in the container,
* allowing for customization of the scheduler to be used or for fine-grained
diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java
index b7c40b1d..78d84049 100644
--- a/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java
+++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 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,8 +27,8 @@ import org.springframework.scheduling.config.TaskManagementConfigUtils;
* bean capable of processing Spring's @{@link Scheduled} annotation.
*
* <p>This configuration class is automatically imported when using the
- * @{@link EnableScheduling} annotation. See {@code @EnableScheduling}'s javadoc
- * for complete usage details.
+ * {@link EnableScheduling @EnableScheduling} annotation. See
+ * {@code @EnableScheduling}'s javadoc for complete usage details.
*
* @author Chris Beams
* @since 3.1
diff --git a/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java b/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java
index c082ca4c..439f3c1e 100644
--- a/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java
+++ b/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptFactory.java
@@ -40,7 +40,7 @@ import org.springframework.util.ClassUtils;
*
* <p>Typically used in combination with a
* {@link org.springframework.scripting.support.ScriptFactoryPostProcessor};
- * see the latter's javadoc} for a configuration example.
+ * see the latter's javadoc for a configuration example.
*
* <p>Note: Spring 4.0 supports Groovy 1.8 and higher.
*
diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/package-info.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/package-info.java
index 7961d3ab..a8bea39a 100644
--- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/package-info.java
+++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/package-info.java
@@ -1,6 +1,6 @@
/**
* Support classes for integrating a JSR-303 Bean Validation provider
- * (such as Hibernate Validator 4.0) into a Spring ApplicationContext
+ * (such as Hibernate Validator) into a Spring ApplicationContext
* and in particular with Spring's data binding and validation APIs.
*
* <p>The central class is {@link