Skip to content

Commit efb5f17

Browse files
committed
Documentation updates around configuration classes
(cherry picked from commit aff914c)
1 parent 086e764 commit efb5f17

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/asciidoc/core-beans.adoc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,7 +2946,6 @@ to perform certain actions upon initialization and destruction of your beans.
29462946

29472947
[TIP]
29482948
====
2949-
29502949
The JSR-250 `@PostConstruct` and `@PreDestroy` annotations are generally considered best
29512950
practice for receiving lifecycle callbacks in a modern Spring application. Using these
29522951
annotations means that your beans are not coupled to Spring specific interfaces. For
@@ -6715,13 +6714,17 @@ The behavior could be different according to the scope of your bean. We are talk
67156714
about singletons here.
67166715
====
67176716

6718-
[NOTE]
6717+
[TIP]
67196718
====
67206719
There are a few restrictions due to the fact that CGLIB dynamically adds features at
6721-
startup-time:
6720+
startup-time, in particular that configuration classes must not be final. However, as
6721+
of 4.3, any constructors are allowed on configuration classes, including the use of
6722+
`@Autowired` or a single non-default constructor declaration for default injection.
67226723
6723-
* Configuration classes should not be final
6724-
* They should have a constructor with no arguments
6724+
If you prefer to avoid any CGLIB-imposed limitations, consider declaring your `@Bean`
6725+
methods on non-`@Configuration` classes, e.g. on plain `@Component` classes instead.
6726+
Cross-method calls between `@Bean` methods won't get intercepted then, so you'll have
6727+
to exclusively rely on dependency injection at the constructor or method level there.
67256728
====
67266729

67276730

@@ -6781,6 +6784,14 @@ This approach simplifies container instantiation, as only one class needs to be
67816784
with, rather than requiring the developer to remember a potentially large number of
67826785
`@Configuration` classes during construction.
67836786

6787+
[TIP]
6788+
====
6789+
As of Spring Framework 4.2, `@Import` also supports references to regular component
6790+
classes, analogous to the `AnnotationConfigApplicationContext.register` method.
6791+
This is particularly useful if you'd like to avoid component scanning, using a few
6792+
configuration classes as entry points for explicitly defining all your components.
6793+
====
6794+
67846795
[[beans-java-injecting-imported-beans]]
67856796
===== Injecting dependencies on imported @Bean definitions
67866797

0 commit comments

Comments
 (0)