Polishing
This commit is contained in:
parent
d3c08552e9
commit
082c524cbe
|
@ -122,11 +122,9 @@ public abstract class BeanUtils {
|
|||
return instantiateClass(clazz.getDeclaredConstructor());
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
if (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(clazz)) {
|
||||
Constructor<T> ctor = findPrimaryConstructor(clazz);
|
||||
if (ctor != null) {
|
||||
return instantiateClass(ctor);
|
||||
}
|
||||
Constructor<T> ctor = findPrimaryConstructor(clazz);
|
||||
if (ctor != null) {
|
||||
return instantiateClass(ctor);
|
||||
}
|
||||
throw new BeanInstantiationException(clazz, "No default constructor found", ex);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import groovy.lang.GroovyObjectSupport;
|
|||
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
||||
|
@ -182,16 +181,16 @@ class GroovyBeanDefinitionWrapper extends GroovyObjectSupport {
|
|||
AbstractBeanDefinition bd = getBeanDefinition();
|
||||
if (AUTOWIRE.equals(property)) {
|
||||
if ("byName".equals(newValue)) {
|
||||
bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
|
||||
bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
|
||||
}
|
||||
else if ("byType".equals(newValue)) {
|
||||
bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE);
|
||||
bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
|
||||
}
|
||||
else if ("constructor".equals(newValue)) {
|
||||
bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR);
|
||||
bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
|
||||
}
|
||||
else if (Boolean.TRUE.equals(newValue)) {
|
||||
bd.setAutowireMode(AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
|
||||
bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
|
||||
}
|
||||
}
|
||||
// constructorArgs
|
||||
|
|
|
@ -1148,8 +1148,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
|||
|
||||
// Candidate constructors for autowiring?
|
||||
Constructor<?>[] ctors = determineConstructorsFromBeanPostProcessors(beanClass, beanName);
|
||||
if (ctors != null ||
|
||||
mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_CONSTRUCTOR ||
|
||||
if (ctors != null || mbd.getResolvedAutowireMode() == AUTOWIRE_CONSTRUCTOR ||
|
||||
mbd.hasConstructorArgumentValues() || !ObjectUtils.isEmpty(args)) {
|
||||
return autowireConstructor(beanName, mbd, ctors, args);
|
||||
}
|
||||
|
@ -1351,25 +1350,21 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
|||
|
||||
PropertyValues pvs = (mbd.hasPropertyValues() ? mbd.getPropertyValues() : null);
|
||||
|
||||
if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_NAME ||
|
||||
mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_TYPE) {
|
||||
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_NAME || mbd.getResolvedAutowireMode() == AUTOWIRE_BY_TYPE) {
|
||||
MutablePropertyValues newPvs = new MutablePropertyValues(pvs);
|
||||
|
||||
// Add property values based on autowire by name if applicable.
|
||||
if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_NAME) {
|
||||
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_NAME) {
|
||||
autowireByName(beanName, mbd, bw, newPvs);
|
||||
}
|
||||
|
||||
// Add property values based on autowire by type if applicable.
|
||||
if (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_BY_TYPE) {
|
||||
if (mbd.getResolvedAutowireMode() == AUTOWIRE_BY_TYPE) {
|
||||
autowireByType(beanName, mbd, bw, newPvs);
|
||||
}
|
||||
|
||||
pvs = newPvs;
|
||||
}
|
||||
|
||||
boolean hasInstAwareBpps = hasInstantiationAwareBeanPostProcessors();
|
||||
boolean needsDepCheck = (mbd.getDependencyCheck() != RootBeanDefinition.DEPENDENCY_CHECK_NONE);
|
||||
boolean needsDepCheck = (mbd.getDependencyCheck() != AbstractBeanDefinition.DEPENDENCY_CHECK_NONE);
|
||||
|
||||
PropertyDescriptor[] filteredPds = null;
|
||||
if (hasInstAwareBpps) {
|
||||
|
@ -1582,9 +1577,9 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
|||
for (PropertyDescriptor pd : pds) {
|
||||
if (pd.getWriteMethod() != null && (pvs == null || !pvs.contains(pd.getName()))) {
|
||||
boolean isSimple = BeanUtils.isSimpleProperty(pd.getPropertyType());
|
||||
boolean unsatisfied = (dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_ALL) ||
|
||||
(isSimple && dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_SIMPLE) ||
|
||||
(!isSimple && dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
|
||||
boolean unsatisfied = (dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_ALL) ||
|
||||
(isSimple && dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_SIMPLE) ||
|
||||
(!isSimple && dependencyCheck == AbstractBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
|
||||
if (unsatisfied) {
|
||||
throw new UnsatisfiedDependencyException(mbd.getResourceDescription(), beanName, pd.getName(),
|
||||
"Set this property value or disable dependency checking for this bean.");
|
||||
|
|
|
@ -69,9 +69,7 @@ public final class BeanDefinitionBuilder {
|
|||
* @param instanceSupplier a callback for creating an instance of the bean
|
||||
* @since 5.0
|
||||
*/
|
||||
public static <T> BeanDefinitionBuilder genericBeanDefinition(
|
||||
@Nullable Class<T> beanClass, Supplier<T> instanceSupplier) {
|
||||
|
||||
public static <T> BeanDefinitionBuilder genericBeanDefinition(Class<T> beanClass, Supplier<T> instanceSupplier) {
|
||||
BeanDefinitionBuilder builder = new BeanDefinitionBuilder(new GenericBeanDefinition());
|
||||
builder.beanDefinition.setBeanClass(beanClass);
|
||||
builder.beanDefinition.setInstanceSupplier(instanceSupplier);
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.springframework.beans.factory.InjectionPoint;
|
|||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
|
||||
import org.springframework.beans.factory.UnsatisfiedDependencyException;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder;
|
||||
import org.springframework.beans.factory.config.DependencyDescriptor;
|
||||
|
@ -174,7 +175,7 @@ class ConstructorResolver {
|
|||
|
||||
// Need to resolve the constructor.
|
||||
boolean autowiring = (chosenCtors != null ||
|
||||
mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
|
||||
mbd.getResolvedAutowireMode() == AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR);
|
||||
ConstructorArgumentValues resolvedValues = null;
|
||||
|
||||
int minNrOfArgs;
|
||||
|
@ -461,7 +462,7 @@ class ConstructorResolver {
|
|||
AutowireUtils.sortFactoryMethods(candidates);
|
||||
|
||||
ConstructorArgumentValues resolvedValues = null;
|
||||
boolean autowiring = (mbd.getResolvedAutowireMode() == RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
|
||||
boolean autowiring = (mbd.getResolvedAutowireMode() == AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR);
|
||||
int minTypeDiffWeight = Integer.MAX_VALUE;
|
||||
Set<Method> ambiguousFactoryMethods = null;
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
|
|||
import org.springframework.beans.factory.config.BeanDefinitionHolder;
|
||||
import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader;
|
||||
import org.springframework.beans.factory.parsing.SourceExtractor;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinitionReader;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReader;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
|
@ -221,7 +222,7 @@ class ConfigurationClassBeanDefinitionReader {
|
|||
beanDef.setFactoryBeanName(configClass.getBeanName());
|
||||
beanDef.setUniqueFactoryMethodName(methodName);
|
||||
}
|
||||
beanDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
|
||||
beanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
|
||||
beanDef.setAttribute(org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor.
|
||||
SKIP_REQUIRED_CHECK_ATTRIBUTE, Boolean.TRUE);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
|
@ -134,11 +134,11 @@ class ScriptBeanDefinitionParser extends AbstractBeanDefinitionParser {
|
|||
String autowire = element.getAttribute(AUTOWIRE_ATTRIBUTE);
|
||||
int autowireMode = parserContext.getDelegate().getAutowireMode(autowire);
|
||||
// Only "byType" and "byName" supported, but maybe other default inherited...
|
||||
if (autowireMode == GenericBeanDefinition.AUTOWIRE_AUTODETECT) {
|
||||
autowireMode = GenericBeanDefinition.AUTOWIRE_BY_TYPE;
|
||||
if (autowireMode == AbstractBeanDefinition.AUTOWIRE_AUTODETECT) {
|
||||
autowireMode = AbstractBeanDefinition.AUTOWIRE_BY_TYPE;
|
||||
}
|
||||
else if (autowireMode == GenericBeanDefinition.AUTOWIRE_CONSTRUCTOR) {
|
||||
autowireMode = GenericBeanDefinition.AUTOWIRE_NO;
|
||||
else if (autowireMode == AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR) {
|
||||
autowireMode = AbstractBeanDefinition.AUTOWIRE_NO;
|
||||
}
|
||||
bd.setAutowireMode(autowireMode);
|
||||
|
||||
|
|
Loading…
Reference in New Issue