Skip to content

Commit 3e81482

Browse files
committed
Sync with 3.1.x
* 3.1.x: Demonstrate use of @configuration as meta-annotation Prune dead code from JmsTransactionManager#doBegin Apply @configuration BeanNameGenerator consistently Improve @configuration bean name discovery Fix infinite recursion bug in nested @configuration Polish static imports Minor fix in ServletResponseMethodArgumentResolver extracted ResourceUtils.useCachesIfNecessary(URLConnection) method (SP prepared for 3.1.1 release CustomSQLExceptionTranslatorRegistry/Registrar etc revised CustomSQLExceptionTranslatorRegistry/Registrar method naming use custom InputStream traversal instead of a full byte array (SPR-911 PathMatchingResourcePatternResolver preserves caching for JNLP jar con Resource "contentLength()" implementations work with OSGi bundle resou fixed MethodInvokingJobDetailFactoryBean for compatibility with Quartz fixed MethodInvokingJobDetailFactoryBean for compatibility with Quartz
2 parents 81dfef9 + 1c2b1d2 commit 3e81482

41 files changed

Lines changed: 622 additions & 227 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotatedGenericBeanDefinition.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2012 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.
@@ -19,6 +19,7 @@
1919
import org.springframework.beans.factory.support.GenericBeanDefinition;
2020
import org.springframework.core.type.AnnotationMetadata;
2121
import org.springframework.core.type.StandardAnnotationMetadata;
22+
import org.springframework.util.Assert;
2223

2324
/**
2425
* Extension of the {@link org.springframework.beans.factory.support.GenericBeanDefinition}
@@ -32,27 +33,46 @@
3233
* which also implements the AnnotatedBeanDefinition interface).
3334
*
3435
* @author Juergen Hoeller
36+
* @author Chris Beams
3537
* @since 2.5
3638
* @see AnnotatedBeanDefinition#getMetadata()
3739
* @see org.springframework.core.type.StandardAnnotationMetadata
3840
*/
41+
@SuppressWarnings("serial")
3942
public class AnnotatedGenericBeanDefinition extends GenericBeanDefinition implements AnnotatedBeanDefinition {
4043

41-
private final AnnotationMetadata annotationMetadata;
44+
private final AnnotationMetadata metadata;
4245

4346

4447
/**
4548
* Create a new AnnotatedGenericBeanDefinition for the given bean class.
4649
* @param beanClass the loaded bean class
4750
*/
48-
public AnnotatedGenericBeanDefinition(Class beanClass) {
51+
public AnnotatedGenericBeanDefinition(Class<?> beanClass) {
4952
setBeanClass(beanClass);
50-
this.annotationMetadata = new StandardAnnotationMetadata(beanClass, true);
53+
this.metadata = new StandardAnnotationMetadata(beanClass, true);
54+
}
55+
56+
/**
57+
* Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
58+
* allowing for ASM-based processing and avoidance of early loading of the bean class.
59+
* Note that this constructor is functionally equivalent to
60+
* {@link org.springframework.context.annotation.ScannedGenericBeanDefinition
61+
* ScannedGenericBeanDefinition}, however the semantics of the latter indicate that
62+
* a bean was discovered specifically via component-scanning as opposed to other
63+
* means.
64+
* @param metadata the annotation metadata for the bean class in question
65+
* @since 3.1.1
66+
*/
67+
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata) {
68+
Assert.notNull(metadata, "AnnotationMetadata must not be null");
69+
setBeanClassName(metadata.getClassName());
70+
this.metadata = metadata;
5171
}
5272

5373

5474
public final AnnotationMetadata getMetadata() {
55-
return this.annotationMetadata;
75+
return this.metadata;
5676
}
5777

5878
}

spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java

Lines changed: 14 additions & 2 deletions
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-2012 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.
@@ -17,6 +17,7 @@
1717
package org.springframework.scheduling.quartz;
1818

1919
import java.lang.reflect.InvocationTargetException;
20+
import java.lang.reflect.Method;
2021

2122
import org.apache.commons.logging.Log;
2223
import org.apache.commons.logging.LogFactory;
@@ -40,6 +41,7 @@
4041
import org.springframework.util.Assert;
4142
import org.springframework.util.ClassUtils;
4243
import org.springframework.util.MethodInvoker;
44+
import org.springframework.util.ReflectionUtils;
4345

