Does the Spring bean container command eliminate duplicate containers?

前端 未结 2 502
醉酒成梦
醉酒成梦 2021-01-17 14:13

Does the command of the Spring bean container eliminate duplicate containers? For example, if bean container file A imports B and C and each the

2条回答
  •  醉酒成梦
    2021-01-17 14:59

    It doesn't eliminate duplicate "containers", but it will eliminate duplicate bean definitions. So the beans in D will only be created once in the resulting bean factory. You'll get a face full of warnings about it, though.

    It's something best avoided. One bean definition which has the same ID as another will "hide" that bean definition, regardless of whether or not the type and properties of that bean are the same. Which one gets "hidden" depends on the declaration order. It's dangerous, and so Spring will warn you about it.

提交回复
热议问题