Don't call ReflectionUtils do deduce bean type
Update `OnBeanCondition` to no longer call `ReflectionUtils` when deducing the bean method return type. Since Spring Framework 4.2 the return type has been directly available from `MethodMetadata`. See gh-7573
This commit is contained in:
parent
996afafac6
commit
cfd5a73b64
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2016 the original author or authors.
|
* Copyright 2012-2017 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.
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.boot.autoconfigure.condition;
|
package org.springframework.boot.autoconfigure.condition;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
@ -43,8 +42,6 @@ import org.springframework.core.type.MethodMetadata;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
import org.springframework.util.ReflectionUtils;
|
|
||||||
import org.springframework.util.ReflectionUtils.MethodCallback;
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -349,33 +346,23 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit
|
||||||
AnnotatedTypeMetadata metadata, final List<String> beanTypes) {
|
AnnotatedTypeMetadata metadata, final List<String> beanTypes) {
|
||||||
if (metadata instanceof MethodMetadata
|
if (metadata instanceof MethodMetadata
|
||||||
&& metadata.isAnnotated(Bean.class.getName())) {
|
&& metadata.isAnnotated(Bean.class.getName())) {
|
||||||
addDeducedBeanTypeForBeanMethod(context, metadata, beanTypes,
|
addDeducedBeanTypeForBeanMethod(context, (MethodMetadata) metadata,
|
||||||
(MethodMetadata) metadata);
|
beanTypes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDeducedBeanTypeForBeanMethod(ConditionContext context,
|
private void addDeducedBeanTypeForBeanMethod(ConditionContext context,
|
||||||
AnnotatedTypeMetadata metadata, final List<String> beanTypes,
|
MethodMetadata metadata, final List<String> beanTypes) {
|
||||||
final MethodMetadata methodMetadata) {
|
|
||||||
try {
|
try {
|
||||||
// We should be safe to load at this point since we are in the
|
// We should be safe to load at this point since we are in the
|
||||||
// REGISTER_BEAN phase
|
// REGISTER_BEAN phase
|
||||||
Class<?> configClass = ClassUtils.forName(
|
Class<?> returnType = ClassUtils.forName(metadata.getReturnTypeName(),
|
||||||
methodMetadata.getDeclaringClassName(), context.getClassLoader());
|
context.getClassLoader());
|
||||||
ReflectionUtils.doWithMethods(configClass, new MethodCallback() {
|
beanTypes.add(returnType.getName());
|
||||||
@Override
|
|
||||||
public void doWith(Method method)
|
|
||||||
throws IllegalArgumentException, IllegalAccessException {
|
|
||||||
if (methodMetadata.getMethodName().equals(method.getName())) {
|
|
||||||
beanTypes.add(method.getReturnType().getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (Throwable ex) {
|
catch (Throwable ex) {
|
||||||
throw new BeanTypeDeductionException(
|
throw new BeanTypeDeductionException(metadata.getDeclaringClassName(),
|
||||||
methodMetadata.getDeclaringClassName(),
|
metadata.getMethodName(), ex);
|
||||||
methodMetadata.getMethodName(), ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue