Skip to content

Commit e8a082f

Browse files
committed
Clarified setAutowireCandidate semantics (plus attribute reordering in BeanDefinition)
Issue: SPR-15072
1 parent ccabff6 commit e8a082f

File tree

6 files changed

+205
-159
lines changed

6 files changed

+205
-159
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinition.java

Lines changed: 64 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -79,57 +79,48 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
7979
int ROLE_INFRASTRUCTURE = 2;
8080

8181

82-
/**
83-
* Return the name of the parent definition of this bean definition, if any.
84-
*/
85-
String getParentName();
82+
// Modifiable attributes
8683

8784
/**
8885
* Set the name of the parent definition of this bean definition, if any.
8986
*/
9087
void setParentName(String parentName);
9188

9289
/**
93-
* Return the current bean class name of this bean definition.
94-
* <p>Note that this does not have to be the actual class name used at runtime, in
95-
* case of a child definition overriding/inheriting the class name from its parent.
96-
* Hence, do <i>not</i> consider this to be the definitive bean type at runtime but
97-
* rather only use it for parsing purposes at the individual bean definition level.
90+
* Return the name of the parent definition of this bean definition, if any.
9891
*/
99-
String getBeanClassName();
92+
String getParentName();
10093

10194
/**
102-
* Override the bean class name of this bean definition.
95+
* Specify the bean class name of this bean definition.
10396
* <p>The class name can be modified during bean factory post-processing,
10497
* typically replacing the original class name with a parsed variant of it.
98+
* @see #setParentName
99+
* @see #setFactoryBeanName
100+
* @see #setFactoryMethodName
105101
*/
106102
void setBeanClassName(String beanClassName);
107103

108104
/**
109-
* Return the factory bean name, if any.
110-
*/
111-
String getFactoryBeanName();
112-
113-
/**
114-
* Specify the factory bean to use, if any.
115-
*/
116-
void setFactoryBeanName(String factoryBeanName);
117-
118-
/**
119-
* Return a factory method, if any.
105+
* Return the current bean class name of this bean definition.
106+
* <p>Note that this does not have to be the actual class name used at runtime, in
107+
* case of a child definition overriding/inheriting the class name from its parent.
108+
* Also, this may just be the class that a factory method is called on, or it may
109+
* even be empty in case of a factory bean reference that a method is called on.
110+
* Hence, do <i>not</i> consider this to be the definitive bean type at runtime but
111+
* rather only use it for parsing purposes at the individual bean definition level.
112+
* @see #getParentName()
113+
* @see #getFactoryBeanName()
114+
* @see #getFactoryMethodName()
120115
*/
121-
String getFactoryMethodName();
116+
String getBeanClassName();
122117

123118
/**
124-
* Specify a factory method, if any. This method will be invoked with
125-
* constructor arguments, or with no arguments if none are specified.
126-
* The method will be invoked on the specified factory bean, if any,
127-
* or otherwise as a static method on the local bean class.
128-
* @param factoryMethodName static factory method name,
129-
* or {@code null} if normal constructor creation should be used
130-
* @see #getBeanClassName()
119+
* Override the target scope of this bean, specifying a new scope name.
120+
* @see #SCOPE_SINGLETON
121+
* @see #SCOPE_PROTOTYPE
131122
*/
132-
void setFactoryMethodName(String factoryMethodName);
123+
void setScope(String scope);
133124

134125
/**
135126
* Return the name of the current target scope for this bean,
@@ -138,11 +129,11 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
138129
String getScope();
139130

140131
/**
141-
* Override the target scope of this bean, specifying a new scope name.
142-
* @see #SCOPE_SINGLETON
143-
* @see #SCOPE_PROTOTYPE
132+
* Set whether this bean should be lazily initialized.
133+
* <p>If {@code false}, the bean will get instantiated on startup by bean
134+
* factories that perform eager initialization of singletons.
144135
*/
145-
void setScope(String scope);
136+
void setLazyInit(boolean lazyInit);
146137

147138
/**
148139
* Return whether this bean should be lazily initialized, i.e. not
@@ -151,47 +142,68 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
151142
boolean isLazyInit();
152143

153144
/**
154-
* Set whether this bean should be lazily initialized.
155-
* <p>If {@code false}, the bean will get instantiated on startup by bean
156-
* factories that perform eager initialization of singletons.
145+
* Set the names of the beans that this bean depends on being initialized.
146+
* The bean factory will guarantee that these beans get initialized first.
157147
*/
158-
void setLazyInit(boolean lazyInit);
148+
void setDependsOn(String... dependsOn);
159149

160150
/**
161151
* Return the bean names that this bean depends on.
162152
*/
163153
String[] getDependsOn();
164154

165155
/**
166-
* Set the names of the beans that this bean depends on being initialized.
167-
* The bean factory will guarantee that these beans get initialized first.
156+
* Set whether this bean is a candidate for getting autowired into some other bean.
157+
* <p>Note that this flag is designed to only affect type-based autowiring.
158+
* It does not affect explicit references by name, which will get resolved even
159+
* if the specified bean is not marked as an autowire candidate. As a consequence,
160+
* autowiring by name will nevertheless inject a bean if the name matches.
168161
*/
169-
void setDependsOn(String... dependsOn);
162+
void setAutowireCandidate(boolean autowireCandidate);
170163

171164
/**
172165
* Return whether this bean is a candidate for getting autowired into some other bean.
173166
*/
174167
boolean isAutowireCandidate();
175168

176169
/**
177-
* Set whether this bean is a candidate for getting autowired into some other bean.
170+
* Set whether this bean is a primary autowire candidate.
171+
* <p>If this value is {@code true} for exactly one bean among multiple
172+
* matching candidates, it will serve as a tie-breaker.
178173
*/
179-
void setAutowireCandidate(boolean autowireCandidate);
174+
void setPrimary(boolean primary);
180175

181176
/**
182177
* Return whether this bean is a primary autowire candidate.
183-
* If this value is true for exactly one bean among multiple
184-
* matching candidates, it will serve as a tie-breaker.
185178
*/
186179
boolean isPrimary();
187180

188181
/**
189-
* Set whether this bean is a primary autowire candidate.
190-
* <p>If this value is true for exactly one bean among multiple
191-
* matching candidates, it will serve as a tie-breaker.
182+
* Specify the factory bean to use, if any.
183+
* This the name of the bean to call the specified factory method on.
184+
* @see #setFactoryMethodName
192185
*/
193-
void setPrimary(boolean primary);
186+
void setFactoryBeanName(String factoryBeanName);
187+
188+
/**
189+
* Return the factory bean name, if any.
190+
*/
191+
String getFactoryBeanName();
192+
193+
/**
194+
* Specify a factory method, if any. This method will be invoked with
195+
* constructor arguments, or with no arguments if none are specified.
196+
* The method will be invoked on the specified factory bean, if any,
197+
* or otherwise as a static method on the local bean class.
198+
* @see #setFactoryBeanName
199+
* @see #setBeanClassName
200+
*/
201+
void setFactoryMethodName(String factoryMethodName);
194202

203+
/**
204+
* Return a factory method, if any.
205+
*/
206+
String getFactoryMethodName();
195207

196208
/**
197209
* Return the constructor argument values for this bean.
@@ -208,6 +220,8 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
208220
MutablePropertyValues getPropertyValues();
209221

210222

223+
// Read-only attributes
224+
211225
/**
212226
* Return whether this a <b>Singleton</b>, with a single, shared instance
213227
* returned on all calls.

0 commit comments

Comments
 (0)