Results 1 to 5 of 5

Thread: Group beans by application

  1. #1

    Default Group beans by application

    Hi everybody,

    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'"?

    Thanks!!

  2. #2
    Join Date
    Jan 2006
    Location
    Seattle, Washington
    Posts
    467

    Default

    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.

  3. #3
    Join Date
    Oct 2008
    Posts
    136

    Default

    Quote Originally Posted by dkarr View Post

    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.
    "ref-local" looks only in the same context file IIRC.

  4. #4
    Join Date
    Jan 2006
    Location
    Seattle, Washington
    Posts
    467

    Default

    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.

  5. #5
    Join Date
    Oct 2008
    Posts
    136

    Default

    My knee jerk response was to look for 'namespace' in the docs TOC. The only thing that I found that seemed promising was NamespaceHandler

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •