Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
d1b5b5d2
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,发现更多精彩内容 >>
提交
d1b5b5d2
编写于
10月 16, 2017
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clarify destroy method suppression for DisposableBean vs (Auto)Closeable
Issue: SPR-16078 (cherry picked from commit
dff2c84e
)
上级
2d05e538
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
6 deletion
+29
-6
spring-context/src/main/java/org/springframework/context/annotation/Bean.java
...ain/java/org/springframework/context/annotation/Bean.java
+7
-3
spring-context/src/test/java/org/springframework/context/annotation/DestroyMethodInferenceTests.java
...ework/context/annotation/DestroyMethodInferenceTests.java
+22
-3
未找到文件。
spring-context/src/main/java/org/springframework/context/annotation/Bean.java
浏览文件 @
d1b5b5d2
...
...
@@ -228,6 +228,8 @@ public @interface Bean {
* Not commonly used, given that the method may be called programmatically directly
* within the body of a Bean-annotated method.
* <p>The default value is {@code ""}, indicating no init method to be called.
* @see org.springframework.beans.factory.InitializingBean
* @see org.springframework.context.ConfigurableApplicationContext#refresh()
*/
String
initMethod
()
default
""
;
...
...
@@ -248,12 +250,14 @@ public @interface Bean {
* creation time).
* <p>To disable destroy method inference for a particular {@code @Bean}, specify an
* empty string as the value, e.g. {@code @Bean(destroyMethod="")}. Note that the
* {@link org.springframework.beans.factory.DisposableBean} and the
* {@link java.io.Closeable}/{@link java.lang.AutoCloseable} interfaces will
* nevertheless get detected and the corresponding destroy/close method invoked.
* {@link org.springframework.beans.factory.DisposableBean} callback interface will
* nevertheless get detected and the corresponding destroy method invoked: In other
* words, {@code destroyMethod=""} only affects custom close/shutdown methods and
* {@link java.io.Closeable}/{@link java.lang.AutoCloseable} declared close methods.
* <p>Note: Only invoked on beans whose lifecycle is under the full control of the
* factory, which is always the case for singletons but not guaranteed for any
* other scope.
* @see org.springframework.beans.factory.DisposableBean
* @see org.springframework.context.ConfigurableApplicationContext#close()
*/
String
destroyMethod
()
default
AbstractBeanDefinition
.
INFER_METHOD
;
...
...
spring-context/src/test/java/org/springframework/context/annotation/DestroyMethodInferenceTests.java
浏览文件 @
d1b5b5d2
...
...
@@ -17,10 +17,10 @@
package
org.springframework.context.annotation
;
import
java.io.Closeable
;
import
java.io.IOException
;
import
org.junit.Test
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.support.GenericXmlApplicationContext
;
...
...
@@ -46,6 +46,7 @@ public class DestroyMethodInferenceTests {
WithNoCloseMethod
c6
=
ctx
.
getBean
(
"c6"
,
WithNoCloseMethod
.
class
);
WithLocalShutdownMethod
c7
=
ctx
.
getBean
(
"c7"
,
WithLocalShutdownMethod
.
class
);
WithInheritedCloseMethod
c8
=
ctx
.
getBean
(
"c8"
,
WithInheritedCloseMethod
.
class
);
WithDisposableBean
c9
=
ctx
.
getBean
(
"c9"
,
WithDisposableBean
.
class
);
assertThat
(
c0
.
closed
,
is
(
false
));
assertThat
(
c1
.
closed
,
is
(
false
));
...
...
@@ -56,6 +57,7 @@ public class DestroyMethodInferenceTests {
assertThat
(
c6
.
closed
,
is
(
false
));
assertThat
(
c7
.
closed
,
is
(
false
));
assertThat
(
c8
.
closed
,
is
(
false
));
assertThat
(
c9
.
closed
,
is
(
false
));
ctx
.
close
();
assertThat
(
"c0"
,
c0
.
closed
,
is
(
true
));
assertThat
(
"c1"
,
c1
.
closed
,
is
(
true
));
...
...
@@ -66,6 +68,7 @@ public class DestroyMethodInferenceTests {
assertThat
(
"c6"
,
c6
.
closed
,
is
(
false
));
assertThat
(
"c7"
,
c7
.
closed
,
is
(
true
));
assertThat
(
"c8"
,
c8
.
closed
,
is
(
false
));
assertThat
(
"c9"
,
c9
.
closed
,
is
(
true
));
}
@Test
...
...
@@ -123,7 +126,7 @@ public class DestroyMethodInferenceTests {
public
WithInheritedCloseMethod
c5
()
{
return
new
WithInheritedCloseMethod
()
{
@Override
public
void
close
()
throws
IOException
{
public
void
close
()
{
throw
new
IllegalStateException
(
"close() should not be called"
);
}
@SuppressWarnings
(
"unused"
)
...
...
@@ -147,6 +150,11 @@ public class DestroyMethodInferenceTests {
public
WithInheritedCloseMethod
c8
()
{
return
new
WithInheritedCloseMethod
();
}
@Bean
(
destroyMethod
=
""
)
public
WithDisposableBean
c9
()
{
return
new
WithDisposableBean
();
}
}
...
...
@@ -175,7 +183,18 @@ public class DestroyMethodInferenceTests {
boolean
closed
=
false
;
@Override
public
void
close
()
throws
IOException
{
public
void
close
()
{
closed
=
true
;
}
}
static
class
WithDisposableBean
implements
DisposableBean
{
boolean
closed
=
false
;
@Override
public
void
destroy
()
{
closed
=
true
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录