@@ -3327,15 +3327,17 @@ overrides the method.
3327
3327
3328
3328
[NOTE]
3329
3329
====
3330
- For this dynamic subclassing to work, the class that the Spring container will subclass
3331
- cannot be `final`, and the method to be overridden cannot be `final` either. Also,
3332
- testing a class that has an `abstract` method requires you to subclass the class
3333
- yourself and to supply a stub implementation of the `abstract` method. Finally, objects
3334
- that have been the target of method injection cannot be serialized. As of Spring 3.2 it
3335
- is no longer necessary to add CGLIB to your classpath, because CGLIB classes are
3336
- repackaged under org.springframework and distributed within the spring-core JAR. This is
3337
- done both for convenience as well as to avoid potential conflicts with other projects
3338
- that use differing versions of CGLIB.
3330
+ * For this dynamic subclassing to work, the class that the Spring bean container will
3331
+ subclass cannot be `final`, and the method to be overridden cannot be `final` either.
3332
+ * Unit-testing a class that has an `abstract` method requires you to subclass the class
3333
+ yourself and to supply a stub implementation of the `abstract` method.
3334
+ * Concrete methods are also necessary for component scanning which requires concrete
3335
+ classes to pick up.
3336
+ * A further key limitation is that lookup methods won't work with factory methods and
3337
+ in particular not with `@Bean` methods in configuration classes, since the container
3338
+ is not in charge of creating the instance in that case and therefore cannot create
3339
+ a runtime-generated subclass on the fly.
3340
+ * Finally, objects that have been the target of method injection cannot be serialized.
3339
3341
====
3340
3342
3341
3343
Looking at the `CommandManager` class in the previous code snippet, you see that the
@@ -15610,13 +15612,10 @@ so. However, there are some issues to consider:
15610
15612
CGLIB classes are repackaged under org.springframework and included directly in the
15611
15613
spring-core JAR. This means that CGLIB-based proxy support 'just works' in the same
15612
15614
way that JDK dynamic proxies always have.
15613
- * The constructor of your proxied object will be called twice. This is a natural
15614
- consequence of the CGLIB proxy model whereby a subclass is generated for each proxied
15615
- object. For each proxied instance, two objects are created: the actual proxied object
15616
- and an instance of the subclass that implements the advice. This behavior is not
15617
- exhibited when using JDK proxies. Usually, calling the constructor of the proxied type
15618
- twice, is not an issue, as there are usually only assignments taking place and no real
15619
- logic is implemented in the constructor.
15615
+ * As of Spring 4.0, the constructor of your proxied object will NOT be called twice
15616
+ anymore since the CGLIB proxy instance will be created via Objenesis. Only if your
15617
+ JVM does not allow for constructor bypassing, you might see double invocations and
15618
+ corresponding debug log entries from Spring's AOP support.
15620
15619
15621
15620
To force the use of CGLIB proxies set the value of the `proxy-target-class` attribute of
15622
15621
the `<aop:config>` element to true:
0 commit comments