Oct 21st, 2009, 12:59 AM
Group beans by application
I would like to know if it's possible to group beans by a prefix or an identifier (other than id). I mean, I have two projects, with each application context. But there are beans with the same id and when I use both application contexts together, there is a problem with the beans of the same id. Is there any way to say "well, I have one A project's bean with id 'myBean' and other bean from B project with id 'myBean', but I reference them like 'A.myBean' and 'B.myBean'"?
Oct 21st, 2009, 11:34 AM
What exactly do you mean by "use both application contexts together"? If these two projects are separate webapps, you should be able to deploy them as separate webapps, and they will not conflict.
I think it's possible to specify bean references that only look in the local context, but I don't think there's a way to specify bean definitions as only local to the context.
If these two projects are merged into the same webapp or standalone app, you may not have much choice besides changing the id values to be different. You might consider using a convention I've seen in Guice, which is to define id values in a package namespace, exactly like your "A.myBean" and "B.myBean" names. I can see it might be confusing to have two separate package hierarchies, one for Java, and one for Spring ids. Using caps for the Spring package components might help to differentiate them.
Oct 22nd, 2009, 02:01 PM
"ref-local" looks only in the same context file IIRC.
Originally Posted by dkarr
Oct 22nd, 2009, 02:06 PM
Yes. That's what I meant. You can have references that specifically target beans defined in the local context, but there's no way I know of to define a bean that is only visible in the local context.
Oct 22nd, 2009, 02:15 PM
My knee jerk response was to look for 'namespace' in the docs TOC. The only thing that I found that seemed promising was NamespaceHandler