tags:

views:

48

answers:

1

Hi all,

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.

I'd like to configure those objects in XML if that is possible without too much effort.

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).

In JBoss Seam, Jetty, I can instantiate components like so:

<New class="" id="">
  <Arg/>
  <Arg>
    <New class=""/>
  </Arg>
</New>

In 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. 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.

Thanks,

Walter

+1  A: 

I don't think that it is possible. Maybe what you need are 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>
Manolo Santos
Thats's the first thought I had. The only other thing I could think of is to used well known property values to instantiate the right objects in the bean. (i.e. <property name="fooDaoImpl" value="fooJdbcDao"/>) Contrived example, but another possibility.
Matt
Ok, I guess that will suffice, not as streamlined, but it gets the job done I suppose.