Results 1 to 4 of 4

Thread: DTD disallows both property and constructor-arg in same bean

  1. #1
    Join Date
    Dec 2004
    Posts
    2

    Default DTD disallows both property and constructor-arg in same bean

    The spring-beans.dtd does not allow the use of both constructor-based and setter-based injection in the same bean, i.e

    <!ELEMENT bean (
    description?,
    (constructor-arg | property)*,
    (lookup-method)*,
    (replaced-method)*
    )>
    Not knowing about this restriction, I created a couple beans that mixed both approaches and they worked fine. Both the c'tor args and the properties were set. This was using Spring 1.1.2; don't know about other versions. The application context was loaded via the ContextLoaderListener and XmlWebApplicationContext.

    My problem is that our XML tools complain about my configuration file since it violates the DTD.

    IMHO mixing both dependency injection approaches are valid. If the Spring code can handle this, can the DTD be changed?

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Please open an issue on JIRA.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Yes. mixing is semantically valid.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  4. #4
    Join Date
    Dec 2004
    Posts
    2

    Default

    A follow-up in case anyone else stumbles across this issue. Turns out the only XML editor that complained about combining constructor-arg and property elements in the same bean element was a configuration of Eclipse 3.1M2 and Spring IDE. Any other XML tool we've tried said mixing was OK.

    I filed a JIRA report on this, and Juergen Hoeller noted that:

    The current DTD is OK in that respect: the syntax there allows any mix of constructor-arg and property tags. We use the same syntax style in other parts of spring-beans.dtd too (for example, to define the list and the set tag). If an XML editor complains about that syntax, it does not properly support DTDs.
    So, ignore this thread and go ahead and mix and match injector styles.

Posting Permissions

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