Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
d49ecab8
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,发现更多精彩内容 >>
提交
d49ecab8
编写于
4月 29, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
f7ace544
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
23 deletion
+29
-23
spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvoker.java
...ingframework/cache/interceptor/CacheOperationInvoker.java
+7
-6
spring-context/src/test/java/org/springframework/cache/CacheReproTests.java
.../test/java/org/springframework/cache/CacheReproTests.java
+10
-8
spring-core/src/main/java/org/springframework/util/ReflectionUtils.java
...c/main/java/org/springframework/util/ReflectionUtils.java
+12
-9
未找到文件。
spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvoker.java
浏览文件 @
d49ecab8
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -21,8 +21,8 @@ package org.springframework.cache.interceptor;
*
* <p>Does not provide a way to transmit checked exceptions but
* provide a special exception that should be used to wrap any
* exception that was thrown by the underlying invocation.
Callers
* are expected to handle this issue type specifically.
* exception that was thrown by the underlying invocation.
*
Callers
are expected to handle this issue type specifically.
*
* @author Stephane Nicoll
* @since 4.1
...
...
@@ -38,11 +38,12 @@ public interface CacheOperationInvoker {
*/
Object
invoke
()
throws
ThrowableWrapper
;
/**
* Wrap any exception thrown while invoking {@link #invoke()}
* Wrap any exception thrown while invoking {@link #invoke()}
.
*/
@SuppressWarnings
(
"serial"
)
public
static
class
ThrowableWrapper
extends
RuntimeException
{
class
ThrowableWrapper
extends
RuntimeException
{
private
final
Throwable
original
;
...
...
@@ -52,7 +53,7 @@ public interface CacheOperationInvoker {
}
public
Throwable
getOriginal
()
{
return
original
;
return
this
.
original
;
}
}
...
...
spring-context/src/test/java/org/springframework/cache/CacheReproTests.java
浏览文件 @
d49ecab8
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -83,11 +83,11 @@ public class CacheReproTests {
String
key
=
"1"
;
Object
result
=
bean
.
getSimple
(
"1"
);
verify
(
cache
,
times
(
1
)).
get
(
key
);
// first call: cache miss
verify
(
cache
,
times
(
1
)).
get
(
key
);
// first call: cache miss
Object
cachedResult
=
bean
.
getSimple
(
"1"
);
assertSame
(
result
,
cachedResult
);
verify
(
cache
,
times
(
2
)).
get
(
key
);
// second call: cache hit
verify
(
cache
,
times
(
2
)).
get
(
key
);
// second call: cache hit
context
.
close
();
}
...
...
@@ -100,11 +100,11 @@ public class CacheReproTests {
String
key
=
"1"
;
Object
result
=
bean
.
getNeverCache
(
"1"
);
verify
(
cache
,
times
(
0
)).
get
(
key
);
// no cache hit at all, caching disabled
verify
(
cache
,
times
(
0
)).
get
(
key
);
// no cache hit at all, caching disabled
Object
cachedResult
=
bean
.
getNeverCache
(
"1"
);
assertNotSame
(
result
,
cachedResult
);
verify
(
cache
,
times
(
0
)).
get
(
key
);
// caching disabled
verify
(
cache
,
times
(
0
)).
get
(
key
);
// caching disabled
context
.
close
();
}
...
...
@@ -114,8 +114,9 @@ public class CacheReproTests {
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
Spr13081Config
.
class
);
MyCacheResolver
cacheResolver
=
context
.
getBean
(
MyCacheResolver
.
class
);
Spr13081Service
bean
=
context
.
getBean
(
Spr13081Service
.
class
);
assertNull
(
cacheResolver
.
getCache
(
"foo"
).
get
(
"foo"
));
Object
result
=
bean
.
getSimple
(
"foo"
);
// cache name = id
Object
result
=
bean
.
getSimple
(
"foo"
);
// cache name = id
assertEquals
(
result
,
cacheResolver
.
getCache
(
"foo"
).
get
(
"foo"
).
get
());
}
...
...
@@ -124,7 +125,6 @@ public class CacheReproTests {
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
Spr13081Config
.
class
);
Spr13081Service
bean
=
context
.
getBean
(
Spr13081Service
.
class
);
thrown
.
expect
(
IllegalStateException
.
class
);
thrown
.
expectMessage
(
MyCacheResolver
.
class
.
getName
());
bean
.
getSimple
(
null
);
...
...
@@ -245,6 +245,7 @@ public class CacheReproTests {
}
}
@Configuration
@EnableCaching
public
static
class
Spr13081Config
extends
CachingConfigurerSupport
{
...
...
@@ -259,9 +260,9 @@ public class CacheReproTests {
public
Spr13081Service
service
()
{
return
new
Spr13081Service
();
}
}
public
static
class
MyCacheResolver
extends
AbstractCacheResolver
{
public
MyCacheResolver
()
{
...
...
@@ -282,6 +283,7 @@ public class CacheReproTests {
}
}
public
static
class
Spr13081Service
{
@Cacheable
...
...
spring-core/src/main/java/org/springframework/util/ReflectionUtils.java
浏览文件 @
d49ecab8
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -265,7 +265,8 @@ public abstract class ReflectionUtils {
* checked exception is expected to be thrown by the target method.
* <p>Throws the underlying RuntimeException or Error in case of an
* InvocationTargetException with such a root cause. Throws an
* IllegalStateException with an appropriate message else.
* IllegalStateException with an appropriate message or
* UndeclaredThrowableException otherwise.
* @param ex the reflection exception to handle
*/
public
static
void
handleReflectionException
(
Exception
ex
)
{
...
...
@@ -288,7 +289,7 @@ public abstract class ReflectionUtils {
* Handle the given invocation target exception. Should only be called if no
* checked exception is expected to be thrown by the target method.
* <p>Throws the underlying RuntimeException or Error in case of such a root
* cause. Throws an
IllegalStateException el
se.
* cause. Throws an
UndeclaredThrowableException otherwi
se.
* @param ex the invocation target exception to handle
*/
public
static
void
handleInvocationTargetException
(
InvocationTargetException
ex
)
{
...
...
@@ -300,8 +301,9 @@ public abstract class ReflectionUtils {
* <em>target exception</em> of an {@link InvocationTargetException}.
* Should only be called if no checked exception is expected to be thrown
* by the target method.
* <p>Rethrows the underlying exception cast to an {@link RuntimeException} or
* {@link Error} if appropriate; otherwise, throws an {@link IllegalStateException}.
* <p>Rethrows the underlying exception cast to a {@link RuntimeException} or
* {@link Error} if appropriate; otherwise, throws an
* {@link UndeclaredThrowableException}.
* @param ex the exception to rethrow
* @throws RuntimeException the rethrown exception
*/
...
...
@@ -321,7 +323,8 @@ public abstract class ReflectionUtils {
* Should only be called if no checked exception is expected to be thrown
* by the target method.
* <p>Rethrows the underlying exception cast to an {@link Exception} or
* {@link Error} if appropriate; otherwise, throws an {@link IllegalStateException}.
* {@link Error} if appropriate; otherwise, throws an
* {@link UndeclaredThrowableException}.
* @param ex the exception to rethrow
* @throws Exception the rethrown exception (in case of a checked exception)
*/
...
...
@@ -804,7 +807,7 @@ public abstract class ReflectionUtils {
/**
* Pre-built FieldFilter that matches all non-static, non-final fields.
*/
public
static
FieldFilter
COPYABLE_FIELDS
=
new
FieldFilter
()
{
public
static
final
FieldFilter
COPYABLE_FIELDS
=
new
FieldFilter
()
{
@Override
public
boolean
matches
(
Field
field
)
{
...
...
@@ -816,7 +819,7 @@ public abstract class ReflectionUtils {
/**
* Pre-built MethodFilter that matches all non-bridge methods.
*/
public
static
MethodFilter
NON_BRIDGED_METHODS
=
new
MethodFilter
()
{
public
static
final
MethodFilter
NON_BRIDGED_METHODS
=
new
MethodFilter
()
{
@Override
public
boolean
matches
(
Method
method
)
{
...
...
@@ -829,7 +832,7 @@ public abstract class ReflectionUtils {
* Pre-built MethodFilter that matches all non-bridge methods
* which are not declared on {@code java.lang.Object}.
*/
public
static
MethodFilter
USER_DECLARED_METHODS
=
new
MethodFilter
()
{
public
static
final
MethodFilter
USER_DECLARED_METHODS
=
new
MethodFilter
()
{
@Override
public
boolean
matches
(
Method
method
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录