From 0cf472b111c268e9771e899f65232640a3e335bc Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 17 Sep 2014 13:26:37 +0200 Subject: [PATCH] BeanDefinitionParserDelegate does not silently ignore 1.x 'singleton' attribute Issue: SPR-12167 --- .../xml/BeanDefinitionParserDelegate.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java index 16e10fb832..37cd92132d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeanDefinitionParserDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -137,6 +137,8 @@ public class BeanDefinitionParserDelegate { public static final String SCOPE_ATTRIBUTE = "scope"; + private static final String SINGLETON_ATTRIBUTE = "singleton"; + public static final String LAZY_INIT_ATTRIBUTE = "lazy-init"; public static final String AUTOWIRE_ATTRIBUTE = "autowire"; @@ -244,12 +246,12 @@ public class BeanDefinitionParserDelegate { private final XmlReaderContext readerContext; + private final Environment environment; + private final DocumentDefaultsDefinition defaults = new DocumentDefaultsDefinition(); private final ParseState parseState = new ParseState(); - private Environment environment; - /** * Stores all used bean names so we can enforce uniqueness on a per * beans-element basis. Duplicate bean ids/names may not exist within the @@ -264,7 +266,7 @@ public class BeanDefinitionParserDelegate { */ public BeanDefinitionParserDelegate(XmlReaderContext readerContext, Environment environment) { Assert.notNull(readerContext, "XmlReaderContext must not be null"); - Assert.notNull(readerContext, "Environment must not be null"); + Assert.notNull(environment, "Environment must not be null"); this.readerContext = readerContext; this.environment = environment; } @@ -280,6 +282,7 @@ public class BeanDefinitionParserDelegate { this(readerContext, new StandardEnvironment()); } + /** * Get the {@link XmlReaderContext} associated with this helper instance. */ @@ -592,7 +595,10 @@ public class BeanDefinitionParserDelegate { public AbstractBeanDefinition parseBeanDefinitionAttributes(Element ele, String beanName, BeanDefinition containingBean, AbstractBeanDefinition bd) { - if (ele.hasAttribute(SCOPE_ATTRIBUTE)) { + if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) { + error("Old 1.x 'singleton' attribute in use - upgrade to 'scope' declaration", ele); + } + else if (ele.hasAttribute(SCOPE_ATTRIBUTE)) { bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE)); } else if (containingBean != null) {