Consistent trace logging for init and destroy methods
Issue: SPR-17090
This commit is contained in:
parent
6ef0938a92
commit
f13f041fae
|
@ -196,7 +196,6 @@ public class InitDestroyAnnotationBeanPostProcessor
|
|||
}
|
||||
|
||||
private LifecycleMetadata buildLifecycleMetadata(final Class<?> clazz) {
|
||||
final boolean debug = logger.isDebugEnabled();
|
||||
List<LifecycleElement> initMethods = new ArrayList<>();
|
||||
List<LifecycleElement> destroyMethods = new ArrayList<>();
|
||||
Class<?> targetClass = clazz;
|
||||
|
@ -209,14 +208,14 @@ public class InitDestroyAnnotationBeanPostProcessor
|
|||
if (this.initAnnotationType != null && method.isAnnotationPresent(this.initAnnotationType)) {
|
||||
LifecycleElement element = new LifecycleElement(method);
|
||||
currInitMethods.add(element);
|
||||
if (debug) {
|
||||
logger.debug("Found init method on class [" + clazz.getName() + "]: " + method);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Found init method on class [" + clazz.getName() + "]: " + method);
|
||||
}
|
||||
}
|
||||
if (this.destroyAnnotationType != null && method.isAnnotationPresent(this.destroyAnnotationType)) {
|
||||
currDestroyMethods.add(new LifecycleElement(method));
|
||||
if (debug) {
|
||||
logger.debug("Found destroy method on class [" + clazz.getName() + "]: " + method);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Found destroy method on class [" + clazz.getName() + "]: " + method);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -276,8 +275,8 @@ public class InitDestroyAnnotationBeanPostProcessor
|
|||
if (!beanDefinition.isExternallyManagedInitMethod(methodIdentifier)) {
|
||||
beanDefinition.registerExternallyManagedInitMethod(methodIdentifier);
|
||||
checkedInitMethods.add(element);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Registered init method on class [" + this.targetClass.getName() + "]: " + element);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Registered init method on class [" + this.targetClass.getName() + "]: " + element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -287,8 +286,8 @@ public class InitDestroyAnnotationBeanPostProcessor
|
|||
if (!beanDefinition.isExternallyManagedDestroyMethod(methodIdentifier)) {
|
||||
beanDefinition.registerExternallyManagedDestroyMethod(methodIdentifier);
|
||||
checkedDestroyMethods.add(element);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Registered destroy method on class [" + this.targetClass.getName() + "]: " + element);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Registered destroy method on class [" + this.targetClass.getName() + "]: " + element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -301,10 +300,9 @@ public class InitDestroyAnnotationBeanPostProcessor
|
|||
Collection<LifecycleElement> initMethodsToIterate =
|
||||
(checkedInitMethods != null ? checkedInitMethods : this.initMethods);
|
||||
if (!initMethodsToIterate.isEmpty()) {
|
||||
boolean debug = logger.isDebugEnabled();
|
||||
for (LifecycleElement element : initMethodsToIterate) {
|
||||
if (debug) {
|
||||
logger.debug("Invoking init method on bean '" + beanName + "': " + element.getMethod());
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Invoking init method on bean '" + beanName + "': " + element.getMethod());
|
||||
}
|
||||
element.invoke(target);
|
||||
}
|
||||
|
@ -316,10 +314,9 @@ public class InitDestroyAnnotationBeanPostProcessor
|
|||
Collection<LifecycleElement> destroyMethodsToUse =
|
||||
(checkedDestroyMethods != null ? checkedDestroyMethods : this.destroyMethods);
|
||||
if (!destroyMethodsToUse.isEmpty()) {
|
||||
boolean debug = logger.isDebugEnabled();
|
||||
for (LifecycleElement element : destroyMethodsToUse) {
|
||||
if (debug) {
|
||||
logger.debug("Invoking destroy method on bean '" + beanName + "': " + element.getMethod());
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Invoking destroy method on bean '" + beanName + "': " + element.getMethod());
|
||||
}
|
||||
element.invoke(target);
|
||||
}
|
||||
|
|
|
@ -1831,7 +1831,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
|||
|
||||
if (initMethod == null) {
|
||||
if (mbd.isEnforceInitMethod()) {
|
||||
throw new BeanDefinitionValidationException("Couldn't find an init method named '" +
|
||||
throw new BeanDefinitionValidationException("Could not find an init method named '" +
|
||||
initMethodName + "' on bean with name '" + beanName + "'");
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Reference in New Issue