Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
4deef379
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,发现更多精彩内容 >>
提交
4deef379
编写于
7月 22, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
@PostConstruct works for multiple private init methods of the same name in a hierarchy (SPR-5945)
上级
9696c665
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
4 deletion
+43
-4
org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java
...ry/annotation/InitDestroyAnnotationBeanPostProcessor.java
+21
-4
org.springframework.context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java
...xt/annotation/CommonAnnotationBeanPostProcessorTests.java
+22
-0
未找到文件。
org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java
浏览文件 @
4deef379
...
...
@@ -20,6 +20,7 @@ import java.io.Serializable;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Modifier
;
import
java.util.Iterator
;
import
java.util.LinkedHashSet
;
import
java.util.Map
;
...
...
@@ -118,7 +119,7 @@ public class InitDestroyAnnotationBeanPostProcessor
if
(
beanType
!=
null
)
{
LifecycleMetadata
metadata
=
findLifecycleMetadata
(
beanType
);
for
(
Iterator
<
LifecycleElement
>
it
=
metadata
.
getInitMethods
().
iterator
();
it
.
hasNext
();)
{
String
methodName
=
it
.
next
().
getMethod
().
getName
(
);
String
methodName
=
calculateMethodIdentifierInHierarchy
(
it
.
next
().
getMethod
()
);
if
(!
beanDefinition
.
isExternallyManagedInitMethod
(
methodName
))
{
beanDefinition
.
registerExternallyManagedInitMethod
(
methodName
);
}
...
...
@@ -127,7 +128,7 @@ public class InitDestroyAnnotationBeanPostProcessor
}
}
for
(
Iterator
<
LifecycleElement
>
it
=
metadata
.
getDestroyMethods
().
iterator
();
it
.
hasNext
();)
{
String
methodName
=
it
.
next
().
getMethod
().
getName
(
);
String
methodName
=
calculateMethodIdentifierInHierarchy
(
it
.
next
().
getMethod
()
);
if
(!
beanDefinition
.
isExternallyManagedDestroyMethod
(
methodName
))
{
beanDefinition
.
registerExternallyManagedDestroyMethod
(
methodName
);
}
...
...
@@ -176,6 +177,15 @@ public class InitDestroyAnnotationBeanPostProcessor
}
private
String
calculateMethodIdentifierInHierarchy
(
Method
method
)
{
if
(
Modifier
.
isPrivate
(
method
.
getModifiers
()))
{
return
method
.
getDeclaringClass
()
+
"."
+
method
.
getName
();
}
else
{
return
method
.
getName
();
}
}
private
LifecycleMetadata
findLifecycleMetadata
(
Class
clazz
)
{
if
(
this
.
lifecycleMetadataCache
==
null
)
{
// Happens after deserialization, during destruction...
...
...
@@ -299,8 +309,15 @@ public class InitDestroyAnnotationBeanPostProcessor
@Override
public
boolean
equals
(
Object
other
)
{
return
(
this
==
other
||
(
other
instanceof
LifecycleElement
&&
this
.
method
.
getName
().
equals
(((
LifecycleElement
)
other
).
method
.
getName
())));
if
(
this
==
other
)
{
return
true
;
}
if
(!(
other
instanceof
LifecycleElement
))
{
return
false
;
}
LifecycleElement
otherElement
=
(
LifecycleElement
)
other
;
return
(
this
.
method
.
getName
().
equals
(
otherElement
.
method
.
getName
())
&&
this
.
method
.
getDeclaringClass
().
equals
(
otherElement
.
method
.
getDeclaringClass
()));
}
@Override
...
...
org.springframework.context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java
浏览文件 @
4deef379
...
...
@@ -113,11 +113,13 @@ public class CommonAnnotationBeanPostProcessorTests {
ResourceInjectionBean
bean
=
(
ResourceInjectionBean
)
bf
.
getBean
(
"annotatedBean"
);
assertTrue
(
bean
.
initCalled
);
assertTrue
(
bean
.
init2Called
);
assertTrue
(
bean
.
init3Called
);
assertSame
(
tb
,
bean
.
getTestBean
());
assertSame
(
tb2
,
bean
.
getTestBean2
());
bf
.
destroySingletons
();
assertTrue
(
bean
.
destroyCalled
);
assertTrue
(
bean
.
destroy2Called
);
assertTrue
(
bean
.
destroy3Called
);
}
@Test
...
...
@@ -338,8 +340,12 @@ public class CommonAnnotationBeanPostProcessorTests {
public
boolean
init2Called
=
false
;
public
boolean
init3Called
=
false
;
public
boolean
destroy2Called
=
false
;
public
boolean
destroy3Called
=
false
;
@Resource
private
TestBean
testBean
;
...
...
@@ -356,6 +362,14 @@ public class CommonAnnotationBeanPostProcessorTests {
this
.
init2Called
=
true
;
}
@PostConstruct
private
void
init
()
{
if
(
this
.
init3Called
)
{
throw
new
IllegalStateException
(
"Already called"
);
}
this
.
init3Called
=
true
;
}
@PreDestroy
protected
void
destroy2
()
{
if
(
this
.
destroy2Called
)
{
...
...
@@ -364,6 +378,14 @@ public class CommonAnnotationBeanPostProcessorTests {
this
.
destroy2Called
=
true
;
}
@PreDestroy
private
void
destroy
()
{
if
(
this
.
destroy3Called
)
{
throw
new
IllegalStateException
(
"Already called"
);
}
this
.
destroy3Called
=
true
;
}
@Resource
public
void
setTestBean2
(
TestBean
testBean2
)
{
if
(
this
.
testBean2
!=
null
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录