4446
/**
4547
* {@link org.springframework.beans.factory.FactoryBean} that exposes a
@@ -80,13 +82,23 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod
8082

8183
private static Class<?> jobDetailImplClass;
8284

85+
private static Method setResultMethod;
86+
8387
static {
8488
try {
8589
jobDetailImplClass = Class.forName("org.quartz.impl.JobDetailImpl");
8690
}
8791
catch (ClassNotFoundException ex) {
8892
jobDetailImplClass = null;
8993
}
94+
try {
95+
Class jobExecutionContextClass =
96+
QuartzJobBean.class.getClassLoader().loadClass("org.quartz.JobExecutionContext");
97+
setResultMethod = jobExecutionContextClass.getMethod("setResult", Object.class);
98+
}
99+
catch (Exception ex) {
100+
throw new IllegalStateException("Incompatible Quartz API: " + ex);
101+
}
90102
}
91103

92104

@@ -296,7 +308,7 @@ public void setMethodInvoker(MethodInvoker methodInvoker) {
296308
@Override
297309
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
298310
try {
299-
context.setResult(this.methodInvoker.invoke());
311+
ReflectionUtils.invokeMethod(setResultMethod, context, this.methodInvoker.invoke());
300312
}
301313
catch (InvocationTargetException ex) {
302314
if (ex.getTargetException() instanceof JobExecutionException) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
package org.springframework.context.annotation;
1818

19-
import static org.springframework.context.annotation.MetadataUtils.attributesFor;
20-
2119
import java.lang.annotation.Annotation;
2220

2321
import org.springframework.core.GenericTypeResolver;
2422
import org.springframework.core.annotation.AnnotationAttributes;
2523
import org.springframework.core.type.AnnotationMetadata;
2624
import org.springframework.util.Assert;
2725

26+
import static org.springframework.context.annotation.MetadataUtils.*;
27+
2828
/**
2929
* Convenient base class for {@link ImportSelector} implementations that select imports
3030
* based on an {@link AdviceMode} value from an annotation (such as the {@code @Enable*}

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

Lines changed: 3 additions & 1 deletion
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-2012 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.
@@ -109,6 +109,8 @@ public void setEnvironment(ConfigurableEnvironment environment) {
109109
public void setBeanNameGenerator(BeanNameGenerator beanNameGenerator) {
110110
this.reader.setBeanNameGenerator(beanNameGenerator);
111111
this.scanner.setBeanNameGenerator(beanNameGenerator);
112+
this.getBeanFactory().registerSingleton(
113+
AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR, beanNameGenerator);
112114
}
113115

114116
/**

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.context.annotation;
1818

19-
import static org.springframework.context.annotation.MetadataUtils.attributesFor;
20-
2119
import java.util.LinkedHashSet;
2220
import java.util.Set;
2321

@@ -32,6 +30,8 @@
3230
import org.springframework.core.type.AnnotationMetadata;
3331
import org.springframework.util.ClassUtils;
3432

33+
import static org.springframework.context.annotation.MetadataUtils.*;
34+
3535
/**
3636
* Utility class that allows for convenient registration of common
3737
* {@link org.springframework.beans.factory.config.BeanPostProcessor} and
@@ -56,6 +56,17 @@ public class AnnotationConfigUtils {
5656
public static final String CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME =
5757
"org.springframework.context.annotation.internalConfigurationAnnotationProcessor";
5858

59+
/**
60+
* The bean name of the internally managed BeanNameGenerator for use when processing
61+
* {@link Configuration} classes. Set by {@link AnnotationConfigApplicationContext}
62+
* and {@code AnnotationConfigWebApplicationContext} during bootstrap in order to make
63+
* any custom name generation strategy available to the underlying
64+
* {@link ConfigurationClassPostProcessor}.
65+
* @since 3.1.1
66+
*/
67+
public static final String CONFIGURATION_BEAN_NAME_GENERATOR =
68+
"org.springframework.context.annotation.internalConfigurationBeanNameGenerator";
69+
5970
/**
6071
* The bean name of the internally managed Autowired annotation processor.
6172
*/
@@ -249,4 +260,5 @@ static BeanDefinitionHolder applyScopedProxyMode(
249260
return ScopedProxyCreator.createScopedProxy(definition, registry, proxyTargetClass);
250261
}
251262

