Skip to content

Commit 1ced8c3

Browse files
committed
Merge branch '6.1.x'
2 parents fd676ed + 0d90335 commit 1ced8c3

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Diff for: framework-docs/modules/ROOT/pages/core/aot.adoc

+14
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,20 @@ For instance, autowiring on fields and methods will be skipped as they are handl
378378

379379
Rather than having prototype-scoped beans created with custom arguments, we recommend a manual factory pattern where a bean is responsible for the creation of the instance.
380380

381+
[[aot.bestpractices.circular-dependencies]]
382+
=== Avoid Circular Dependencies
383+
384+
Certain use cases can result in circular dependencies between one or more beans. With the
385+
regular runtime, it may be possible to wire those circular dependencies via `@Autowired`
386+
on setter methods or fields. However, an AOT-optimized context will fail to start with
387+
explicit circular dependencies.
388+
389+
In an AOT-optimized application, you should therefore strive to avoid circular
390+
dependencies. If that is not possible, you can use `@Lazy` injection points or
391+
`ObjectProvider` to lazily access or retrieve the necessary collaborating beans. See
392+
xref:core/beans/classpath-scanning.adoc#beans-factorybeans-annotations-lazy-injection-points[this tip]
393+
for further information.
394+
381395
[[aot.bestpractices.factory-bean]]
382396
=== FactoryBean
383397

Diff for: framework-docs/modules/ROOT/pages/core/beans/classpath-scanning.adoc

+5-1
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,15 @@ factory method and other bean definition properties, such as a qualifier value t
480480
the `@Qualifier` annotation. Other method-level annotations that can be specified are
481481
`@Scope`, `@Lazy`, and custom qualifier annotations.
482482

483-
TIP: In addition to its role for component initialization, you can also place the `@Lazy`
483+
[[beans-factorybeans-annotations-lazy-injection-points]]
484+
[TIP]
485+
====
486+
In addition to its role for component initialization, you can also place the `@Lazy`
484487
annotation on injection points marked with `@Autowired` or `@Inject`. In this context,
485488
it leads to the injection of a lazy-resolution proxy. However, such a proxy approach
486489
is rather limited. For sophisticated lazy interactions, in particular in combination
487490
with optional dependencies, we recommend `ObjectProvider<MyTargetBean>` instead.
491+
====
488492

489493
Autowired fields and methods are supported, as previously discussed, with additional
490494
support for autowiring of `@Bean` methods. The following example shows how to do so:

Diff for: spring-context/src/test/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluatorTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void testMultipleCachingEval() {
8686
AnnotatedClass target = new AnnotatedClass();
8787
Method method = ReflectionUtils.findMethod(
8888
AnnotatedClass.class, "multipleCaching", Object.class, Object.class);
89-
Object[] args = new Object[] {new Object(), new Object()};
89+
Object[] args = {"arg1", "arg2"};
9090
Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
9191

9292
EvaluationContext evalCtx = this.eval.createEvaluationContext(caches, method, args,
@@ -155,7 +155,7 @@ private EvaluationContext createEvaluationContext(Object result, @Nullable BeanF
155155
AnnotatedClass target = new AnnotatedClass();
156156
Method method = ReflectionUtils.findMethod(
157157
AnnotatedClass.class, "multipleCaching", Object.class, Object.class);
158-
Object[] args = new Object[] {new Object(), new Object()};
158+
Object[] args = new Object[] {"arg1", "arg2"};
159159
Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
160160
return this.eval.createEvaluationContext(
161161
caches, method, args, target, target.getClass(), method, result);

0 commit comments

Comments
 (0)