Groovy loader should delegate to XML loader in the TCF
If a resource location in the MergedContextConfiguration has a ".xml" extension, the GenericGroovyXmlContextLoader now delegates to a dedicated XmlBeanDefinitionReader for loading bean definitions from that resource, thus preserving XML validation for all XML resource locations. For all other extensions (presumably only ".groovy"), the GenericGroovyXmlContextLoader delegates to a GroovyBeanDefinitionReader. Issue: SPR-11233
This commit is contained in:
parent
9fa4dad13c
commit
f862a009a7
|
|
@ -17,8 +17,10 @@
|
|||
package org.springframework.test.context.support;
|
||||
|
||||
import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Concrete implementation of {@link AbstractGenericContextLoader} that reads
|
||||
|
|
@ -36,12 +38,30 @@ import org.springframework.context.support.GenericApplicationContext;
|
|||
public class GenericGroovyXmlContextLoader extends GenericXmlContextLoader {
|
||||
|
||||
/**
|
||||
* Create a new {@link GroovyBeanDefinitionReader}.
|
||||
* @return a new {@code GroovyBeanDefinitionReader}
|
||||
* Load bean definitions into the supplied {@link GenericApplicationContext context}
|
||||
* from the locations in the supplied {@code MergedContextConfiguration}.
|
||||
*
|
||||
* <p>If a location ends with the suffix {@code ".xml"}, bean definitions
|
||||
* will be loaded from that location using an {@link XmlBeanDefinitionReader};
|
||||
* otherwise, a {@link GroovyBeanDefinitionReader} will be used.
|
||||
*
|
||||
* @param context the context into which the bean definitions should be loaded
|
||||
* @param mergedConfig the merged context configuration
|
||||
* @see org.springframework.test.context.support.AbstractGenericContextLoader#loadBeanDefinitions
|
||||
*/
|
||||
@Override
|
||||
protected BeanDefinitionReader createBeanDefinitionReader(final GenericApplicationContext context) {
|
||||
return new GroovyBeanDefinitionReader(context);
|
||||
protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
|
||||
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
|
||||
GroovyBeanDefinitionReader groovyReader = new GroovyBeanDefinitionReader(context);
|
||||
|
||||
for (String location : mergedConfig.getLocations()) {
|
||||
if (StringUtils.endsWithIgnoreCase(location, ".xml")) {
|
||||
xmlReader.loadBeanDefinitions(location);
|
||||
}
|
||||
else {
|
||||
groovyReader.loadBeanDefinitions(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue