From 62eb21f93867d4fef7570b8e1db8352845905827 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 13 Nov 2024 15:09:58 +0100 Subject: [PATCH] Add note on declaring autowired fields as ObjectProvider Closes gh-33834 --- .../springframework/cache/annotation/CachingConfigurer.java | 4 ++++ .../annotation/TransactionManagementConfigurer.java | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java index 85c372dfeb3c..05babe1da464 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java @@ -32,6 +32,10 @@ * {@link #cacheManager()}, {@link #cacheResolver()}, {@link #keyGenerator()}, and * {@link #errorHandler()} for detailed instructions. * + *

NOTE: A {@code CachingConfigurer} will get initialized early. + * Do not inject common dependencies into autowired fields directly; instead, consider + * declaring a lazy {@link org.springframework.beans.factory.ObjectProvider} for those. + * * @author Chris Beams * @author Stephane Nicoll * @since 3.1 diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionManagementConfigurer.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionManagementConfigurer.java index c6c4e37ff41d..55775347ace2 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionManagementConfigurer.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionManagementConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -30,6 +30,10 @@ *

See @{@link EnableTransactionManagement} for general examples and context; * see {@link #annotationDrivenTransactionManager()} for detailed instructions. * + *

NOTE: A {@code TransactionManagementConfigurer} will get initialized early. + * Do not inject common dependencies into autowired fields directly; instead, consider + * declaring a lazy {@link org.springframework.beans.factory.ObjectProvider} for those. + * *

Note that in by-type lookup disambiguation cases, an alternative approach to * implementing this interface is to simply mark one of the offending * {@code PlatformTransactionManager} {@code @Bean} methods (or