From 999c7809a7acc0edd5e6a7e673dbc7560993d303 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 13 Aug 2018 12:43:52 +0200 Subject: [PATCH] Refined warn/info logging in AutowiredAnnotationBeanPostProcessor Issue: SPR-16946 --- .../AutowiredAnnotationBeanPostProcessor.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index 870378487c9..fa34e3bcb07 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -258,7 +258,7 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean } catch (NoSuchBeanDefinitionException ex) { throw new BeanCreationException(beanName, - "Cannot apply @Lookup to beans without corresponding bean definition"); + "Cannot apply @Lookup to beans without corresponding bean definition"); } } }); @@ -340,8 +340,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean if (defaultConstructor != null) { candidates.add(defaultConstructor); } - else if (candidates.size() == 1 && logger.isWarnEnabled()) { - logger.warn("Inconsistent constructor declaration on bean with name '" + beanName + + else if (candidates.size() == 1 && logger.isInfoEnabled()) { + logger.info("Inconsistent constructor declaration on bean with name '" + beanName + "': single autowire-marked constructor flagged as optional - " + "this constructor is effectively required since there is no " + "default constructor to fall back to: " + candidates.get(0)); @@ -352,8 +352,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean else if (rawCandidates.length == 1 && rawCandidates[0].getParameterCount() > 0) { candidateConstructors = new Constructor[] {rawCandidates[0]}; } - else if (nonSyntheticConstructors == 2 && primaryConstructor != null - && defaultConstructor != null && !primaryConstructor.equals(defaultConstructor)) { + else if (nonSyntheticConstructors == 2 && primaryConstructor != null && + defaultConstructor != null && !primaryConstructor.equals(defaultConstructor)) { candidateConstructors = new Constructor[] {primaryConstructor, defaultConstructor}; } else if (nonSyntheticConstructors == 1 && primaryConstructor != null) { @@ -445,8 +445,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean AnnotationAttributes ann = findAutowiredAnnotation(field); if (ann != null) { if (Modifier.isStatic(field.getModifiers())) { - if (logger.isWarnEnabled()) { - logger.warn("Autowired annotation is not supported on static fields: " + field); + if (logger.isInfoEnabled()) { + logger.info("Autowired annotation is not supported on static fields: " + field); } return; } @@ -463,14 +463,14 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean AnnotationAttributes ann = findAutowiredAnnotation(bridgedMethod); if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) { if (Modifier.isStatic(method.getModifiers())) { - if (logger.isWarnEnabled()) { - logger.warn("Autowired annotation is not supported on static methods: " + method); + if (logger.isInfoEnabled()) { + logger.info("Autowired annotation is not supported on static methods: " + method); } return; } if (method.getParameterCount() == 0) { - if (logger.isWarnEnabled()) { - logger.warn("Autowired annotation should only be used on methods with parameters: " + + if (logger.isInfoEnabled()) { + logger.info("Autowired annotation should only be used on methods with parameters: " + method); } } @@ -537,8 +537,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean if (this.beanFactory != null && this.beanFactory.containsBean(autowiredBeanName)) { this.beanFactory.registerDependentBean(autowiredBeanName, beanName); } - if (logger.isDebugEnabled()) { - logger.debug("Autowiring by type from bean name '" + beanName + + if (logger.isTraceEnabled()) { + logger.trace("Autowiring by type from bean name '" + beanName + "' to bean named '" + autowiredBeanName + "'"); } }