How to do conditional auto-wiring in Spring?

前端 未结 4 1956
一整个雨季
一整个雨季 2020-11-28 02:59

Has anyone tried to auto-wire different beans into a Spring-managed bean based on a condition? For e.g. if some condition is met, inject class A, else B? I saw in one of the

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 03:05

    I had a case where I needed to inject different beans depending on property: "my.property". In my case this solution was successful:

     
    

    I needed to add the apostrophes around bean names in order to make it work.

提交回复
热议问题