DisposableBeanAdapter.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:lams 作者:
/**
 * Create a new DisposableBeanAdapter for the given bean.
 * @param bean the bean instance (never {@code null})
 * @param beanName the name of the bean
 * @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, 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();
        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 && !paramTypes[0].equals(boolean.class)) {
                throw new BeanDefinitionValidationException("Method '" + destroyMethodName + "' of bean '" +
                        beanName + "' has a non-boolean parameter - not supported as destroy method");
            }
        }
    }
    this.beanPostProcessors = filterPostProcessors(postProcessors);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号