Aurel Medvegy opened SPR-9963 and commented

Documentation 4.5.4.5 Scoped beans as dependencies says:

"Note: You do not need to use the <aop:scoped-proxy/> in conjunction with beans that are scoped as singletons or prototypes. If you try to create a scoped proxy for a singleton bean, the BeanCreationException is raised."

but implementation for example:

<bean id="districtService" class="com.domain.my.services.impl.DistrictServiceImpl" >
        <aop:scoped-proxy/>
</bean>

doesn't raise any exception. So what's correct?


Affects: 3.1.1

Reference URL: http://static.springsource.org/spring/docs/current/spring-framework-reference/htmlsingle/spring-framework-reference.html#beans-factory-scopes-other-injection

Issue Links: - #12595 Update documentation regarding scoped-proxy and singleton beans ("duplicates")

1 votes, 3 watchers

Comment From: spring-projects-issues

Slavomir Kocka commented

Just intention explanation. We need to access singletons from session objects. Therefore singletons needs to be serialized, what we think, is wrong. The main purpose is to use this application in cluster. What happens, if session is replicated (including session beans), with pointers to singletons in another JVM? We guess this scoped proxy (as it is serializable by default) could help. But documentation doesn't mention this case. However we fully understand, that scoped proxy was intentionaly designed to be used for exactly opposite case... (singleton points to session object)

Comment From: spring-projects-issues

Phil Webb commented

Looks like this is a duplicate of #12595 which has since been fixed.

For your particular use-case you could consider using javax.inject.Provider from JSR-330. I believe that Spring's implementations of this interface are Serializable.