Announcement Announcement Module
Collapse
No announcement yet.
cross-container bean sharing/identification? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • cross-container bean sharing/identification?

    in a single JVM, i've got several AppContext's configured.
    is it possible to reference beans in the config file that i know will be in a different context?

    For instance:
    file(a)
    <bean id="foo" class="Foo"/>

    file(b)
    <bean id="Bar" class="Bar">
    <constructor-arg index="0"><ref bean="foo"/></constructor-arg>
    </bean>

    each file is then used to build a context within a java class.
    obviously since file(a) is in a different context, then file(b) doesn't know what bean="foo" is, so what would be the best way to accomplish this?

    thanks

  • #2
    The only way (I'm aware of) to get this done declaratively would be to either use an "import" directive to import one context into the other, or merge the two files into one ApplicationContext.
    I would recommend the latter approach if possible, since that way the files are more loosely coupled.

    Regards,
    Andreas

    Comment


    • #3
      yeah, currently i'm looping over all xml files, creating a string[] then passing that to a single configurableApplicationContext for creation of one container.
      the parent/child relationship won't work for me either, b/c child containers can only see up, not the other way around, so a parent wouldn't have knowledge of beans in a child appl ctx's container

      Comment


      • #4
        maybe that's what you need?..

        Not sure if I understood your particular challenge, but may be you just need bean factory configuration. Eg, the following works for me and merges all beans.xml context in one, so that all siblings have access to each other beans as well as those declared in parent factories:

        Code:
        <beans>
          <bean id="com.artilekt.modules.jetmailer" lazy-init="true"
                class="org.springframework.context.support.ClassPathXmlApplicationContext">
            <constructor-arg>
              <list>
                <value>classpath*:com/artilekt/modules/jetmailer/**/beans.xml</value>
                <value>classpath*:com/artilekt/modules/template/**/beans.xml</value>
                <value>com/artilekt/modules/configurer/beans.xml</value>
              </list>
            </constructor-arg>
          </bean>
        </beans>
        You might want to check out SingletonBeanFactoryLocator class documentation (http://www.springframework.org/docs/...ryLocator.html) if you haven't yet for possible use case scenarios...

        Comment

        Working...
        X