Example usage for org.springframework.beans.factory.support RootBeanDefinition isExternallyManagedDestroyMethod

List of usage examples for org.springframework.beans.factory.support RootBeanDefinition isExternallyManagedDestroyMethod

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support RootBeanDefinition isExternallyManagedDestroyMethod.

Prototype

public boolean isExternallyManagedDestroyMethod(String destroyMethod) 

Source Link

Usage

From source file:org.springframework.beans.factory.support.DisposableBeanAdapter.java

/**
 * Create a new DisposableBeanAdapter for the given bean.
 * @param bean the bean instance (never {@code null})
 * @param beanName the name of the bean/*from  w  w  w  .  j a  va 2s. c om*/
 * @param beanDefinition the merged bean definition
 * @param postProcessors the List of BeanPostProcessors
 * (potentially DestructionAwareBeanPostProcessor), if any
 */
public DisposableBeanAdapter(Object bean, String beanName, RootBeanDefinition beanDefinition,
        List<BeanPostProcessor> postProcessors, @Nullable AccessControlContext acc) {

    Assert.notNull(bean, "Disposable bean must not be null");
    this.bean = bean;
    this.beanName = beanName;
    this.invokeDisposableBean = (this.bean instanceof DisposableBean
            && !beanDefinition.isExternallyManagedDestroyMethod("destroy"));
    this.nonPublicAccessAllowed = beanDefinition.isNonPublicAccessAllowed();
    this.acc = acc;
    String destroyMethodName = inferDestroyMethodIfNecessary(bean, beanDefinition);
    if (destroyMethodName != null && !(this.invokeDisposableBean && "destroy".equals(destroyMethodName))
            && !beanDefinition.isExternallyManagedDestroyMethod(destroyMethodName)) {
        this.destroyMethodName = destroyMethodName;
        this.destroyMethod = determineDestroyMethod(destroyMethodName);
        if (this.destroyMethod == null) {
            if (beanDefinition.isEnforceDestroyMethod()) {
                throw new BeanDefinitionValidationException("Couldn't find a destroy method named '"
                        + destroyMethodName + "' on bean with name '" + beanName + "'");
            }
        } else {
            Class<?>[] paramTypes = this.destroyMethod.getParameterTypes();
            if (paramTypes.length > 1) {
                throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '"
                        + beanName + "' has more than one parameter - not supported as destroy method");
            } else if (paramTypes.length == 1 && boolean.class != paramTypes[0]) {
                throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '"
                        + beanName + "' has a non-boolean parameter - not supported as destroy method");
            }
        }
    }
    this.beanPostProcessors = filterPostProcessors(postProcessors, bean);
}