Browse Source

Merge branch '5.3.x'

# Conflicts:
#	build.gradle
#	spring-context/src/main/java/org/springframework/context/annotation/Lazy.java
pull/27554/head
Juergen Hoeller 4 years ago
parent
commit
0e1ba7aae5
  1. 1
      build.gradle
  2. 2
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
  3. 4
      spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java
  4. 4
      spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java
  5. 12
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java
  6. 7
      spring-context/src/main/java/org/springframework/context/annotation/Lazy.java
  7. 4
      spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java
  8. 8
      spring-tx/src/main/java/org/springframework/dao/annotation/PersistenceExceptionTranslationPostProcessor.java
  9. 10
      src/docs/asciidoc/core/core-beans.adoc

1
build.gradle

@ -255,7 +255,6 @@ configure(allprojects) { project -> @@ -255,7 +255,6 @@ configure(allprojects) { project ->
repositories {
mavenCentral()
maven { url "https://repo.spring.io/libs-spring-framework-build" }
}
}
configurations.all {

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

@ -471,7 +471,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA @@ -471,7 +471,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
return metadata;
}
private InjectionMetadata buildAutowiringMetadata(final Class<?> clazz) {
private InjectionMetadata buildAutowiringMetadata(Class<?> clazz) {
if (!AnnotationUtils.isCandidateClass(clazz, this.autowiredAnnotationTypes)) {
return InjectionMetadata.EMPTY;
}

4
spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java

@ -315,7 +315,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean @@ -315,7 +315,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
}
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, @Nullable PropertyValues pvs) {
private InjectionMetadata findResourceMetadata(String beanName, Class<?> clazz, @Nullable PropertyValues pvs) {
// Fall back to class name as cache key, for backwards compatibility with custom callers.
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
// Quick check on the concurrent map first, with minimal locking.
@ -335,7 +335,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean @@ -335,7 +335,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
return metadata;
}
private InjectionMetadata buildResourceMetadata(final Class<?> clazz) {
private InjectionMetadata buildResourceMetadata(Class<?> clazz) {
if (!AnnotationUtils.isCandidateClass(clazz, resourceAnnotationTypes)) {
return InjectionMetadata.EMPTY;
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2021 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.
@ -65,7 +65,7 @@ class ComponentScanAnnotationParser { @@ -65,7 +65,7 @@ class ComponentScanAnnotationParser {
}
public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan, final String declaringClass) {
public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan, String declaringClass) {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(this.registry,
componentScan.getBoolean("useDefaultFilters"), this.environment, this.resourceLoader);

12
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java

@ -453,8 +453,8 @@ class ConfigurationClassEnhancer { @@ -453,8 +453,8 @@ class ConfigurationClassEnhancer {
* instance directly. If a FactoryBean instance is fetched through the container via &-dereferencing,
* it will not be proxied. This too is aligned with the way XML configuration works.
*/
private Object enhanceFactoryBean(final Object factoryBean, Class<?> exposedType,
final ConfigurableBeanFactory beanFactory, final String beanName) {
private Object enhanceFactoryBean(Object factoryBean, Class<?> exposedType,
ConfigurableBeanFactory beanFactory, String beanName) {
try {
Class<?> clazz = factoryBean.getClass();
@ -489,8 +489,8 @@ class ConfigurationClassEnhancer { @@ -489,8 +489,8 @@ class ConfigurationClassEnhancer {
return createCglibProxyForFactoryBean(factoryBean, beanFactory, beanName);
}
private Object createInterfaceProxyForFactoryBean(final Object factoryBean, Class<?> interfaceType,
final ConfigurableBeanFactory beanFactory, final String beanName) {
private Object createInterfaceProxyForFactoryBean(Object factoryBean, Class<?> interfaceType,
ConfigurableBeanFactory beanFactory, String beanName) {
return Proxy.newProxyInstance(
factoryBean.getClass().getClassLoader(), new Class<?>[] {interfaceType},
@ -502,8 +502,8 @@ class ConfigurationClassEnhancer { @@ -502,8 +502,8 @@ class ConfigurationClassEnhancer {
});
}
private Object createCglibProxyForFactoryBean(final Object factoryBean,
final ConfigurableBeanFactory beanFactory, final String beanName) {
private Object createCglibProxyForFactoryBean(Object factoryBean,
ConfigurableBeanFactory beanFactory, String beanName) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(factoryBean.getClass());

7
spring-context/src/main/java/org/springframework/context/annotation/Lazy.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2021 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,6 +47,11 @@ import java.lang.annotation.Target; @@ -47,6 +47,11 @@ import java.lang.annotation.Target;
* or {@link jakarta.inject.Inject}: In that context, it leads to the creation of a
* lazy-resolution proxy for all affected dependencies, as an alternative to using
* {@link org.springframework.beans.factory.ObjectFactory} or {@link jakarta.inject.Provider}.
* Please note that such a lazy-resolution proxy will always be injected; if the target
* dependency does not exist, you will only be able to find out through an exception on
* invocation. As a consequence, such an injection point results in unintuitive behavior
* for optional dependencies. For a programmatic equivalent, allowing for lazy references
* with more sophistication, consider {@link org.springframework.beans.factory.ObjectProvider}.
*
* @author Chris Beams
* @author Juergen Hoeller

4
spring-orm/src/main/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.java

@ -373,7 +373,7 @@ public class PersistenceAnnotationBeanPostProcessor @@ -373,7 +373,7 @@ public class PersistenceAnnotationBeanPostProcessor
}
private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?> clazz, @Nullable PropertyValues pvs) {
private InjectionMetadata findPersistenceMetadata(String beanName, Class<?> clazz, @Nullable PropertyValues pvs) {
// Fall back to class name as cache key, for backwards compatibility with custom callers.
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
// Quick check on the concurrent map first, with minimal locking.
@ -393,7 +393,7 @@ public class PersistenceAnnotationBeanPostProcessor @@ -393,7 +393,7 @@ public class PersistenceAnnotationBeanPostProcessor
return metadata;
}
private InjectionMetadata buildPersistenceMetadata(final Class<?> clazz) {
private InjectionMetadata buildPersistenceMetadata(Class<?> clazz) {
if (!AnnotationUtils.isCandidateClass(clazz, Arrays.asList(PersistenceContext.class, PersistenceUnit.class))) {
return InjectionMetadata.EMPTY;
}

8
spring-tx/src/main/java/org/springframework/dao/annotation/PersistenceExceptionTranslationPostProcessor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2021 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.
@ -38,7 +38,6 @@ import org.springframework.util.Assert; @@ -38,7 +38,6 @@ import org.springframework.util.Assert;
* PersistenceExceptionTranslator} interface, which are subsequently asked to translate
* candidate exceptions.
*
* <p>All of Spring's applicable resource factories (e.g.
* {@link org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean})
* implement the {@code PersistenceExceptionTranslator} interface out of the box.
@ -47,6 +46,11 @@ import org.springframework.util.Assert; @@ -47,6 +46,11 @@ import org.springframework.util.Assert;
* with the {@code @Repository} annotation, along with defining this post-processor
* as a bean in the application context.
*
* <p>As of 5.3, {@code PersistenceExceptionTranslator} beans will be sorted according
* to Spring's dependency ordering rules: see {@link org.springframework.core.Ordered}
* and {@link org.springframework.core.annotation.Order}. Note that such beans will
* get retrieved from any scope, not just singleton scope, as of this 5.3 revision.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @since 2.0

10
src/docs/asciidoc/core/core-beans.adoc

@ -3039,7 +3039,7 @@ constructor or setter argument or autowired field) as `ObjectFactory<MyTargetBea @@ -3039,7 +3039,7 @@ constructor or setter argument or autowired field) as `ObjectFactory<MyTargetBea
allowing for a `getObject()` call to retrieve the current instance on demand every
time it is needed -- without holding on to the instance or storing it separately.
As an extended variant, you may declare `ObjectProvider<MyTargetBean>`, which delivers
As an extended variant, you may declare `ObjectProvider<MyTargetBean>` which delivers
several additional access variants, including `getIfAvailable` and `getIfUnique`.
The JSR-330 variant of this is called `Provider` and is used with a `Provider<MyTargetBean>`
@ -6675,9 +6675,11 @@ factory method and other bean definition properties, such as a qualifier value t @@ -6675,9 +6675,11 @@ factory method and other bean definition properties, such as a qualifier value t
the `@Qualifier` annotation. Other method-level annotations that can be specified are
`@Scope`, `@Lazy`, and custom qualifier annotations.
TIP: In addition to its role for component initialization, you can also place the `@Lazy` annotation
on injection points marked with `@Autowired` or `@Inject`. In this context, it
leads to the injection of a lazy-resolution proxy.
TIP: In addition to its role for component initialization, you can also place the `@Lazy`
annotation on injection points marked with `@Autowired` or `@Inject`. In this context,
it leads to the injection of a lazy-resolution proxy. However, such a proxy approach
is rather limited. For sophisticated lazy interactions, in particular in combination
with optional dependencies, we recommend `ObjectProvider<MyTargetBean>` instead.
Autowired fields and methods are supported, as previously discussed, with additional
support for autowiring of `@Bean` methods. The following example shows how to do so:

Loading…
Cancel
Save