Results 1 to 6 of 6

Thread: spring 2.0 extensible xml authoring help

  1. #1
    Join Date
    Jul 2006
    Posts
    3

    Default spring 2.0 extensible xml authoring help

    I'm new to the extensible xml authoring support in spring 2.0 so please bear with me if my question sounds very basic.

    I'm trying to simplify the bean definition files that we have in our product and am not able to find a solution to simplify a bean definition which looks something like below:

    <bean id="fooId" class="mypackage.FooClass" singleton="true">
    <property name="text" value="foo" />
    </bean>

    <bean id="barId" class="mypackage.BarClass">
    <property name="refBean" ref="fooId" />
    </bean>

    to something like:

    <mynamespace:foo text="foo"/>
    <mynamespace:bar refBean="fooId"/>

    Basically, I'm not sure whether there is some neat way to define a BeanDefinitionParser implementation for element "mynamespace:bar" so that I can specify in its bean definition that I want to use the singleton bean with id=fooId?

    Thanks in advance for the help

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    I have no experience with it myself, but have you read http://static.springframework.org/sp...sible-xml.html
    Colin Yates
    SpringSource - http://www.springsource.com - Spring Training, Consulting, and Support - "From the Source"
    Please read http://www.springframework.org/documentation
    Co-Author of Expert Spring MVC + Web Flow.

  3. #3
    Join Date
    Jul 2006
    Posts
    3

    Default

    Yeah, I went thru that document but unfortunately that talks about the simple case of how to set up the simple properties. Thanks.

  4. #4
    Join Date
    Jul 2006
    Posts
    3

    Default

    I found a quick fix to do this in the BeanDefinitionParser impl. Basically, I replicated what the BeanFactory does in the normal XML bean definition parser which is to associate a RuntimeBeanReference to the property and then add it to the bean defintion. So, the example mentioned above would look something like:

    beanDef.getPropertyValues().addPropertyValue(new PropertyValue("refBean", new RuntimeBeanReference("fooId")));

  5. #5
    Join Date
    Aug 2006
    Location
    Sydney
    Posts
    1

    Default Working sample needed

    Can you point out to any working(and downloadable) sample project for xml authoring? Or may be share yours? I am trying to migrate some of my old projects and I am getting all bunch of errors about missing schema and not known namespace handler.

  6. #6
    Join Date
    Oct 2004
    Location
    Houston
    Posts
    8

    Default

    beanDef.getPropertyValues().addPropertyValue(new PropertyValue("refBean", new RuntimeBeanReference("fooId")));
    thx for the advice above, works gr8

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •