Skip to content

XML config isn't fully supported for web integration tests if Groovy is on the classpath [SPR-12768] #17365

@spring-projects-issues

Description

@spring-projects-issues

Sam Brannen opened SPR-12768 and commented

Status Quo

As discussed in the "spring-test, groovy library and qualifier tag incompatibility" thread on Stack Overflow, it is currently impossible to configure an integration test using @WebAppConfiguration and XML config that uses the <qualifier> tag if Groovy is on the classpath. Any attempt to do so will result in a stack trace similar to the following.

Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unexpected failure during bean definition parsing
Offending resource: class path resource [spring/app-config.xml]
Bean 'service'; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Tag 'qualifier' must have a 'type' attribute
Offending resource: class path resource [spring/app-config.xml]

Analysis

The reason that the aforementioned BeanDefinitionParsingException is thrown is that GenericGroovyXmlWebContextLoader internally uses a GroovyBeanDefinitionReader for loading bean definitions from XML configuration files, and GroovyBeanDefinitionReader disables XML validation for its internal XmlBeanDefinitionReader.

The absence of XML validation apparently causes the default value of the type attribute (from the spring-beans XSD) in the <qualifier> tag to be ignored.


Temporary Work-around

It is possible to circumvent this bug by explicitly setting the type attribute in the <qualifier> tag to the intended default value which is "org.springframework.beans.factory.annotation.Qualifier" - for example, as follows.

<bean id="foo" class="java.lang.String" c:_="bar">
    <qualifier value="foo" type="org.springframework.beans.factory.annotation.Qualifier" />
</bean>

Deliverables

  1. Ensure that it is possible to use all features of XML configuration when loading a WebApplicationContext in the TestContext framework if Groovy is on the classpath.

Affects: 4.1 GA

Reference URL: http://stackoverflow.com/questions/28212993/spring-test-groovy-library-and-qualifier-tag-incompatibility

Issue Links:

Referenced from: commits 55eb5b6, 2ba1151

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions