关于Schema-based AOP support 遇到的问题解决
2008-04-23 23:58
489 查看
在以aspectj方式声明AOP的时候,spring官方的参考手册中的对args的用法一直都是这样
<!-- this is the object that will be proxied by Spring's AOP infrastructure -->
<bean id="fooService" class="x.y.service.DefaultFooService"/>
<!-- this is the actual advice itself -->
<bean id="profiler" class="x.y.SimpleProfiler"/>
<aop:config>
<aop:aspect ref="profiler">
<aop:pointcut id="theExecutionOfSomeFooServiceMethod"
expression="execution(* x.y.service.FooService.getFoo(String,int))
and args(name, age)"/>
<aop:around pointcut-ref="theExecutionOfSomeFooServiceMethod"
method="profile"/>
</aop:aspect>
</aop:config>
注意name,age都是getFoo方法的临时变量名,而我在开发的时候按照这样的写法却报错warning no match for this type name: XX。在我把name,age换成String, int这两种类型名称后,很意外却能正常工作,
我开发的代码如下:
<aop:pointcut id="prefixPointCut"
expression="execution(* services.OcsServices.add*(..)) and args(prefix)" />
<aop:after pointcut-ref="prefixPointCut" method="afterAdd" arg-names="prefix" />
其中prefix是我另外定义的bean:
<bean id="prefix" class="pojo.Prefix">
</bean>
Advice触发的LogAop类的方法定义如下:
public void afterAdd(Prefix p) {
System.out.println(p.getMvnoname() +" afterAdd execute......");
}
被Aop的类OcsServices的方法定义为:
public void add(Object o){
…….
}
上面这些相关定义能正常的工作。但是当我将prefix改成o后(因为官方的定义都是定义为o,是临时变量名),即报异常warning no match for this type name: o;这个问题困扰了我3天,google了无数,论坛发帖求解,都无济于事,最后发现还是得靠自己。最后终于以官方教程得方式设置成功了,怎么做得呢?
<aop:pointcut id="prefixPointCut"
expression="execution(* services.OcsServices.add(Object)) and args(o)" />
<aop:after pointcut-ref="prefixPointCut" method="afterAdd" arg-names="o" />
Advice触发的LogAop类的方法定义如下:
public void afterAdd(Object o) {
Prefix p = (Prefix)o;
System.out.println(p.getMvnoname() +" afterAdd execute......");
}
被Aop的类OcsServices的方法定义为:
public void add(Object o){
…….
}
可以发现,所有得相关得参数都一致改成了o,很有意思,原来问题就在于我们必须对保持变量名一致,尽管这个变量运行在不同得方法不同得类中。
对于我们配置aop:after-returning这样可以捕获返回值得aop,目前也遇到了类似得问题,只是猜想类似而已,看配置:
<aop:pointcut id="prefixPointCutQuery"
expression="execution(* services.OcsServices.query(Object, int, int)) and args(Object, int, int)" />
<aop:after-returning
pointcut-ref="prefixPointCutQuery"
returning="retVal"
method="afterAddReturn"/>
Advice触发的LogAop类的方法定义如下:
public void afterAddReturn(Object retVal){
System.out.println(retVal);
}
被Aop的类OcsServices的方法定义为:
public List query(Object o, int page, int perpage){
………
}
上面这样得关联配置可以正常工作,但是当我改成这样后:
<aop:pointcut id="prefixPointCutQuery"
expression="execution(* services.OcsServices.query(Object, int, int)) and args(o, page, perpage)" />
同样报错warning no match for this type name: o;
但是当我改成:
<aop:pointcut id="prefixPointCutQuery"
expression="execution(* services.OcsServices.query(..))" />
却又是成功的。难道aop中的advice触发的方法没有使用o, page, perpage的话在args定义就会出现问题?这个原因没有能够得到官方的说法。
<!-- this is the object that will be proxied by Spring's AOP infrastructure -->
<bean id="fooService" class="x.y.service.DefaultFooService"/>
<!-- this is the actual advice itself -->
<bean id="profiler" class="x.y.SimpleProfiler"/>
<aop:config>
<aop:aspect ref="profiler">
<aop:pointcut id="theExecutionOfSomeFooServiceMethod"
expression="execution(* x.y.service.FooService.getFoo(String,int))
and args(name, age)"/>
<aop:around pointcut-ref="theExecutionOfSomeFooServiceMethod"
method="profile"/>
</aop:aspect>
</aop:config>
注意name,age都是getFoo方法的临时变量名,而我在开发的时候按照这样的写法却报错warning no match for this type name: XX。在我把name,age换成String, int这两种类型名称后,很意外却能正常工作,
我开发的代码如下:
<aop:pointcut id="prefixPointCut"
expression="execution(* services.OcsServices.add*(..)) and args(prefix)" />
<aop:after pointcut-ref="prefixPointCut" method="afterAdd" arg-names="prefix" />
其中prefix是我另外定义的bean:
<bean id="prefix" class="pojo.Prefix">
</bean>
Advice触发的LogAop类的方法定义如下:
public void afterAdd(Prefix p) {
System.out.println(p.getMvnoname() +" afterAdd execute......");
}
被Aop的类OcsServices的方法定义为:
public void add(Object o){
…….
}
上面这些相关定义能正常的工作。但是当我将prefix改成o后(因为官方的定义都是定义为o,是临时变量名),即报异常warning no match for this type name: o;这个问题困扰了我3天,google了无数,论坛发帖求解,都无济于事,最后发现还是得靠自己。最后终于以官方教程得方式设置成功了,怎么做得呢?
<aop:pointcut id="prefixPointCut"
expression="execution(* services.OcsServices.add(Object)) and args(o)" />
<aop:after pointcut-ref="prefixPointCut" method="afterAdd" arg-names="o" />
Advice触发的LogAop类的方法定义如下:
public void afterAdd(Object o) {
Prefix p = (Prefix)o;
System.out.println(p.getMvnoname() +" afterAdd execute......");
}
被Aop的类OcsServices的方法定义为:
public void add(Object o){
…….
}
可以发现,所有得相关得参数都一致改成了o,很有意思,原来问题就在于我们必须对保持变量名一致,尽管这个变量运行在不同得方法不同得类中。
对于我们配置aop:after-returning这样可以捕获返回值得aop,目前也遇到了类似得问题,只是猜想类似而已,看配置:
<aop:pointcut id="prefixPointCutQuery"
expression="execution(* services.OcsServices.query(Object, int, int)) and args(Object, int, int)" />
<aop:after-returning
pointcut-ref="prefixPointCutQuery"
returning="retVal"
method="afterAddReturn"/>
Advice触发的LogAop类的方法定义如下:
public void afterAddReturn(Object retVal){
System.out.println(retVal);
}
被Aop的类OcsServices的方法定义为:
public List query(Object o, int page, int perpage){
………
}
上面这样得关联配置可以正常工作,但是当我改成这样后:
<aop:pointcut id="prefixPointCutQuery"
expression="execution(* services.OcsServices.query(Object, int, int)) and args(o, page, perpage)" />
同样报错warning no match for this type name: o;
但是当我改成:
<aop:pointcut id="prefixPointCutQuery"
expression="execution(* services.OcsServices.query(..))" />
却又是成功的。难道aop中的advice触发的方法没有使用o, page, perpage的话在args定义就会出现问题?这个原因没有能够得到官方的说法。
相关文章推荐
- linux下安装Subversion遇到关于BerkeleyDB问题及解决方法
- 实际工作中遇到关于Struts2线程安全的问题解决
- 关于tomcat端口的修改,以及同时部署多个应用,自己遇到的问题以及解决办法
- VS2008中关于“加载安装组件时遇到问题。取消安装”的解决
- 关于nginx+uWsgi配置遇到的问题的解决
- 关于使用spring框架来实现email发送其中遇到的问题已解决
- 关于将Java中序列化对象写入byte[]遇到的一些问题及解决方法
- Schema-based AOP support
- 关于BadgeView遇到的一个奇怪的问题和解决办法
- 关于TP5视图分离到根目录的解决方法 原有: 为了方便前端开发,我想把视图(view)部分分离出来专门给前端进行修改 过程:在进行视图设置分离的过程遇到了问题 参考了官方文档http://www
- 关于VISTA遇到“Windows需要您的许可才能继续”的问题解决办法
- 关于工作中遇到的一些问题及解决方法
- 关于在使用codeblocks+wxWidgets的过程中遇到的问题及解决
- 关于mysql数据库常遇到的问题和解决方法
- VS2008中关于“加载安装组件时遇到问题。取消安装”的解决
- VS2008中关于“加载安装组件时遇到问题。取消安装”的解决
- 关于引用WebLogic.jar时遇到NoClassDefFoundError问题的解决方法
- 关于操作access遇到的问题以及解决办法
- 关于as遇到的Enable "Android Support" Plugin错误问题
- 解决重装VC++所遇到问题的方法(关于“内存不能read”)