Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
fd159ad0
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fd159ad0
编写于
6月 11, 2019
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Custom init/destroy methods get invoked through interface is possible
Closes gh-22939
上级
dec6d698
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
13 addition
and
10 deletion
+13
-10
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
...s/factory/support/AbstractAutowireCapableBeanFactory.java
+4
-3
spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
...ramework/beans/factory/support/DisposableBeanAdapter.java
+9
-7
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
浏览文件 @
fd159ad0
...
...
@@ -1860,7 +1860,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
String
initMethodName
=
mbd
.
getInitMethodName
();
Assert
.
state
(
initMethodName
!=
null
,
"No init method set"
);
final
Method
initMethod
=
(
mbd
.
isNonPublicAccessAllowed
()
?
Method
initMethod
=
(
mbd
.
isNonPublicAccessAllowed
()
?
BeanUtils
.
findMethod
(
bean
.
getClass
(),
initMethodName
)
:
ClassUtils
.
getMethodIfAvailable
(
bean
.
getClass
(),
initMethodName
));
...
...
@@ -1882,15 +1882,16 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
"Invoking init method '"
+
initMethodName
+
"' on bean with name '"
+
beanName
+
"'"
);
}
Method
methodToInvoke
=
ClassUtils
.
getInterfaceMethodIfPossible
(
initMethod
);
if
(
System
.
getSecurityManager
()
!=
null
)
{
AccessController
.
doPrivileged
((
PrivilegedAction
<
Object
>)
()
->
{
ReflectionUtils
.
makeAccessible
(
initMethod
);
ReflectionUtils
.
makeAccessible
(
methodToInvoke
);
return
null
;
});
try
{
AccessController
.
doPrivileged
((
PrivilegedExceptionAction
<
Object
>)
()
->
initMethod
.
invoke
(
bean
),
getAccessControlContext
());
methodToInvoke
.
invoke
(
bean
),
getAccessControlContext
());
}
catch
(
PrivilegedActionException
pae
)
{
InvocationTargetException
ex
=
(
InvocationTargetException
)
pae
.
getException
();
...
...
spring-beans/src/main/java/org/springframework/beans/factory/support/DisposableBeanAdapter.java
浏览文件 @
fd159ad0
/*
* Copyright 2002-201
8
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -112,15 +112,15 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
if
(
destroyMethodName
!=
null
&&
!(
this
.
invokeDisposableBean
&&
"destroy"
.
equals
(
destroyMethodName
))
&&
!
beanDefinition
.
isExternallyManagedDestroyMethod
(
destroyMethodName
))
{
this
.
destroyMethodName
=
destroyMethodName
;
this
.
destroyMethod
=
determineDestroyMethod
(
destroyMethodName
);
if
(
this
.
destroyMethod
==
null
)
{
Method
destroyMethod
=
determineDestroyMethod
(
destroyMethodName
);
if
(
destroyMethod
==
null
)
{
if
(
beanDefinition
.
isEnforceDestroyMethod
())
{
throw
new
BeanDefinitionValidationException
(
"Could not find a destroy method named '"
+
destroyMethodName
+
"' on bean with name '"
+
beanName
+
"'"
);
}
}
else
{
Class
<?>[]
paramTypes
=
this
.
destroyMethod
.
getParameterTypes
();
Class
<?>[]
paramTypes
=
destroyMethod
.
getParameterTypes
();
if
(
paramTypes
.
length
>
1
)
{
throw
new
BeanDefinitionValidationException
(
"Method '"
+
destroyMethodName
+
"' of bean '"
+
beanName
+
"' has more than one parameter - not supported as destroy method"
);
...
...
@@ -129,7 +129,9 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
throw
new
BeanDefinitionValidationException
(
"Method '"
+
destroyMethodName
+
"' of bean '"
+
beanName
+
"' has a non-boolean parameter - not supported as destroy method"
);
}
destroyMethod
=
ClassUtils
.
getInterfaceMethodIfPossible
(
destroyMethod
);
}
this
.
destroyMethod
=
destroyMethod
;
}
this
.
beanPostProcessors
=
filterPostProcessors
(
postProcessors
,
bean
);
}
...
...
@@ -271,9 +273,9 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {
invokeCustomDestroyMethod
(
this
.
destroyMethod
);
}
else
if
(
this
.
destroyMethodName
!=
null
)
{
Method
methodTo
Call
=
determineDestroyMethod
(
this
.
destroyMethodName
);
if
(
methodTo
Call
!=
null
)
{
invokeCustomDestroyMethod
(
methodToCall
);
Method
methodTo
Invoke
=
determineDestroyMethod
(
this
.
destroyMethodName
);
if
(
methodTo
Invoke
!=
null
)
{
invokeCustomDestroyMethod
(
ClassUtils
.
getInterfaceMethodIfPossible
(
methodToInvoke
)
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录