263+
252264
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
package org.springframework.context.annotation;
1818

19-
import static org.springframework.context.annotation.MetadataUtils.attributesFor;
20-
2119
import java.lang.annotation.Annotation;
2220

2321
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
2422
import org.springframework.beans.factory.config.BeanDefinition;
2523
import org.springframework.core.annotation.AnnotationAttributes;
2624
import org.springframework.util.Assert;
2725

26+
import static org.springframework.context.annotation.MetadataUtils.*;
27+
2828
/**
2929
* A {@link ScopeMetadataResolver} implementation that by default checks for
3030
* the presence of Spring's {@link Scope} annotation on the bean class.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
package org.springframework.context.annotation;
1818

19-
import static org.springframework.context.annotation.MetadataUtils.attributesFor;
20-
2119
import org.springframework.aop.config.AopConfigUtils;
2220
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
2321
import org.springframework.core.annotation.AnnotationAttributes;
2422
import org.springframework.core.type.AnnotationMetadata;
2523

24+
import static org.springframework.context.annotation.MetadataUtils.*;
25+
2626
/**
2727
* Registers an {@link org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator
2828
* AnnotationAwareAspectJAutoProxyCreator} against the current {@link BeanDefinitionRegistry}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
import org.springframework.beans.factory.config.BeanDefinition;
3131
import org.springframework.context.ResourceLoaderAware;
3232
import org.springframework.core.annotation.AnnotationAttributes;
33-
import org.springframework.core.env.StandardEnvironment;
3433
import org.springframework.core.env.Environment;
3534
import org.springframework.core.env.EnvironmentCapable;
35+
import org.springframework.core.env.StandardEnvironment;
3636
import org.springframework.core.io.Resource;
3737
import org.springframework.core.io.ResourceLoader;
3838
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

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

Lines changed: 8 additions & 2 deletions
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-2012 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.
@@ -77,8 +77,14 @@
7777
/**
7878
* The {@link BeanNameGenerator} class to be used for naming detected components
7979
* within the Spring container.
80+
* <p>The default value of the {@link BeanNameGenerator} interface itself indicates
81+
* that the scanner used to process this {@code @ComponentScan} annotation should
82+
* use its inherited bean name generator, e.g. the default
83+
* {@link AnnotationBeanNameGenerator} or any custom instance supplied to the
84+
* application context at bootstrap time.
85+
* @see AnnotationConfigApplicationContext#setBeanNameGenerator(BeanNameGenerator)
8086
*/
81-
Class<? extends BeanNameGenerator> nameGenerator() default AnnotationBeanNameGenerator.class;
87+
Class<? extends BeanNameGenerator> nameGenerator() default BeanNameGenerator.class;
8288

8389
/**
8490
* The {@link ScopeMetadataResolver} to be used for resolving the scope of detected components.

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@ class ComponentScanAnnotationParser {
5151

5252
private final BeanDefinitionRegistry registry;
5353

54+
private final BeanNameGenerator beanNameGenerator;
55+
5456

5557
public ComponentScanAnnotationParser(
56-
ResourceLoader resourceLoader, Environment environment, BeanDefinitionRegistry registry) {
58+
ResourceLoader resourceLoader, Environment environment,
59+
BeanNameGenerator beanNameGenerator, BeanDefinitionRegistry registry) {
60+
5761
this.resourceLoader = resourceLoader;
5862
this.environment = environment;
63+
this.beanNameGenerator = beanNameGenerator;
5964
this.registry = registry;
6065
}
6166

@@ -71,7 +76,10 @@ public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan) {
7176
scanner.setResourceLoader(this.resourceLoader);
7277

7378
Class<? extends BeanNameGenerator> generatorClass = componentScan.getClass("nameGenerator");
74-
scanner.setBeanNameGenerator(BeanUtils.instantiateClass(generatorClass));
79+
boolean useInheritedGenerator = BeanNameGenerator.class.equals(generatorClass);
80+
scanner.setBeanNameGenerator(useInheritedGenerator
81+
? this.beanNameGenerator
82+
: BeanUtils.instantiateClass(generatorClass));
7583

7684
ScopedProxyMode scopedProxyMode = componentScan.getEnum("scopedProxy");
7785
if (scopedProxyMode != ScopedProxyMode.DEFAULT) {

0 commit comments

Comments
 (0)