[英]Spring - configuring a class not as a bean though
I have a Spring-managed bean (Application-scoped, or a singleton in the Spring world) that has properties within it that are a list of objects. 我有一个Spring管理的bean(应用程序作用域,或Spring世界中的单例),其中具有作为对象列表的属性。
I'd like to configure those objects in XML if that is possible without too much effort. 如果可能的话,我想在XML中配置这些对象。
If I declare them as a bean, then I can inject them, but I don't want them to be Spring-managed beans, the configuration is longer, and there is additional overhead associated with making them beans (memory + cpu cycles). 如果我将它们声明为Bean,则可以注入它们,但是我不希望它们成为Spring管理的Bean,配置会更长,并且与使它们成为Bean(内存+ CPU周期)相关的额外开销。
In JBoss Seam, Jetty, I can instantiate components like so: 在JBoss Seam,Jetty中,我可以实例化组件,如下所示:
<New class="" id="">
<Arg/>
<Arg>
<New class=""/>
</Arg>
</New>
In JBoss Seam: 在JBoss Seam中:
<mypackage:class-name id="someComponent">
<component:property name="items">
<mypackage:other-class-name title="The Great Gatsby" pages="201"/>
</...>
</...>
I want the main item to be a component / bean, but not the inner components. 我希望主要项目是组件/ bean,而不是内部组件。 I just want those to be anonymous, no lifecycle associated with them other than the lifecycle inherited from their parent. 我只希望它们是匿名的,除了从其父级继承的生命周期外,没有与它们相关联的生命周期。
The inner items would be mypackage:other-class-name and the New within the Arg element. 内部项目是mypackage:other-class-name和Arg元素中的New。
Thanks, 谢谢,
Walter 沃尔特
I don't think that it is possible. 我认为不可能。 Maybe what you need are inner beans definitions . 也许您需要的是内部bean定义 。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.