Defining the same Spring bean twice with same name

后端 未结 4 1252
名媛妹妹
名媛妹妹 2020-12-13 19:17

Is having two definition for a bean (with same name and class) valid in Spring IOC ?

I am having two bean definition files included in web.xml. See the sample below.

4条回答
  •  悲哀的现实
    2020-12-13 19:51

    This is valid and useful especially when you try to change the implementation of a third party bean (I mean, where you are not allowed to change the implementation of a bean) and Where you need to provide/configure some extra (merge) properties for the bean.

    The overriding of the bean depends upon the order of the xmls you provide to build the ApplicationContext through web.xml or stand-alone. The latest bean definition will win the game.

提交回复
热议问题