Skip to content

Scoped proxies are fragile with respect to serialization [SPR-14117] #18689

Closed
@spring-projects-issues

Description

@spring-projects-issues

Dave Syer opened SPR-14117 and commented

A scoped proxy (e.g. in @Scope("session") with @Lazy) carries a reference to a "serialization id" for the BeanFactory. This is in case, when it is deserialized, it needs to inject a dependency from the Spring context. As such, that can be quite useful, but it is also brittle, and not always necessary, since not all beans have dependencies to re-inject, and sometimes you want to share an instance between two contexts that don't naturally have the same serialization id.

There's quite a bit of discussion in one or two github issues related to Spring Cloud, Spring Boot and Spring OAuth2 (e.g. spring-attic/spring-security-oauth#705).

In the OAuth2 case we are only using @Scope("session") to keep the state segregated between concurrent users, and the data held in those beans is naturally serializable without any reference to the BeanFactory. I imagine this could be quite common, and I would like a way to annotate (or have Spring detect) that this is the case, so that the serialized form of the object does not contain a BeanFactory reference if it is not going to be needed.


Reference URL: spring-attic/spring-security-oauth#705

Issue Links:

Referenced from: commits 4024b2f

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