Announcement Announcement Module
No announcement yet.
Bean locator question Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bean locator question

    Hello all,

    We have a project with a number of components each with their own Spring configuration file.

    All components are deployed into the same application ear file.

    We have a spring bean (which is wrapped with the TransactionFactoryProxyBean to define transactional behaviour) within one of our core components (lets call it A).

    This bean needs to be called from another component (again with its own configuration file, lets call it B) and we would ideally like this component to simply lookup the bean in component A rather than redefine it (along with the proxy class) in its own Spring configuration file.

    At the moment component B calling the bean in component A does the following:

    ContextSingletonBeanFactoryLocator.getInstance().u seBeanFactory("com.something.componentA").getFacto ry().getBean("mybean");

    Now while we can externalise the bean factory and mybean lookup keys, what we would like to do is put all this in the component B's configuration file.

    So what I am asking is can one Spring context file reference a bean from another bean reference context file?

    Hope someone can help!


  • #2
    If you load all configuration files in one context you can simply reference the bean, no need to do lookups etc. For instance if you name all configuration files applicationContext.xml you can load them all at once by

    ApplicationContext ctc = new ClassPathXmlApplicationContext("classpath*:applicationContext.xml");


    • #3
      Thanks for the reponse.

      Unfortunatly that is not an option as our architecture (which uses EJBs with Spring support) utilizes the concept of an ApplicationContext bag, which contains inner bean factories. This approach has been agreed already with two other vendors writing components for the same application/client and its too late to change it - especially for such a small change.

      Any other ideas....