Skip to content

Commit d39e44c

Browse files
committed
Deprecate AutowireCapableBeanFactory.createBean(Class, int, boolean)
Includes consistent usage of createBean(Class) in SpringBeanJobFactory and SpringBeanContainer. Closes gh-30345 See gh-29855 See gh-30041
1 parent 4d15b58 commit d39e44c

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
6464
/**
6565
* Constant that indicates no externally defined autowiring. Note that
6666
* BeanFactoryAware etc and annotation-driven injection will still be applied.
67-
* @see #createBean
6867
* @see #autowire
6968
* @see #autowireBeanProperties
7069
*/
@@ -73,7 +72,6 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
7372
/**
7473
* Constant that indicates autowiring bean properties by name
7574
* (applying to all bean property setters).
76-
* @see #createBean
7775
* @see #autowire
7876
* @see #autowireBeanProperties
7977
*/
@@ -82,7 +80,6 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
8280
/**
8381
* Constant that indicates autowiring bean properties by type
8482
* (applying to all bean property setters).
85-
* @see #createBean
8683
* @see #autowire
8784
* @see #autowireBeanProperties
8885
*/
@@ -91,15 +88,13 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
9188
/**
9289
* Constant that indicates autowiring the greediest constructor that
9390
* can be satisfied (involves resolving the appropriate constructor).
94-
* @see #createBean
9591
* @see #autowire
9692
*/
9793
int AUTOWIRE_CONSTRUCTOR = 3;
9894

9995
/**
10096
* Constant that indicates determining an appropriate autowire strategy
10197
* through introspection of the bean class.
102-
* @see #createBean
10398
* @see #autowire
10499
* @deprecated as of Spring 3.0: If you are using mixed autowiring strategies,
105100
* prefer annotation-based autowiring for clearer demarcation of autowiring needs.
@@ -192,7 +187,9 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
192187
* @see #AUTOWIRE_BY_NAME
193188
* @see #AUTOWIRE_BY_TYPE
194189
* @see #AUTOWIRE_CONSTRUCTOR
190+
* @deprecated as of 6.1, in favor of {@link #createBean(Class)}
195191
*/
192+
@Deprecated(since = "6.1")
196193
Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;
197194

198195
/**
@@ -322,7 +319,7 @@ Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String be
322319
throws BeansException;
323320

324321
/**
325-
* Destroy the given bean instance (typically coming from {@link #createBean}),
322+
* Destroy the given bean instance (typically coming from {@link #createBean(Class)}),
326323
* applying the {@link org.springframework.beans.factory.DisposableBean} contract as well as
327324
* registered {@link DestructionAwareBeanPostProcessor DestructionAwareBeanPostProcessors}.
328325
* <p>Any exception that arises during destruction should be caught

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ public Object configureBean(Object existingBean, String beanName) throws BeansEx
357357
// Specialized methods for fine-grained control over the bean lifecycle
358358
//-------------------------------------------------------------------------
359359

360+
@Deprecated
360361
@Override
361362
public Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException {
362363
// Use non-singleton bean definition, to avoid registering bean as dependent bean.

spring-context-support/src/main/java/org/springframework/scheduling/quartz/SpringBeanJobFactory.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.beans.BeanWrapper;
2323
import org.springframework.beans.MutablePropertyValues;
2424
import org.springframework.beans.PropertyAccessorFactory;
25-
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
2625
import org.springframework.context.ApplicationContext;
2726
import org.springframework.context.ApplicationContextAware;
2827
import org.springframework.lang.Nullable;
@@ -87,9 +86,7 @@ public void setSchedulerContext(SchedulerContext schedulerContext) {
8786
@Override
8887
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
8988
Object job = (this.applicationContext != null ?
90-
// to be replaced with createBean(Class) in 6.1
91-
this.applicationContext.getAutowireCapableBeanFactory().createBean(
92-
bundle.getJobDetail().getJobClass(), AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false) :
89+
this.applicationContext.getAutowireCapableBeanFactory().createBean(bundle.getJobDetail().getJobClass()) :
9390
super.createJobInstance(bundle));
9491

9592
if (isEligibleForPropertyPopulation(job)) {

spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringBeanContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private SpringContainedBean<?> createBean(
144144
try {
145145
if (lifecycleOptions.useJpaCompliantCreation()) {
146146
return new SpringContainedBean<>(
147-
this.beanFactory.createBean(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false),
147+
this.beanFactory.createBean(beanType),
148148
this.beanFactory::destroyBean);
149149
}
150150
else {

spring-test/src/main/java/org/springframework/test/web/servlet/setup/StubWebApplicationContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -421,6 +421,7 @@ public <T> T createBean(Class<T> beanClass) {
421421
return BeanUtils.instantiateClass(beanClass);
422422
}
423423

424+
@Deprecated
424425
@Override
425426
public Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) {
426427
return BeanUtils.instantiateClass(beanClass);

spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,12 +915,12 @@ protected <T> List<T> getDefaultStrategies(ApplicationContext context, Class<T>
915915
/**
916916
* Create a default strategy.
917917
* <p>The default implementation uses
918-
* {@link org.springframework.beans.factory.config.AutowireCapableBeanFactory#createBean}.
918+
* {@link org.springframework.beans.factory.config.AutowireCapableBeanFactory#createBean(Class)}.
919919
* @param context the current WebApplicationContext
920920
* @param clazz the strategy implementation class to instantiate
921921
* @return the fully configured strategy instance
922922
* @see org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()
923-
* @see org.springframework.beans.factory.config.AutowireCapableBeanFactory#createBean
923+
* @see org.springframework.beans.factory.config.AutowireCapableBeanFactory#createBean(Class)
924924
*/
925925
protected Object createDefaultStrategy(ApplicationContext context, Class<?> clazz) {
926926
return context.getAutowireCapableBeanFactory().createBean(clazz);

0 commit comments

Comments
 (0)