Skip to content

Add ability to create proxy around classes that has no default constructor [SPR-10594] #15223

@spring-projects-issues

Description

@spring-projects-issues

Fedor Bobin opened SPR-10594 and commented

There is some limitations in current proxy instantiation model:

  1. class should have default constructor (but spring supports autowiring constructor arguments for object itself)
  2. calling the constructor can cause side-effects
  3. 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:

1 votes, 6 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions