Announcement Announcement Module
Collapse
No announcement yet.
Ensuring fail on creation of duplicately-named beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ensuring fail on creation of duplicately-named beans

    Hi,

    I have about 100 applicationContext files, and want to ensure that if any beans are defined in these files with the same name, there is an exception at run-time, rather than what seems to be the default behaviour of overriding the previously defined bean.

    I can see the setAllowBeanDefinitionOverriding method in DefaultListableBeanFactory, but I'm not sure whether this is the best method to use, or even how to go about it... any suggestions?

    Thanks

  • #2
    That's the one I guess. N.B. you get different default behaviour when you are

    a) importing xml files into a config unit;

    b) creating a context from a String[] array of config locations;

    c) creating a context with a parent that has possibly duplicate bean ids.

    As far as I know, setAllowBeanDefinitionOverriding only applies to b). With a) I think it is always illegal to have duplicate ids, so you could just refactor your code to do that - it's probably the most common solution.

    With a large number of config files such as you have b) is the most flexible choice. The best way to do it is to use SingletonBeanFactoryLocator to configure your bean factories. that way you can choose the best mixture of a), b) and c), depending on what you need.

    Comment

    Working...
    X