Skip to content

Commit 1bde1ff

Browse files
committed
Documentation updates around configuration classes
(cherry picked from commit efb5f17)
1 parent 5f55add commit 1bde1ff

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/asciidoc/core-beans.adoc

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

29082908
[TIP]
29092909
====
2910-
29112910
The JSR-250 `@PostConstruct` and `@PreDestroy` annotations are generally considered best
29122911
practice for receiving lifecycle callbacks in a modern Spring application. Using these
29132912
annotations means that your beans are not coupled to Spring specific interfaces. For
@@ -6622,13 +6621,16 @@ The behavior could be different according to the scope of your bean. We are talk
66226621
about singletons here.
66236622
====
66246623

6625-
[NOTE]
6624+
[TIP]
66266625
====
66276626
There are a few restrictions due to the fact that CGLIB dynamically adds features at
6628-
startup-time:
6627+
startup-time, in particular that configuration classes must not be final and need to
6628+
have a default constructor with no arguments.
66296629
6630-
* Configuration classes should not be final
6631-
* They should have a constructor with no arguments
6630+
If you prefer to avoid any CGLIB-imposed limitations, consider declaring your `@Bean`
6631+
methods on non-`@Configuration` classes, e.g. on plain `@Component` classes instead.
6632+
Cross-method calls between `@Bean` methods won't get intercepted then, so you'll have
6633+
to exclusively rely on dependency injection at the field or method level there.
66326634
====
66336635

66346636

@@ -6688,6 +6690,14 @@ This approach simplifies container instantiation, as only one class needs to be
66886690
with, rather than requiring the developer to remember a potentially large number of
66896691
`@Configuration` classes during construction.
66906692

6693+
[TIP]
6694+
====
6695+
As of Spring Framework 4.2, `@Import` also supports references to regular component
6696+
classes, analogous to the `AnnotationConfigApplicationContext.register` method.
6697+
This is particularly useful if you'd like to avoid component scanning, using a few
6698+
configuration classes as entry points for explicitly defining all your components.
6699+
====
6700+
66916701
[[beans-java-injecting-imported-beans]]
66926702
===== Injecting dependencies on imported @Bean definitions
66936703

0 commit comments

Comments
 (0)