overriding bean configuration in spring

前端 未结 1 596
日久生厌
日久生厌 2021-01-02 08:45

Let\'s say I have two modules. One is core and another is core dependent implementation module. Core is a jar file for that dependent implementation module war.

In t

1条回答
  •  迷失自我
    2021-01-02 08:57

    One way of overriding the bean definition is what you have indicated - to define it with the same id multiple times and the last bean definition with the same id is the one which takes effect. So if you ensure that ExtX is the last one loaded up, it should just work, and to ensure this you can do this in your war file, instead of loading up by saying classpath:springfolder, you can explicitly import the core configuration in your war's Spring config file and then override the bean this way:

    
    
         
         
    
    

    This will ensure that your overridden bean is the one which takes effect.

    There is no priority/order field that you can make use of here though - if you want you can load up all bean definitions of a type by providing Map as a parameter, and sort it by expecting an order property and use it that way, but there is lot more work to it.

    A second approach is described here: Overriding the bean defined in parent context in a child context

    0 讨论(0)
提交回复
热议问题