簡體   English   中英

Spring-雖然不將類配置為bean

[英]Spring - configuring a class not as a bean though

我有一個Spring管理的bean(應用程序作用域,或Spring世界中的單例),其中具有作為對象列表的屬性。

如果可能的話,我想在XML中配置這些對象。

如果我將它們聲明為Bean,則可以注入它們,但是我不希望它們成為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。

謝謝,

沃爾特

我認為不可能。 也許您需要的是內部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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM