Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
2a5d7690
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,体验更适合开发者的 AI 搜索 >>
提交
2a5d7690
编写于
11月 20, 2018
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CglibAopProxy skips method proxy for equals/hashCode/toString override
Issue: SPR-17500
上级
f5aeb814
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
5 deletion
+51
-5
spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java
...java/org/springframework/aop/framework/CglibAopProxy.java
+8
-5
spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java
...va/org/springframework/aop/framework/CglibProxyTests.java
+43
-0
未找到文件。
spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java
浏览文件 @
2a5d7690
...
...
@@ -723,17 +723,20 @@ class CglibAopProxy implements AopProxy, Serializable {
*/
private
static
class
CglibMethodInvocation
extends
ReflectiveMethodInvocation
{
@Nullable
private
final
MethodProxy
methodProxy
;
private
final
boolean
publicMethod
;
public
CglibMethodInvocation
(
Object
proxy
,
@Nullable
Object
target
,
Method
method
,
Object
[]
arguments
,
@Nullable
Class
<?>
targetClass
,
List
<
Object
>
interceptorsAndDynamicMethodMatchers
,
MethodProxy
methodProxy
)
{
super
(
proxy
,
target
,
method
,
arguments
,
targetClass
,
interceptorsAndDynamicMethodMatchers
);
this
.
methodProxy
=
methodProxy
;
this
.
publicMethod
=
Modifier
.
isPublic
(
method
.
getModifiers
());
// Only use method proxy for public methods not derived from java.lang.Object
this
.
methodProxy
=
(
Modifier
.
isPublic
(
method
.
getModifiers
())
&&
method
.
getDeclaringClass
()
!=
Object
.
class
&&
!
AopUtils
.
isEqualsMethod
(
method
)
&&
!
AopUtils
.
isHashCodeMethod
(
method
)
&&
!
AopUtils
.
isToStringMethod
(
method
)
?
methodProxy
:
null
);
}
/**
...
...
@@ -742,7 +745,7 @@ class CglibAopProxy implements AopProxy, Serializable {
*/
@Override
protected
Object
invokeJoinpoint
()
throws
Throwable
{
if
(
this
.
publicMethod
&&
getMethod
().
getDeclaringClass
()
!=
Object
.
class
)
{
if
(
this
.
methodProxy
!=
null
)
{
return
this
.
methodProxy
.
invoke
(
this
.
target
,
this
.
arguments
);
}
else
{
...
...
spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java
浏览文件 @
2a5d7690
...
...
@@ -74,6 +74,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
return
true
;
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testNullConfig
()
{
new
CglibAopProxy
(
null
);
...
...
@@ -153,6 +154,20 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
assertEquals
(
"The name property has been overwritten by the constructor"
,
"Rob Harrop"
,
proxy
.
getName
());
}
@Test
public
void
testToStringInvocation
()
{
PrivateCglibTestBean
bean
=
new
PrivateCglibTestBean
();
bean
.
setName
(
"Rob Harrop"
);
AdvisedSupport
as
=
new
AdvisedSupport
();
as
.
setTarget
(
bean
);
as
.
addAdvice
(
new
NopInterceptor
());
AopProxy
aop
=
new
CglibAopProxy
(
as
);
PrivateCglibTestBean
proxy
=
(
PrivateCglibTestBean
)
aop
.
getProxy
();
assertEquals
(
"The name property has been overwritten by the constructor"
,
"Rob Harrop"
,
proxy
.
toString
());
}
@Test
public
void
testUnadvisedProxyCreationWithCallDuringConstructor
()
{
CglibTestBean
target
=
new
CglibTestBean
();
...
...
@@ -480,6 +495,29 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
return
this
.
value
;
}
}
private
static
class
PrivateCglibTestBean
{
private
String
name
;
public
PrivateCglibTestBean
()
{
setName
(
"Some Default"
);
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getName
()
{
return
this
.
name
;
}
@Override
public
String
toString
()
{
return
this
.
name
;
}
}
}
...
...
@@ -498,6 +536,11 @@ class CglibTestBean {
public
String
getName
()
{
return
this
.
name
;
}
@Override
public
String
toString
()
{
return
this
.
name
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录