From e24a7ded620b74110141bc6d4a80ae86c74c157b Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 28 Feb 2015 23:28:55 +0100 Subject: [PATCH] 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 --- .../GenericGroovyXmlContextLoader.java | 23 ++++--------------- .../web/GenericGroovyXmlWebContextLoader.java | 22 +++--------------- 2 files changed, 7 insertions(+), 38 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/support/GenericGroovyXmlContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/support/GenericGroovyXmlContextLoader.java index 47b62142cf..83ee2ba572 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/GenericGroovyXmlContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/GenericGroovyXmlContextLoader.java @@ -1,5 +1,5 @@ /* - * 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}. - * - *

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()); } /** diff --git a/spring-test/src/main/java/org/springframework/test/context/web/GenericGroovyXmlWebContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/web/GenericGroovyXmlWebContextLoader.java index 61d7a927b3..93d2706950 100644 --- a/spring-test/src/main/java/org/springframework/test/context/web/GenericGroovyXmlWebContextLoader.java +++ b/spring-test/src/main/java/org/springframework/test/context/web/GenericGroovyXmlWebContextLoader.java @@ -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}. - * - *

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()); } /**