Announcement Announcement Module
No announcement yet.
DTD disallows both property and constructor-arg in same bean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 (
    (constructor-arg | property)*,
    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
    Please open an issue on JIRA.


    • #3
      Yes. mixing is semantically valid.


      • #4
        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.