Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
8b2d9951
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,发现更多精彩内容 >>
提交
8b2d9951
编写于
4月 15, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
AnnotationAsyncExecutionAspect properly accepts ListenableFuture return type
Issue: SPR-12895
上级
c006b74e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
27 deletion
+36
-27
spring-aspects/src/main/java/org/springframework/scheduling/aspectj/AnnotationAsyncExecutionAspect.aj
...work/scheduling/aspectj/AnnotationAsyncExecutionAspect.aj
+23
-24
spring-aspects/src/test/java/org/springframework/scheduling/aspectj/AnnotationAsyncExecutionAspectTests.java
...heduling/aspectj/AnnotationAsyncExecutionAspectTests.java
+13
-3
未找到文件。
spring-aspects/src/main/java/org/springframework/scheduling/aspectj/AnnotationAsyncExecutionAspect.aj
浏览文件 @
8b2d9951
/*
*
Copyright
2002
-
201
2
the
original
author
or
authors
.
*
Copyright
2002
-
201
5
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
.
...
...
@@ -23,15 +23,15 @@ import org.springframework.core.annotation.AnnotationUtils;
import
org
.
springframework
.
scheduling
.
annotation
.
Async
;
/**
*
Aspect
to
route
methods
based
on
the
{@
link
Async
}
annotation
.
*
Aspect
to
route
methods
based
on
Spring
's
{@link Async} annotation.
*
*
<
p
>
This
aspect
routes
methods
marked
with
the
{@
link
Async
}
annotation
*
as
well
as
methods
in
classes
marked
with
the
same
.
Any
method
expected
*
to
be
routed
asynchronously
must
return
either
{@
code
void
},
{@
link
Future
}
,
*
or
a
subtype
of
{@
link
Future
}.
This
aspect
,
therefore
,
will
produce
*
a
compile
-
time
error
for
methods
that
violate
this
constraint
on
the
return
type
.
*
If
,
however
,
a
class
marked
with
{@
code
@
Async
}
contains
a
method
that
violates
this
*
constraint
,
it
produces
only
a
warning
.
* <p>This aspect routes methods marked with the {@link Async} annotation
as well as methods
*
in classes marked with the same. Any method expected to be routed asynchronously must
*
return either {@code void}, {@link Future}, or a subtype of {@link Future} (in particular
,
*
Spring'
s
{@
link
org
.
springframework
.
util
.
concurrent
.
ListenableFuture
}).
This
aspect
,
*
therefore
,
will
produce
a
compile
-
time
error
for
methods
that
violate
this
constraint
*
on
the
return
type
.
If
,
however
,
a
class
marked
with
{@
code
@
Async
}
contains
a
method
*
that
violates
this
constraint
,
it
produces
only
a
warning
.
*
*
@
author
Ramnivas
Laddad
*
@
author
Chris
Beams
...
...
@@ -39,42 +39,41 @@ import org.springframework.scheduling.annotation.Async;
*/
public
aspect
AnnotationAsyncExecutionAspect
extends
AbstractAsyncExecutionAspect
{
private
pointcut
asyncMarkedMethod
()
:
execution
(@
Async
(
void
||
Future
+)
*(..));
private
pointcut
asyncMarkedMethod
()
:
execution
(@
Async
(
void
||
Future
+)
*(..));
private
pointcut
asyncTypeMarkedMethod
()
:
execution
((
void
||
Future
+)
(@
Async
*).*(..));
private
pointcut
asyncTypeMarkedMethod
()
:
execution
((
void
||
Future
+)
(@
Async
*).*(..));
public
pointcut
asyncMethod
()
:
asyncMarkedMethod
()
||
asyncTypeMarkedMethod
();
/**
*
{@
inheritDoc
}
*
<
p
>
This
implementation
inspects
the
given
method
and
its
declaring
class
for
the
*
{@
code
@
Async
}
annotation
,
returning
the
qualifier
value
expressed
by
*
{@
link
Async
#
value
()}.
If
{@
code
@
Async
}
is
specified
at
both
the
method
and
class
level
,
the
*
method
's {@code #value} takes precedence (even if empty string, indicating that
* the default executor should be used preferentially).
*
This
implementation
inspects
the
given
method
and
its
declaring
class
for
the
*
{@
code
@
Async
}
annotation
,
returning
the
qualifier
value
expressed
by
{@
link
Async
#
value
()}.
*
If
{@
code
@
Async
}
is
specified
at
both
the
method
and
class
level
,
the
method
's
* {@code #value} takes precedence (even if empty string, indicating that the default
* executor should be used preferentially).
* @return the qualifier if specified, otherwise empty string indicating that the
* {@linkplain #setExecutor
(Executor)
default executor} should be used
* {@linkplain #setExecutor default executor} should be used
* @see #determineAsyncExecutor(Method)
*/
@Override
protected String getExecutorQualifier(Method method) {
//
m
aintainer'
s
note
:
changes
made
here
should
also
be
made
in
//
M
aintainer'
s
note
:
changes
made
here
should
also
be
made
in
//
AnnotationAsyncExecutionInterceptor
#
getExecutorQualifier
Async
async
=
AnnotationUtils
.
findAnnotation
(
method
,
Async
.
class
);
if
(
async
==
null
)
{
async
=
AnnotationUtils
.
findAnnotation
(
method
.
getDeclaringClass
(),
Async
.
class
);
}
return
async
==
null
?
null
:
async
.
value
(
);
return
(
async
!= null ? async.value() : null
);
}
declare
error
:
execution
(@
Async
!(void
||Future
) *(..)):
execution
(@
Async
!(void
|| Future+
) *(..)):
"Only methods that return void or Future may have an @Async annotation"
;
declare
warning
:
execution
(
!(void
||Future
) (@Async *).*(..)):
execution
(
!(void
|| Future+
) (@Async *).*(..)):
"Methods in a class marked with @Async that do not return void or Future will "
+
"be routed synchronously"
;
...
...
spring-aspects/src/test/java/org/springframework/scheduling/aspectj/AnnotationAsyncExecutionAspectTests.java
浏览文件 @
8b2d9951
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -35,6 +35,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import
org.springframework.tests.Assume
;
import
org.springframework.tests.TestGroup
;
import
org.springframework.util.ReflectionUtils
;
import
org.springframework.util.concurrent.ListenableFuture
;
import
static
org
.
hamcrest
.
CoreMatchers
.
startsWith
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
...
...
@@ -50,9 +51,10 @@ public class AnnotationAsyncExecutionAspectTests {
private
static
final
long
WAIT_TIME
=
1000
;
//milliseconds
private
final
AsyncUncaughtExceptionHandler
defaultExceptionHandler
=
new
SimpleAsyncUncaughtExceptionHandler
();
private
CountingExecutor
executor
;
private
AsyncUncaughtExceptionHandler
defaultExceptionHandler
=
new
SimpleAsyncUncaughtExceptionHandler
();
@Before
public
void
setUp
()
{
...
...
@@ -62,6 +64,7 @@ public class AnnotationAsyncExecutionAspectTests {
AnnotationAsyncExecutionAspect
.
aspectOf
().
setExecutor
(
executor
);
}
@Test
public
void
asyncMethodGetsRoutedAsynchronously
()
{
ClassWithoutAsyncAnnotation
obj
=
new
ClassWithoutAsyncAnnotation
();
...
...
@@ -184,7 +187,9 @@ public class AnnotationAsyncExecutionAspectTests {
@SuppressWarnings
(
"serial"
)
private
static
class
CountingExecutor
extends
SimpleAsyncTaskExecutor
{
int
submitStartCounter
;
int
submitCompleteCounter
;
@Override
...
...
@@ -209,6 +214,7 @@ public class AnnotationAsyncExecutionAspectTests {
static
class
ClassWithoutAsyncAnnotation
{
int
counter
;
@Async
public
void
incrementAsync
()
{
...
...
@@ -239,6 +245,7 @@ public class AnnotationAsyncExecutionAspectTests {
@Async
static
class
ClassWithAsyncAnnotation
{
int
counter
;
public
void
increment
()
{
...
...
@@ -261,17 +268,19 @@ public class AnnotationAsyncExecutionAspectTests {
static
class
ClassWithQualifiedAsyncMethods
{
@Async
public
Future
<
Thread
>
defaultWork
()
{
return
new
AsyncResult
<
Thread
>(
Thread
.
currentThread
());
}
@Async
(
"e1"
)
public
Future
<
Thread
>
e1Work
()
{
public
Listenable
Future
<
Thread
>
e1Work
()
{
return
new
AsyncResult
<
Thread
>(
Thread
.
currentThread
());
}
}
static
class
ClassWithException
{
@Async
...
...
@@ -279,4 +288,5 @@ public class AnnotationAsyncExecutionAspectTests {
throw
new
UnsupportedOperationException
(
"failWithVoid"
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录