diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java index 535d2a8e9611bffc31652bc1cf66d0eb53c1146f..c9e0db6ad85885e29f7b0531577ebdd6a245aa11 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java @@ -79,10 +79,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { int ROLE_INFRASTRUCTURE = 2; - /** - * Return the name of the parent definition of this bean definition, if any. - */ - String getParentName(); + // Modifiable attributes /** * Set the name of the parent definition of this bean definition, if any. @@ -90,46 +87,40 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { void setParentName(String parentName); /** - * Return the current bean class name of this bean definition. - *
Note that this does not have to be the actual class name used at runtime, in - * case of a child definition overriding/inheriting the class name from its parent. - * Hence, do not consider this to be the definitive bean type at runtime but - * rather only use it for parsing purposes at the individual bean definition level. + * Return the name of the parent definition of this bean definition, if any. */ - String getBeanClassName(); + String getParentName(); /** - * Override the bean class name of this bean definition. + * Specify the bean class name of this bean definition. *
The class name can be modified during bean factory post-processing, * typically replacing the original class name with a parsed variant of it. + * @see #setParentName + * @see #setFactoryBeanName + * @see #setFactoryMethodName */ void setBeanClassName(String beanClassName); /** - * Return the factory bean name, if any. - */ - String getFactoryBeanName(); - - /** - * Specify the factory bean to use, if any. - */ - void setFactoryBeanName(String factoryBeanName); - - /** - * Return a factory method, if any. + * Return the current bean class name of this bean definition. + *
Note that this does not have to be the actual class name used at runtime, in + * case of a child definition overriding/inheriting the class name from its parent. + * Also, this may just be the class that a factory method is called on, or it may + * even be empty in case of a factory bean reference that a method is called on. + * Hence, do not consider this to be the definitive bean type at runtime but + * rather only use it for parsing purposes at the individual bean definition level. + * @see #getParentName() + * @see #getFactoryBeanName() + * @see #getFactoryMethodName() */ - String getFactoryMethodName(); + String getBeanClassName(); /** - * Specify a factory method, if any. This method will be invoked with - * constructor arguments, or with no arguments if none are specified. - * The method will be invoked on the specified factory bean, if any, - * or otherwise as a static method on the local bean class. - * @param factoryMethodName static factory method name, - * or {@code null} if normal constructor creation should be used - * @see #getBeanClassName() + * Override the target scope of this bean, specifying a new scope name. + * @see #SCOPE_SINGLETON + * @see #SCOPE_PROTOTYPE */ - void setFactoryMethodName(String factoryMethodName); + void setScope(String scope); /** * Return the name of the current target scope for this bean, @@ -138,11 +129,11 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { String getScope(); /** - * Override the target scope of this bean, specifying a new scope name. - * @see #SCOPE_SINGLETON - * @see #SCOPE_PROTOTYPE + * Set whether this bean should be lazily initialized. + *
If {@code false}, the bean will get instantiated on startup by bean + * factories that perform eager initialization of singletons. */ - void setScope(String scope); + void setLazyInit(boolean lazyInit); /** * Return whether this bean should be lazily initialized, i.e. not @@ -151,11 +142,10 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { boolean isLazyInit(); /** - * Set whether this bean should be lazily initialized. - *
If {@code false}, the bean will get instantiated on startup by bean - * factories that perform eager initialization of singletons. + * Set the names of the beans that this bean depends on being initialized. + * The bean factory will guarantee that these beans get initialized first. */ - void setLazyInit(boolean lazyInit); + void setDependsOn(String... dependsOn); /** * Return the bean names that this bean depends on. @@ -163,10 +153,13 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { String[] getDependsOn(); /** - * Set the names of the beans that this bean depends on being initialized. - * The bean factory will guarantee that these beans get initialized first. + * Set whether this bean is a candidate for getting autowired into some other bean. + *
Note that this flag is designed to only affect type-based autowiring. + * It does not affect explicit references by name, which will get resolved even + * if the specified bean is not marked as an autowire candidate. As a consequence, + * autowiring by name will nevertheless inject a bean if the name matches. */ - void setDependsOn(String... dependsOn); + void setAutowireCandidate(boolean autowireCandidate); /** * Return whether this bean is a candidate for getting autowired into some other bean. @@ -174,24 +167,43 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { boolean isAutowireCandidate(); /** - * Set whether this bean is a candidate for getting autowired into some other bean. + * Set whether this bean is a primary autowire candidate. + *
If this value is {@code true} for exactly one bean among multiple + * matching candidates, it will serve as a tie-breaker. */ - void setAutowireCandidate(boolean autowireCandidate); + void setPrimary(boolean primary); /** * Return whether this bean is a primary autowire candidate. - * If this value is true for exactly one bean among multiple - * matching candidates, it will serve as a tie-breaker. */ boolean isPrimary(); /** - * Set whether this bean is a primary autowire candidate. - *
If this value is true for exactly one bean among multiple
- * matching candidates, it will serve as a tie-breaker.
+ * Specify the factory bean to use, if any.
+ * This the name of the bean to call the specified factory method on.
+ * @see #setFactoryMethodName
*/
- void setPrimary(boolean primary);
+ void setFactoryBeanName(String factoryBeanName);
+
+ /**
+ * Return the factory bean name, if any.
+ */
+ String getFactoryBeanName();
+
+ /**
+ * Specify a factory method, if any. This method will be invoked with
+ * constructor arguments, or with no arguments if none are specified.
+ * The method will be invoked on the specified factory bean, if any,
+ * or otherwise as a static method on the local bean class.
+ * @see #setFactoryBeanName
+ * @see #setBeanClassName
+ */
+ void setFactoryMethodName(String factoryMethodName);
+ /**
+ * Return a factory method, if any.
+ */
+ String getFactoryMethodName();
/**
* Return the constructor argument values for this bean.
@@ -208,6 +220,8 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
MutablePropertyValues getPropertyValues();
+ // Read-only attributes
+
/**
* Return whether this a Singleton, with a single, shared instance
* returned on all calls.
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java
index 9c42e31b1489a4d0f4a9df2ca6dd1a09461dfca4..7b21fcb3ec8f83d394217e82959455da93d88268 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java
@@ -49,6 +49,7 @@ import org.springframework.util.StringUtils;
* @author Juergen Hoeller
* @author Rob Harrop
* @author Mark Fisher
+ * @see GenericBeanDefinition
* @see RootBeanDefinition
* @see ChildBeanDefinition
*/
@@ -153,25 +154,24 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
private boolean primary = false;
- private final Map The default is singleton status, although this is only applied once
@@ -483,7 +488,6 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
return this.lazyInit;
}
-
/**
* Set the autowire mode. This determines whether any automagical detection
* and setting of bean references will happen. Default is AUTOWIRE_NO,
@@ -574,6 +578,12 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Set whether this bean is a candidate for getting autowired into some other bean.
+ * Note that this flag is designed to only affect type-based autowiring.
+ * It does not affect explicit references by name, which will get resolved even
+ * if the specified bean is not marked as an autowire candidate. As a consequence,
+ * autowiring by name will nevertheless inject a bean if the name matches.
+ * @see #AUTOWIRE_BY_TYPE
+ * @see #AUTOWIRE_BY_NAME
*/
@Override
public void setAutowireCandidate(boolean autowireCandidate) {
@@ -590,7 +600,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Set whether this bean is a primary autowire candidate.
- * If this value is true for exactly one bean among multiple
+ * If this value is {@code true} for exactly one bean among multiple
* matching candidates, it will serve as a tie-breaker.
*/
@Override
@@ -600,8 +610,6 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
/**
* Return whether this bean is a primary autowire candidate.
- * If this value is true for exactly one bean among multiple
- * matching candidates, it will serve as a tie-breaker.
*/
@Override
public boolean isPrimary() {
@@ -648,6 +656,27 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
this.qualifiers.putAll(source.qualifiers);
}
+ /**
+ * Specify a callback for creating an instance of the bean,
+ * as an alternative to a declaratively specified factory method.
+ * If such a callback is set, it will override any other constructor
+ * or factory method metadata. However, bean property population and
+ * potential annotation-driven injection will still apply as usual.
+ * @since 5.0
+ * @see #setConstructorArgumentValues(ConstructorArgumentValues)
+ * @see #setPropertyValues(MutablePropertyValues)
+ */
+ public void setInstanceSupplier(Supplier> instanceSupplier) {
+ this.instanceSupplier = instanceSupplier;
+ }
+
+ /**
+ * Return a callback for creating an instance of the bean, if any.
+ * @since 5.0
+ */
+ public Supplier> getInstanceSupplier() {
+ return this.instanceSupplier;
+ }
/**
* Specify whether to allow access to non-public constructors and methods,
@@ -688,6 +717,45 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
return this.lenientConstructorResolution;
}
+ /**
+ * Specify the factory bean to use, if any.
+ * This the name of the bean to call the specified factory method on.
+ * @see #setFactoryMethodName
+ */
+ @Override
+ public void setFactoryBeanName(String factoryBeanName) {
+ this.factoryBeanName = factoryBeanName;
+ }
+
+ /**
+ * Return the factory bean name, if any.
+ */
+ @Override
+ public String getFactoryBeanName() {
+ return this.factoryBeanName;
+ }
+
+ /**
+ * Specify a factory method, if any. This method will be invoked with
+ * constructor arguments, or with no arguments if none are specified.
+ * The method will be invoked on the specified factory bean, if any,
+ * or otherwise as a static method on the local bean class.
+ * @see #setFactoryBeanName
+ * @see #setBeanClassName
+ */
+ @Override
+ public void setFactoryMethodName(String factoryMethodName) {
+ this.factoryMethodName = factoryMethodName;
+ }
+
+ /**
+ * Return a factory method, if any.
+ */
+ @Override
+ public String getFactoryMethodName() {
+ return this.factoryMethodName;
+ }
+
/**
* Specify constructor argument values for this bean.
*/
@@ -742,49 +810,6 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
return this.methodOverrides;
}
-
- /**
- * Specify a callback for creating an instance of the bean,
- * as an alternative to a declaratively specified factory method.
- * If such a callback is set, it will override any other constructor
- * or factory method metadata. However, bean property population and
- * potential annotation-driven injection will still apply as usual.
- * @since 5.0
- * @see #setConstructorArgumentValues(ConstructorArgumentValues)
- * @see #setPropertyValues(MutablePropertyValues)
- */
- public void setInstanceSupplier(Supplier> instanceSupplier) {
- this.instanceSupplier = instanceSupplier;
- }
-
- /**
- * Return a callback for creating an instance of the bean, if any.
- * @since 5.0
- */
- public Supplier> getInstanceSupplier() {
- return this.instanceSupplier;
- }
-
- @Override
- public void setFactoryBeanName(String factoryBeanName) {
- this.factoryBeanName = factoryBeanName;
- }
-
- @Override
- public String getFactoryBeanName() {
- return this.factoryBeanName;
- }
-
- @Override
- public void setFactoryMethodName(String factoryMethodName) {
- this.factoryMethodName = factoryMethodName;
- }
-
- @Override
- public String getFactoryMethodName() {
- return this.factoryMethodName;
- }
-
/**
* Set the name of the initializer method. The default is {@code null}
* in which case there is no initializer method.
@@ -849,7 +874,6 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
return this.enforceDestroyMethod;
}
-
/**
* Set whether this bean definition is 'synthetic', that is, not defined
* by the application itself (for example, an infrastructure bean such
@@ -882,7 +906,6 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
return this.role;
}
-
/**
* Set a human-readable description of this bean definition.
*/
@@ -890,6 +913,9 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
this.description = description;
}
+ /**
+ * Return a human-readable description of this bean definition.
+ */
@Override
public String getDescription() {
return this.description;
@@ -918,6 +944,10 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
this.resource = new DescriptiveResource(resourceDescription);
}
+ /**
+ * Return a description of the resource that this bean definition
+ * came from (for the purpose of showing context in case of errors).
+ */
@Override
public String getResourceDescription() {
return (this.resource != null ? this.resource.getDescription() : null);
@@ -930,6 +960,12 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
this.resource = new BeanDefinitionResource(originatingBd);
}
+ /**
+ * Return the originating BeanDefinition, or {@code null} if none.
+ * Allows for retrieving the decorated bean definition, if any.
+ * Note that this method returns the immediate originator. Iterate through the
+ * originator chain to find the original BeanDefinition as defined by the user.
+ */
@Override
public BeanDefinition getOriginatingBeanDefinition() {
return (this.resource instanceof BeanDefinitionResource ?
@@ -1008,7 +1044,6 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
*/
public abstract AbstractBeanDefinition cloneBeanDefinition();
-
@Override
public boolean equals(Object other) {
if (this == other) {
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.java
index 87fc66ba879c000993cd349b2dc69092b905b4a6..a6204ae2169f2a70349b6b69bb47311c5977e8ae 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -53,10 +53,7 @@ public class ChildBeanDefinition extends AbstractBeanDefinition {
* configured through its bean properties and configuration methods.
* @param parentName the name of the parent bean
* @see #setBeanClass
- * @see #setBeanClassName
* @see #setScope
- * @see #setAutowireMode
- * @see #setDependencyCheck
* @see #setConstructorArgumentValues
* @see #setPropertyValues
*/
@@ -174,9 +171,7 @@ public class ChildBeanDefinition extends AbstractBeanDefinition {
@Override
public String toString() {
- StringBuilder sb = new StringBuilder("Child bean with parent '");
- sb.append(this.parentName).append("': ").append(super.toString());
- return sb.toString();
+ return "Child bean with parent '" + this.parentName + "': " + super.toString();
}
}
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java
index 77c08f67390c8e0d19a50061ff23e8d19857f1e4..04ec986dec5ffeb5c51dbadd4d34f66a53d8b2ea 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2014 the original author or authors.
+ * Copyright 2002-2016 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.
@@ -45,10 +45,7 @@ public class GenericBeanDefinition extends AbstractBeanDefinition {
* Create a new GenericBeanDefinition, to be configured through its bean
* properties and configuration methods.
* @see #setBeanClass
- * @see #setBeanClassName
* @see #setScope
- * @see #setAutowireMode
- * @see #setDependencyCheck
* @see #setConstructorArgumentValues
* @see #setPropertyValues
*/
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java
index 64908bd3404cb0e695f5022071f48200940d3242..31ab2a0866362ef93951f13c696d1a6d66516dae 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/RootBeanDefinition.java
@@ -103,10 +103,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
* Create a new RootBeanDefinition, to be configured through its bean
* properties and configuration methods.
* @see #setBeanClass
- * @see #setBeanClassName
* @see #setScope
- * @see #setAutowireMode
- * @see #setDependencyCheck
* @see #setConstructorArgumentValues
* @see #setPropertyValues
*/
@@ -131,7 +128,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
* @param instanceSupplier the supplier to construct a bean instance,
* as an alternative to a declaratively specified factory method
* @since 5.0
- * @see #setInstanceSupplier(Supplier)
+ * @see #setInstanceSupplier
*/
public