我有一个 Spring 管理的 bean(应用程序范围,或者 Spring 世界中的单例),其中的属性是对象列表。
如果可能的话,我想在 XML 中配置这些对象,而不需要太多的努力。
如果我将它们声明为bean,那么我可以注入(inject)它们,但我不希望它们成为Spring管理的bean,配置更长,并且与使它们成为bean相关的额外开销(内存+cpu周期)。
在 JBoss Seam、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。
谢谢
沃尔特
最佳答案
我认为这是不可能的。也许您需要的是inner beans definitions .
<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>
关于java - Spring - 配置一个类而不是一个 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2185674/