Skip to content

Commit 2c3a8a5

Browse files
jhoellerunknown
authored and
unknown
committed
Removed parsing support for the 'singleton' attribute in an XML bean definition
Following the introduction of spring-beans-4.0.xsd and the corresponding removal of the pre-2.0 spring-beans.dtd. Issue: SPR-10437
1 parent 0fc5a5d commit 2c3a8a5

File tree

4 files changed

+4
-151
lines changed

4 files changed

+4
-151
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java

+2-28
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
136136

137137
private String scope = SCOPE_DEFAULT;
138138

139-
private boolean singleton = true;
140-
141-
private boolean prototype = false;
142-
143139
private boolean abstractFlag = false;
144140

145141
private boolean lazyInit = false;
@@ -409,8 +405,6 @@ public Class resolveBeanClass(ClassLoader classLoader) throws ClassNotFoundExcep
409405
*/
410406
public void setScope(String scope) {
411407
this.scope = scope;
412-
this.singleton = SCOPE_SINGLETON.equals(scope) || SCOPE_DEFAULT.equals(scope);
413-
this.prototype = SCOPE_PROTOTYPE.equals(scope);
414408
}
415409

416410
/**
@@ -420,33 +414,13 @@ public String getScope() {
420414
return this.scope;
421415
}
422416

423-
/**
424-
* Set if this a <b>Singleton</b>, with a single, shared instance returned
425-
* on all calls. In case of "false", the BeanFactory will apply the <b>Prototype</b>
426-
* design pattern, with each caller requesting an instance getting an independent
427-
* instance. How this is exactly defined will depend on the BeanFactory.
428-
* <p>"Singletons" are the commoner type, so the default is "true".
429-
* Note that as of Spring 2.0, this flag is just an alternative way to
430-
* specify scope="singleton" or scope="prototype".
431-
* @deprecated since Spring 2.5, in favor of {@link #setScope}
432-
* @see #setScope
433-
* @see #SCOPE_SINGLETON
434-
* @see #SCOPE_PROTOTYPE
435-
*/
436-
@Deprecated
437-
public void setSingleton(boolean singleton) {
438-
this.scope = (singleton ? SCOPE_SINGLETON : SCOPE_PROTOTYPE);
439-
this.singleton = singleton;
440-
this.prototype = !singleton;
441-
}
442-
443417
/**
444418
* Return whether this a <b>Singleton</b>, with a single shared instance
445419
* returned from all calls.
446420
* @see #SCOPE_SINGLETON
447421
*/
448422
public boolean isSingleton() {
449-
return this.singleton;
423+
return SCOPE_SINGLETON.equals(scope) || SCOPE_DEFAULT.equals(scope);
450424
}
451425

452426
/**
@@ -455,7 +429,7 @@ public boolean isSingleton() {
455429
* @see #SCOPE_PROTOTYPE
456430
*/
457431
public boolean isPrototype() {
458-
return this.prototype;
432+
return SCOPE_PROTOTYPE.equals(scope);
459433
}
460434

461435
/**

spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java

+1-56
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -166,28 +166,6 @@ public BeanDefinitionBuilder setFactoryMethod(String factoryMethod) {
166166
return this;
167167
}
168168

169-
/**
170-
* Set the name of the factory bean to use for this definition.
171-
* @deprecated since Spring 2.5, in favor of preparing this on the
172-
* {@link #getRawBeanDefinition() raw BeanDefinition object}
173-
*/
174-
@Deprecated
175-
public BeanDefinitionBuilder setFactoryBean(String factoryBean, String factoryMethod) {
176-
this.beanDefinition.setFactoryBeanName(factoryBean);
177-
this.beanDefinition.setFactoryMethodName(factoryMethod);
178-
return this;
179-
}
180-
181-
/**
182-
* Add an indexed constructor arg value. The current index is tracked internally
183-
* and all additions are at the present point.
184-
* @deprecated since Spring 2.5, in favor of {@link #addConstructorArgValue}
185-
*/
186-
@Deprecated
187-
public BeanDefinitionBuilder addConstructorArg(Object value) {
188-
return addConstructorArgValue(value);
189-
}
190-
191169
/**
192170
* Add an indexed constructor arg value. The current index is tracked internally
193171
* and all additions are at the present point.
@@ -253,17 +231,6 @@ public BeanDefinitionBuilder setScope(String scope) {
253231
return this;
254232
}
255233

256-
/**
257-
* Set whether or not this definition describes a singleton bean,
258-
* as alternative to {@link #setScope}.
259-
* @deprecated since Spring 2.5, in favor of {@link #setScope}
260-
*/
261-
@Deprecated
262-
public BeanDefinitionBuilder setSingleton(boolean singleton) {
263-
this.beanDefinition.setSingleton(singleton);
264-
return this;
265-
}
266-
267234
/**
268235
* Set whether or not this definition is abstract.
269236
*/
@@ -319,26 +286,4 @@ public BeanDefinitionBuilder setRole(int role) {
319286
return this;
320287
}
321288

