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
This commit is contained in:
parent
4d15b58ca4
commit
d39e44c209
|
|
@ -64,7 +64,6 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||||
/**
|
/**
|
||||||
* Constant that indicates no externally defined autowiring. Note that
|
* Constant that indicates no externally defined autowiring. Note that
|
||||||
* BeanFactoryAware etc and annotation-driven injection will still be applied.
|
* BeanFactoryAware etc and annotation-driven injection will still be applied.
|
||||||
* @see #createBean
|
|
||||||
* @see #autowire
|
* @see #autowire
|
||||||
* @see #autowireBeanProperties
|
* @see #autowireBeanProperties
|
||||||
*/
|
*/
|
||||||
|
|
@ -73,7 +72,6 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||||
/**
|
/**
|
||||||
* Constant that indicates autowiring bean properties by name
|
* Constant that indicates autowiring bean properties by name
|
||||||
* (applying to all bean property setters).
|
* (applying to all bean property setters).
|
||||||
* @see #createBean
|
|
||||||
* @see #autowire
|
* @see #autowire
|
||||||
* @see #autowireBeanProperties
|
* @see #autowireBeanProperties
|
||||||
*/
|
*/
|
||||||
|
|
@ -82,7 +80,6 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||||
/**
|
/**
|
||||||
* Constant that indicates autowiring bean properties by type
|
* Constant that indicates autowiring bean properties by type
|
||||||
* (applying to all bean property setters).
|
* (applying to all bean property setters).
|
||||||
* @see #createBean
|
|
||||||
* @see #autowire
|
* @see #autowire
|
||||||
* @see #autowireBeanProperties
|
* @see #autowireBeanProperties
|
||||||
*/
|
*/
|
||||||
|
|
@ -91,7 +88,6 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||||
/**
|
/**
|
||||||
* Constant that indicates autowiring the greediest constructor that
|
* Constant that indicates autowiring the greediest constructor that
|
||||||
* can be satisfied (involves resolving the appropriate constructor).
|
* can be satisfied (involves resolving the appropriate constructor).
|
||||||
* @see #createBean
|
|
||||||
* @see #autowire
|
* @see #autowire
|
||||||
*/
|
*/
|
||||||
int AUTOWIRE_CONSTRUCTOR = 3;
|
int AUTOWIRE_CONSTRUCTOR = 3;
|
||||||
|
|
@ -99,7 +95,6 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||||
/**
|
/**
|
||||||
* Constant that indicates determining an appropriate autowire strategy
|
* Constant that indicates determining an appropriate autowire strategy
|
||||||
* through introspection of the bean class.
|
* through introspection of the bean class.
|
||||||
* @see #createBean
|
|
||||||
* @see #autowire
|
* @see #autowire
|
||||||
* @deprecated as of Spring 3.0: If you are using mixed autowiring strategies,
|
* @deprecated as of Spring 3.0: If you are using mixed autowiring strategies,
|
||||||
* prefer annotation-based autowiring for clearer demarcation of autowiring needs.
|
* prefer annotation-based autowiring for clearer demarcation of autowiring needs.
|
||||||
|
|
@ -192,7 +187,9 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||||
* @see #AUTOWIRE_BY_NAME
|
* @see #AUTOWIRE_BY_NAME
|
||||||
* @see #AUTOWIRE_BY_TYPE
|
* @see #AUTOWIRE_BY_TYPE
|
||||||
* @see #AUTOWIRE_CONSTRUCTOR
|
* @see #AUTOWIRE_CONSTRUCTOR
|
||||||
|
* @deprecated as of 6.1, in favor of {@link #createBean(Class)}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.1")
|
||||||
Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;
|
Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -322,7 +319,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
|
||||||
throws BeansException;
|
throws BeansException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the given bean instance (typically coming from {@link #createBean}),
|
* Destroy the given bean instance (typically coming from {@link #createBean(Class)}),
|
||||||
* applying the {@link org.springframework.beans.factory.DisposableBean} contract as well as
|
* applying the {@link org.springframework.beans.factory.DisposableBean} contract as well as
|
||||||
* registered {@link DestructionAwareBeanPostProcessor DestructionAwareBeanPostProcessors}.
|
* registered {@link DestructionAwareBeanPostProcessor DestructionAwareBeanPostProcessors}.
|
||||||
* <p>Any exception that arises during destruction should be caught
|
* <p>Any exception that arises during destruction should be caught
|
||||||
|
|
|
||||||
|
|
@ -357,6 +357,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||||
// Specialized methods for fine-grained control over the bean lifecycle
|
// Specialized methods for fine-grained control over the bean lifecycle
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException {
|
public Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException {
|
||||||
// Use non-singleton bean definition, to avoid registering bean as dependent bean.
|
// Use non-singleton bean definition, to avoid registering bean as dependent bean.
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ import org.quartz.spi.TriggerFiredBundle;
|
||||||
import org.springframework.beans.BeanWrapper;
|
import org.springframework.beans.BeanWrapper;
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.PropertyAccessorFactory;
|
import org.springframework.beans.PropertyAccessorFactory;
|
||||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
|
|
@ -87,9 +86,7 @@ public class SpringBeanJobFactory extends AdaptableJobFactory
|
||||||
@Override
|
@Override
|
||||||
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
|
protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
|
||||||
Object job = (this.applicationContext != null ?
|
Object job = (this.applicationContext != null ?
|
||||||
// to be replaced with createBean(Class) in 6.1
|
this.applicationContext.getAutowireCapableBeanFactory().createBean(bundle.getJobDetail().getJobClass()) :
|
||||||
this.applicationContext.getAutowireCapableBeanFactory().createBean(
|
|
||||||
bundle.getJobDetail().getJobClass(), AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false) :
|
|
||||||
super.createJobInstance(bundle));
|
super.createJobInstance(bundle));
|
||||||
|
|
||||||
if (isEligibleForPropertyPopulation(job)) {
|
if (isEligibleForPropertyPopulation(job)) {
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ public final class SpringBeanContainer implements BeanContainer {
|
||||||
try {
|
try {
|
||||||
if (lifecycleOptions.useJpaCompliantCreation()) {
|
if (lifecycleOptions.useJpaCompliantCreation()) {
|
||||||
return new SpringContainedBean<>(
|
return new SpringContainedBean<>(
|
||||||
this.beanFactory.createBean(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false),
|
this.beanFactory.createBean(beanType),
|
||||||
this.beanFactory::destroyBean);
|
this.beanFactory::destroyBean);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2023 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -421,6 +421,7 @@ class StubWebApplicationContext implements WebApplicationContext {
|
||||||
return BeanUtils.instantiateClass(beanClass);
|
return BeanUtils.instantiateClass(beanClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
public Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) {
|
public Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) {
|
||||||
return BeanUtils.instantiateClass(beanClass);
|
return BeanUtils.instantiateClass(beanClass);
|
||||||
|
|
|
||||||
|
|
@ -915,12 +915,12 @@ public class DispatcherServlet extends FrameworkServlet {
|
||||||
/**
|
/**
|
||||||
* Create a default strategy.
|
* Create a default strategy.
|
||||||
* <p>The default implementation uses
|
* <p>The default implementation uses
|
||||||
* {@link org.springframework.beans.factory.config.AutowireCapableBeanFactory#createBean}.
|
* {@link org.springframework.beans.factory.config.AutowireCapableBeanFactory#createBean(Class)}.
|
||||||
* @param context the current WebApplicationContext
|
* @param context the current WebApplicationContext
|
||||||
* @param clazz the strategy implementation class to instantiate
|
* @param clazz the strategy implementation class to instantiate
|
||||||
* @return the fully configured strategy instance
|
* @return the fully configured strategy instance
|
||||||
* @see org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()
|
* @see org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()
|
||||||
* @see org.springframework.beans.factory.config.AutowireCapableBeanFactory#createBean
|
* @see org.springframework.beans.factory.config.AutowireCapableBeanFactory#createBean(Class)
|
||||||
*/
|
*/
|
||||||
protected Object createDefaultStrategy(ApplicationContext context, Class<?> clazz) {
|
protected Object createDefaultStrategy(ApplicationContext context, Class<?> clazz) {
|
||||||
return context.getAutowireCapableBeanFactory().createBean(clazz);
|
return context.getAutowireCapableBeanFactory().createBean(clazz);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue