Spring dynamic injection, factory-like pattern

前端 未结 3 1108
情话喂你
情话喂你 2021-01-31 20:58

A continuation from Dependency injection, delayed injection praxis. I have the Main class:

package test;

import org.springframework.beans.factory.annotation.Aut         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-31 21:33

    Sounds like a user can choose 1..N graphs of Objects and you only want to load the one that the user selects at runtime. If the graphs are known at design time but the user just chooses the one they want then it sounds to me like what you have is a bunch of ApplicationContexts and you only want to load the one ApplicationContext that the user selects at runtime. So why not just define the set of ApplicationContexts and then just instantiate the right one at runtime. Since Spring supports Java Config it might make sense to define these configs as Java classes so you can get inheritance and avoid cutting/pasting any code.

提交回复
热议问题