322-
/**
323-
* Set the source of this definition.
324-
* @deprecated since Spring 2.5, in favor of preparing this on the
325-
* {@link #getRawBeanDefinition() raw BeanDefinition object}
326-
*/
327-
@Deprecated
328-
public BeanDefinitionBuilder setSource(Object source) {
329-
this.beanDefinition.setSource(source);
330-
return this;
331-
}
332-
333-
/**
334-
* Set the description associated with this definition.
335-
* @deprecated since Spring 2.5, in favor of preparing this on the
336-
* {@link #getRawBeanDefinition() raw BeanDefinition object}
337-
*/
338-
@Deprecated
339-
public BeanDefinitionBuilder setResourceDescription(String resourceDescription) {
340-
this.beanDefinition.setResourceDescription(resourceDescription);
341-
return this;
342-
}
343-
344289
}

spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java

-55
Original file line numberDiff line numberDiff line change
@@ -113,33 +113,6 @@ public RootBeanDefinition(Class beanClass) {
113113
setBeanClass(beanClass);
114114
}
115115

116-
/**
117-
* Create a new RootBeanDefinition with the given singleton status.
118-
* @param beanClass the class of the bean to instantiate
119-
* @param singleton the singleton status of the bean
120-
* @deprecated since Spring 2.5, in favor of {@link #setScope}
121-
*/
122-
@Deprecated
123-
public RootBeanDefinition(Class beanClass, boolean singleton) {
124-
super();
125-
setBeanClass(beanClass);
126-
setSingleton(singleton);
127-
}
128-
129-
/**
130-
* Create a new RootBeanDefinition for a singleton,
131-
* using the given autowire mode.
132-
* @param beanClass the class of the bean to instantiate
133-
* @param autowireMode by name or type, using the constants in this interface
134-
* @deprecated as of Spring 3.0, in favor of {@link #setAutowireMode} usage
135-
*/
136-
@Deprecated
137-
public RootBeanDefinition(Class beanClass, int autowireMode) {
138-
super();
139-
setBeanClass(beanClass);
140-
setAutowireMode(autowireMode);
141-
}
142-
143116
/**
144117
* Create a new RootBeanDefinition for a singleton,
145118
* using the given autowire mode.
@@ -157,34 +130,6 @@ public RootBeanDefinition(Class beanClass, int autowireMode, boolean dependencyC
157130
}
158131
}
159132

160-
/**
161-
* Create a new RootBeanDefinition for a singleton,
162-
* providing property values.
163-
* @param beanClass the class of the bean to instantiate
164-
* @param pvs the property values to apply
165-
* @deprecated as of Spring 3.0, in favor of {@link #getPropertyValues} usage
166-
*/
167-
@Deprecated
168-
public RootBeanDefinition(Class beanClass, MutablePropertyValues pvs) {
169-
super(null, pvs);
170-
setBeanClass(beanClass);
171-
}
172-
173-
/**
174-
* Create a new RootBeanDefinition with the given singleton status,
175-
* providing property values.
176-
* @param beanClass the class of the bean to instantiate
177-
* @param pvs the property values to apply
178-
* @param singleton the singleton status of the bean
179-
* @deprecated since Spring 2.5, in favor of {@link #setScope}
180-
*/
181-
@Deprecated
182-
public RootBeanDefinition(Class beanClass, MutablePropertyValues pvs, boolean singleton) {
183-
super(null, pvs);
184-
setBeanClass(beanClass);
185-
setSingleton(singleton);
186-
}
187-
188133
/**
189134
* Create a new RootBeanDefinition for a singleton,
190135
* providing constructor arguments and property values.

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

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -137,8 +137,6 @@ public class BeanDefinitionParserDelegate {
137137

138138
public static final String SCOPE_ATTRIBUTE = "scope";
139139

140-
public static final String SINGLETON_ATTRIBUTE = "singleton";
141-
142140
public static final String LAZY_INIT_ATTRIBUTE = "lazy-init";
143141

144142
public static final String AUTOWIRE_ATTRIBUTE = "autowire";
@@ -598,16 +596,7 @@ public AbstractBeanDefinition parseBeanDefinitionAttributes(Element ele, String
598596
BeanDefinition containingBean, AbstractBeanDefinition bd) {
599597

600598
if (ele.hasAttribute(SCOPE_ATTRIBUTE)) {
601-
// Spring 2.x "scope" attribute
602599
bd.setScope(ele.getAttribute(SCOPE_ATTRIBUTE));
603-
if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) {
604-
error("Specify either 'scope' or 'singleton', not both", ele);
605-
}
606-
}
607-
else if (ele.hasAttribute(SINGLETON_ATTRIBUTE)) {
608-
// Spring 1.x "singleton" attribute
609-
bd.setScope(TRUE_VALUE.equals(ele.getAttribute(SINGLETON_ATTRIBUTE)) ?
610-
BeanDefinition.SCOPE_SINGLETON : BeanDefinition.SCOPE_PROTOTYPE);
611600
}
612601
else if (containingBean != null) {
613602
// Take default from containing bean in case of an inner bean definition.

0 commit comments

Comments
 (0)