提交 e24a7ded 编写于 作者: S Sam Brannen

Simplify Groovy ContextLoaders in the TCF

This commit simplifies the implementations of loadBeanDefinitions() in
GenericGroovyXmlContextLoader and GenericGroovyXmlWebContextLoader.

Due to the recent bug fix for GroovyBeanDefinitionReader regarding full
support for XML config files, these Groovy context loaders can now
simply use a GroovyBeanDefinitionReader instead of a
GroovyBeanDefinitionReader plus an XmlBeanDefinitionReader.

Issue: SPR-12769
上级 7edc7c2c
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,10 +17,8 @@
package org.springframework.test.context.support;
import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader;
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
......@@ -39,11 +37,8 @@ public class GenericGroovyXmlContextLoader extends GenericXmlContextLoader {
/**
* 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.
* from the locations in the supplied {@code MergedContextConfiguration} using a
* {@link GroovyBeanDefinitionReader}.
*
* @param context the context into which the bean definitions should be loaded
* @param mergedConfig the merged context configuration
......@@ -51,17 +46,7 @@ public class GenericGroovyXmlContextLoader extends GenericXmlContextLoader {
*/
@Override
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);
}
}
new GroovyBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations());
}
/**
......
......@@ -17,8 +17,6 @@
package org.springframework.test.context.web;
import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.util.StringUtils;
import org.springframework.web.context.support.GenericWebApplicationContext;
/**
......@@ -38,11 +36,8 @@ public class GenericGroovyXmlWebContextLoader extends GenericXmlWebContextLoader
/**
* Load bean definitions into the supplied {@link GenericWebApplicationContext context}
* from the locations in the supplied {@code WebMergedContextConfiguration}.
*
* <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.
* from the locations in the supplied {@code WebMergedContextConfiguration} using a
* {@link GroovyBeanDefinitionReader}.
*
* @param context the context into which the bean definitions should be loaded
* @param webMergedConfig the merged context configuration
......@@ -51,18 +46,7 @@ public class GenericGroovyXmlWebContextLoader extends GenericXmlWebContextLoader
@Override
protected void loadBeanDefinitions(GenericWebApplicationContext context,
WebMergedContextConfiguration webMergedConfig) {
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
GroovyBeanDefinitionReader groovyReader = new GroovyBeanDefinitionReader(context);
for (String location : webMergedConfig.getLocations()) {
if (StringUtils.endsWithIgnoreCase(location, ".xml")) {
xmlReader.loadBeanDefinitions(location);
}
else {
groovyReader.loadBeanDefinitions(location);
}
}
new GroovyBeanDefinitionReader(context).loadBeanDefinitions(webMergedConfig.getLocations());
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册