Announcement Announcement Module
No announcement yet.
Help needed... bind beans in several xml files Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help needed... bind beans in several xml files

    Hi all,

    I would like to know if this is possible to add new definitions of beans after we have initialized once the bean factory.

    To be more clear I have the following lines in my application:

    String[] configLocations = new String[] {

    beanFactory = new ClassPathXmlApplicationContext(configLocations, false);

    Those lines instantiate wired all my objects of the backend but actually I want also to wire the objects of my frontend. Therefore I would like to add other bean definitions to this factory after those lines (under) are executed.

    I do not find any methods which allow to add new definitions of beans without removing the beans that has already been loaded.
    Does anyone can tell if this is possible ? if yes how ?

    Thanks in advance,

  • #2
    Look at the methods on the AutowireCapableBeanFactory interface. With any of the Spring ApplicationContext implementations, you can cast it to ConfigurableApplicationContext, and get an AutowireCapableBeanFactory from that. You can then "autowire" existing instances, satisfying their dependencies from the factory.

    If you want to add a bean, you can look to the methods on DefaultListableBeanFactory.