boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - spring creating objects depending on properties?
相关主题
关于 Java bean
这三种方法获得EJB有何不同?
Inject property file into a spring bean?
问个spring问题
Java中如何动态生成对象
JMS消息发布的问题
怎样让一个servlet返回到jsp的HTML-object?
spring frame work question
哪个JSON Library最好用呢
请教一个spring的问题
相关话题的讨论汇总
话题: bean话题: creating话题: company
进入Java版参与讨论
1 (共1页)
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)

1 (共1页)
进入Java版参与讨论
相关主题
请教一个spring的问题
问一个spring dynamic module/OSGi的问题
what's inside an java object?
How to know the size of a java object ?
Javascript speed up
Argh, maven sucks
dependency version collision problem
ant dependency analyzer
in eclipse, how do you use inter dependencies?
jetty疑问
相关话题的讨论汇总
话题: bean话题: creating话题: company