Announcement Announcement Module
Collapse
No announcement yet.
How to reference a bean from a bean? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to reference a bean from a bean?

    Hello all,

    I know this may sound like a stupid question but for some organizational reason I am trying to reference a bean from a bean (instead of a class) as follows (ps: the beanRef attribute is fake of course):

    in application-context.xml:
    <bean name="myService" beanRef="serviceX"/>

    in local-context.xml:
    <bean name=serviceX" class="com.james.someClass"/>

    Is this kind of configuration possible with Spring 2.5? If so how? I've been searching around the web but couldn't find any workaround to this.

    Thanks for any help,
    James
    Last edited by James Equalizer; Jan 23rd, 2008, 03:20 AM.

  • #2
    Have a look at the alias tag. That way you can define an alias for a bean already defined. It is only defining an alias, you cannot set any additional properties.

    Comment


    • #3
      Thanks. I have tried to use an alias but thing is the bean I am trying to reach is in a child context therefore the aliasing does not work. I'm looking now for a way to look into beans of child contexts, would that be possible?

      Many thanks,
      James

      Comment


      • #4
        No... The parents knows nothing of it's children, the children know of the parent.

        Comment


        • #5
          How about no parent/child relationship context in my case, like some kind of helper context where beans declaration could be shared throughout all the hierarchy?

          Thanks,
          James

          Comment


          • #6
            Why?

            Why not simply declare that context as the root/super parent?! Why hack around??

            Comment


            • #7
              Well actually the root context where lies the alias is the main context used by the spring web services MessageDispatcherServlet defined in web.xml. That's why I am bit stuck in terms of hacking around. Thanks anyhow

              Comment

              Working...
              X