c******n 发帖数: 4965 | 1 now in spring, as long as I write a in the .xml, it will be
created (lazily ??),
I wonder if there is a way to disable creating an bean depending on
properties settings, for example, my main bean is
let's say I decide that I won't give salary to employees in some cases, so
I don't need to use the salaryQueryer, is there a way to disable creating
the mySalaryQueryer at all? (without changing the .xml)
of course the design could be quite wrong, but I'm just thinking about
this particular problem now.
thanks | g*****g 发帖数: 34805 | 2 If you don't want to create mySalaryQueryer, don't put it
as a property of your Company bean.
You may dynamically get an instance using
BeanContext.getInstance().getCtx().getBean("mySalaryQueryer");
Make sure the queryer is lazy-init
【在 c******n 的大作中提到】 : now in spring, as long as I write a in the .xml, it will be : created (lazily ??), : I wonder if there is a way to disable creating an bean depending on : properties settings, for example, my main bean is : : : : let's say I decide that I won't give salary to employees in some cases, so : I don't need to use the salaryQueryer, is there a way to disable creating : the mySalaryQueryer at all? (without changing the .xml)
| w*******s 发帖数: 940 | 3 means
Company company = new Company();
while means
company.setSalaryQueryer(mySalaryQueryer);
【在 c******n 的大作中提到】 : now in spring, as long as I write a in the .xml, it will be : created (lazily ??), : I wonder if there is a way to disable creating an bean depending on : properties settings, for example, my main bean is : : : : let's say I decide that I won't give salary to employees in some cases, so : I don't need to use the salaryQueryer, is there a way to disable creating : the mySalaryQueryer at all? (without changing the .xml)
| c******n 发帖数: 4965 | 4 got it, essentially taking what is written in .xml form and put it in
.java code , which has the ability to dynamically construct members
based on property settings
【在 g*****g 的大作中提到】 : If you don't want to create mySalaryQueryer, don't put it : as a property of your Company bean. : You may dynamically get an instance using : BeanContext.getInstance().getCtx().getBean("mySalaryQueryer"); : Make sure the queryer is lazy-init
| r*****l 发帖数: 2859 | 5
【在 c******n 的大作中提到】 : now in spring, as long as I write a in the .xml, it will be : created (lazily ??), : I wonder if there is a way to disable creating an bean depending on : properties settings, for example, my main bean is : : : : let's say I decide that I won't give salary to employees in some cases, so : I don't need to use the salaryQueryer, is there a way to disable creating : the mySalaryQueryer at all? (without changing the .xml)
| r*****l 发帖数: 2859 | 6 You can use lookup method and put your switch there. If you queryer is not a
singleton, then this is not the expected use of lookup method though.
【在 c******n 的大作中提到】 : now in spring, as long as I write a in the .xml, it will be : created (lazily ??), : I wonder if there is a way to disable creating an bean depending on : properties settings, for example, my main bean is : : : : let's say I decide that I won't give salary to employees in some cases, so : I don't need to use the salaryQueryer, is there a way to disable creating : the mySalaryQueryer at all? (without changing the .xml)
|
|