Log OnBeanCondition.addDeducedBeanType errors

Update addDeducedBeanType.addDeducedBeanType to log any exceptions at
debug level.

Fixes gh-2436
This commit is contained in:
Phillip Webb 2015-02-02 20:55:47 -08:00
parent 0696695e16
commit 3d9cf06c31
1 changed files with 33 additions and 18 deletions

View File

@ -26,6 +26,8 @@ import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.HierarchicalBeanFactory; import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.ListableBeanFactory;
@ -56,6 +58,8 @@ import org.springframework.util.StringUtils;
public class OnBeanCondition extends SpringBootCondition implements public class OnBeanCondition extends SpringBootCondition implements
ConfigurationCondition { ConfigurationCondition {
private static final Log logger = LogFactory.getLog(OnBeanCondition.class);
private static final String[] NO_BEANS = {}; private static final String[] NO_BEANS = {};
/** /**
@ -249,25 +253,36 @@ public class OnBeanCondition extends SpringBootCondition implements
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())) {
try { addDeducedBeanTypeForBeanMethod(context, metadata, beanTypes,
final MethodMetadata methodMetadata = (MethodMetadata) metadata; (MethodMetadata) metadata);
// We should be safe to load at this point since we are in the }
// REGISTER_BEAN phase }
Class<?> configClass = ClassUtils.forName(
methodMetadata.getDeclaringClassName(), private void addDeducedBeanTypeForBeanMethod(ConditionContext context,
context.getClassLoader()); AnnotatedTypeMetadata metadata, final List<String> beanTypes,
ReflectionUtils.doWithMethods(configClass, new MethodCallback() { final MethodMetadata methodMetadata) {
@Override try {
public void doWith(Method method) // We should be safe to load at this point since we are in the
throws IllegalArgumentException, IllegalAccessException { // REGISTER_BEAN phase
if (methodMetadata.getMethodName().equals(method.getName())) { Class<?> configClass = ClassUtils.forName(
beanTypes.add(method.getReturnType().getName()); methodMetadata.getDeclaringClassName(), context.getClassLoader());
} ReflectionUtils.doWithMethods(configClass, new MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException,
IllegalAccessException {
if (methodMetadata.getMethodName().equals(method.getName())) {
beanTypes.add(method.getReturnType().getName());
} }
}); }
} });
catch (Throwable ex) { }
// swallow exception and continue catch (Throwable ex) {
// swallow exception and continue
if (logger.isDebugEnabled()) {
logger.debug(
"Unable to deduce bean type for "
+ methodMetadata.getDeclaringClassName() + "."
+ methodMetadata.getMethodName(), ex);
} }
} }
} }