-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Fedor Bobin opened SPR-10594 and commented
There is some limitations in current proxy instantiation model:
- class should have default constructor (but spring supports autowiring constructor arguments for object itself)
- calling the constructor can cause side-effects
- if constructor throws an exception proxy will not be created.
Note that proxy does not need to have any valid state at all.
Solution is to use Objenesis library ( http://objenesis.googlecode.com/svn/docs/index.html ). It can instantiate objects without calling any constructor and cglib-callbacks can be set after creation.
If Objenesis library is in classpath => create using it.
If no Objenesis library is in classpath => create using default constructor (fallback to current implementation).
So user that does not want to have Objenesis dependency in class path will have old instantiation model.
You can see proposed changes at #290
Additionaly there is a problem with proxy around Externalizable classes: this proxies are not serialized correctly. Solution is to make proxies implement java.io.Externalizable and add read/writeExternal implementations to them. It was done for proxies created by Objenesis. Seems that it should be done also for proxies created using default constructor.
Reference URL: #290
Issue Links:
- Method injection causes memory leak [SPR-10785] #15411 Method injection causes memory leak
- ObjenesisCglibAopProxy's fallback mode triggers duplicate class definition error [SPR-13131] #17722 ObjenesisCglibAopProxy's fallback mode triggers duplicate class definition error
- ProxyFactory should not discard objenesis cache, thereby enabling efficient proxy instantiation [SPR-12755] #17352 ProxyFactory should not discard objenesis cache, thereby enabling efficient proxy instantiation
- Create CGLIB proxy instances honoring <constructor-arg> tags [SPR-3150] #7836 Create CGLIB proxy instances honoring tags ("supersedes")
1 votes, 6 watchers