Defining the same Spring bean twice with same name

后端 未结 4 1250
名媛妹妹
名媛妹妹 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 20:00

    It's valid, but you'll find that one bean is overridden by the other. You'll see this in the logs as

    Overriding bean definition for...
    

    This behaviour allows you to override previously supplied bean definitions. It affects the static assembly of your app, and doesn't relate to threading/clustering as suggested in your question.

    Note that the DefaultListableBeanFactory allows you to configure this behaviour via setAllowBeanDefinitionOverriding()

提交回复
热议问题