Scoped proxies are fragile with respect to serialization [SPR-14117] #18689
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
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 theBeanFactory
. 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 theBeanFactory
. 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 aBeanFactory
reference if it is not going to be needed.Reference URL: spring-attic/spring-security-oauth#705
Issue Links:
Referenced from: commits 4024b2f
The text was updated successfully, but these errors were encountered: