-
Mar 14th, 2012, 10:10 AM
#1
Overriding bean scope
(I'm using Spring v3.1.1.)
I'm fond of the request bean scope and started using it heavily in my web services. I have run into a small issue, however.
After I implement the domain logic, which may use singleton-scoped or prototype-scoped beans, I wrap a web service interface around it. To avoid concurrency issues, I redefine some of the singleton-scoped or prototype-scoped beans (predominantly those that aren't stateless) to be request-scoped.
Unfortunately I need to duplicate the domain model's bean definitions in my service's bean definition and add a scope="request" property and a <aop:scoped-proxy> section to each bean that I redefine.
Is it possible to extend a bean definition instead of overriding it completely?
I have full access to the code and bean definition files.
-
Mar 16th, 2012, 05:57 PM
#2
There is bean definition inheritance in xml
<bean id="someParent" class="blah.Blah">
…property and other settings for shared information
<bean id="someChild" parent="someParent">
so someChild with have all the information set from someParent.
Hope that helps.
Personally, I have never seen a need to have a scope other than Singleton. If I find that I need a different scope, I use it as a code smell that something is up with my design, either that I am declaring beans for stateful objects that shouldn't be beans, or sthey shouldn't have state, or I just wrote bad code. Not that there aren't corner cases that might need a bean at a different scope, I have just never come across such a case.
Good Luck
Mark
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules