Skip to content

Commit e36a415

Browse files
committed
Explain FactoryBean lifecycle management and destroy method handling
Closes gh-24948
1 parent 401f959 commit e36a415

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -39,10 +39,16 @@
3939
*
4040
* <p><b>{@code FactoryBean} is a programmatic contract. Implementations are not
4141
* supposed to rely on annotation-driven injection or other reflective facilities.</b>
42-
* {@link #getObjectType()} {@link #getObject()} invocations may arrive early in
43-
* the bootstrap process, even ahead of any post-processor setup. If you need access
42+
* {@link #getObjectType()} {@link #getObject()} invocations may arrive early in the
43+
* bootstrap process, even ahead of any post-processor setup. If you need access to
4444
* other beans, implement {@link BeanFactoryAware} and obtain them programmatically.
4545
*
46+
* <p><b>The container is only responsible for managing the lifecycle of the FactoryBean
47+
* instance, not the lifecycle of the objects created by the FactoryBean.</b> Therefore,
48+
* a destroy method on an exposed bean object (such as {@link java.io.Closeable#close()}
49+
* will <i>not</i> be called automatically. Instead, a FactoryBean should implement
50+
* {@link DisposableBean} and delegate any such close call to the underlying object.
51+
*
4652
* <p>Finally, FactoryBean objects participate in the containing BeanFactory's
4753
* synchronization of bean creation. There is usually no need for internal
4854
* synchronization other than for purposes of lazy initialization within the

0 commit comments

Comments
 (0)