我有一个Spring管理的bean (应用程序范围的bean,或者Spring世界中的单例bean),它的属性是一个对象列表。
如果可以的话,我想在XML中配置这些对象,不需要太多的工作。
如果我将它们声明为bean,那么我就可以注入它们,但我不希望它们是Spring管理的bean,配置较长,并且与使它们成为bean(内存+ cpu周期)相关的额外开销。
在Jetty中,我可以像这样实例化组件:
<New class="" id="">
<Arg/>
<Arg>
<New class=""/>
</Arg>
</New>
在JBoss Seam中:
<mypackage:class-name id="someComponent">
<component:property name="items">
<mypackage:other-class-name title="The Great Gatsby" pages="201"/>
</...>
</...>
我希望主项目是组件/ bean,而不是内部组件。我只希望它们是匿名的,除了从它们的父类继承的生命周期之外,没有与它们相关的生命周期。
内部项是mypackage:other-class-name和Arg元素中的New。
谢谢,
沃尔特
发布于 2010-02-03 20:46:12
我认为这是不可能的。也许你需要的是。
<bean id="outer" class="...">
<!-- instead of using a reference to a target bean, simply define the target bean inline -->
<property name="target">
<bean class="com.example.Person"> <!-- this is the inner bean -->
<property name="name" value="Fiona Apple"/>
<property name="age" value="25"/>
</bean>
</property>
</bean>
https://stackoverflow.com/questions/2185674
复制相似问题