Skip to content

Commit b7d7fa7

Browse files
committed
Further compensations for STS; binary compat fixes
Defensively catch NoSuchMethodError when calling BDPD.getEnvironment() and supply a DefaultEnvironment if not available. Replace the single-arg constructor for BDPD and deprecate, preserving binary compat particularly for Spring Integration who instantiates this class directly, which is unusual.
1 parent 9cc1255 commit b7d7fa7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

org.springframework.beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.apache.commons.logging.Log;
2929
import org.apache.commons.logging.LogFactory;
30+
3031
import org.w3c.dom.Element;
3132
import org.w3c.dom.NamedNodeMap;
3233
import org.w3c.dom.Node;
@@ -58,6 +59,7 @@
5859
import org.springframework.beans.factory.support.ManagedSet;
5960
import org.springframework.beans.factory.support.MethodOverrides;
6061
import org.springframework.beans.factory.support.ReplaceOverride;
62+
import org.springframework.core.env.DefaultEnvironment;
6163
import org.springframework.core.env.Environment;
6264
import org.springframework.util.Assert;
6365
import org.springframework.util.ClassUtils;
@@ -265,6 +267,17 @@ public BeanDefinitionParserDelegate(XmlReaderContext readerContext, Environment
265267
this.environment = environment;
266268
}
267269

270+
/**
271+
* Create a new BeanDefinitionParserDelegate associated with the
272+
* supplied {@link XmlReaderContext} and a new {@link DefaultEnvironment}.
273+
* @deprecated since Spring 3.1 in favor of
274+
* {@link #BeanDefinitionParserDelegate(XmlReaderContext, Environment)}
275+
*/
276+
@Deprecated
277+
public BeanDefinitionParserDelegate(XmlReaderContext readerContext) {
278+
this(readerContext, new DefaultEnvironment());
279+
}
280+
268281
/**
269282
* Get the {@link XmlReaderContext} associated with this helper instance.
270283
*/

org.springframework.context/src/main/java/org/springframework/context/config/AbstractSpecificationBeanDefinitionParser.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.springframework.beans.factory.parsing.ReaderContext;
2525
import org.springframework.beans.factory.xml.BeanDefinitionParser;
2626
import org.springframework.beans.factory.xml.ParserContext;
27+
import org.springframework.core.env.DefaultEnvironment;
2728
import org.w3c.dom.Element;
2829

2930
/**
@@ -54,11 +55,19 @@ private SpecificationContext specificationContextFrom(ParserContext parserContex
5455
specContext.setRegistry(parserContext.getRegistry());
5556
specContext.setRegistrar(new ComponentRegistrarAdapter(parserContext));
5657
specContext.setResourceLoader(parserContext.getReaderContext().getResourceLoader());
57-
specContext.setEnvironment(parserContext.getDelegate().getEnvironment());
58+
try {
59+
// again, STS constraints around the addition of the new getEnvironment()
60+
// method in 3.1.0 (it's not present in STS current spring version, 3.0.5)
61+
// TODO 3.1 GA: remove this block prior to 3.1 GA
62+
specContext.setEnvironment(parserContext.getDelegate().getEnvironment());
63+
} catch (NoSuchMethodError ex) {
64+
specContext.setEnvironment(new DefaultEnvironment());
65+
}
5866
try {
5967
// access the reader context's problem reporter reflectively in order to
6068
// compensate for tooling (STS) constraints around introduction of changes
6169
// to parser context / reader context classes.
70+
// TODO 3.1 GA: remove this block prior to 3.1 GA
6271
Field field = ReaderContext.class.getDeclaredField("problemReporter");
6372
field.setAccessible(true);
6473
ProblemReporter problemReporter = (ProblemReporter)field.get(parserContext.getReaderContext());

0 commit comments

Comments
 (0)