Spring AOP忽略Hessian Service的一些方法
我有一个具有以下切入点定义的方面
@Pointcut("execution(public de.company.project..* *(..))")
和一个包含以下内容的 spring 配置
<aop:aspectj-autoproxy />
<bean id="myaspect"
class="de.company.project.impl.MyAspect" />
<bean id="someService" class="de.company.project.impl.SomeService" />
<bean name="/SomeService"
class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="someService" />
<property name="serviceInterface"
value="de.company.project.interf.SomeService" />
</bean>
(实际配置中有多个服务)
我看到该方面在某些方法中被调用,但不是在所有方法中都被调用。我怀疑(但还不完全确定)只有直接在接口中声明的方法被包装在方面中,并且在超级接口中声明的方法被忽略(尽管该接口应该匹配相同的切入点)。
这是预期的行为吗?我怎样才能改变它?还可能发生什么?
I have an Aspect with the following pointcut definition
@Pointcut("execution(public de.company.project..* *(..))")
and a spring configuration containing the following
<aop:aspectj-autoproxy />
<bean id="myaspect"
class="de.company.project.impl.MyAspect" />
<bean id="someService" class="de.company.project.impl.SomeService" />
<bean name="/SomeService"
class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="someService" />
<property name="serviceInterface"
value="de.company.project.interf.SomeService" />
</bean>
(there are multiple services in the real configuration)
I see the aspect getting invoked in some methods, but not on all. I am suspecting (but not completely shure yet) only the methods declared directly in the interface get wrapped in the aspect and methods declared in a superinterface get ignored (although that interface should match the same pointcut).
Is this expected behaviour? How can I change it? What else might be going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是一个猜测。我没有证据证明这可能是您设置中的实际原因。
我知道Spring AOP不会拦截本地方法调用。即,如果同一对象调用其自己的方法,即使它与切入点表达式匹配,所应用的代理也不会拦截调用。
编辑:另一个猜测。您确定相关类的所有实例都是 Spring 托管代码吗?您的代码(或某些库)的某些部分是否有可能在不使用 Spring 的情况下创建类的实例?
如果发生这种情况,Spring AOP 无法拦截此类 bean,因为 Spring AOP 仅围绕 Spring 管理的 bean 编织。
Just a guess. I haven't got a proof this might be the actual reason in your setup.
I know that Spring AOP won't intercept local method calls. I.e. the proxy which is applied doesn't intercept the calls if the same object calls its own method, even if it matches the pointcut expression.
EDIT: Another guess. Are you sure all your instances of the classes in question are Spring managed code? Is there any chance that some portions of your code (or some library) creates instances of the classes without using Spring?
If such things happen, Spring AOP cannot intercept such beans as Spring AOP weaves around Spring-managed beans only.
答案是:我搞乱了切入点模式。看起来 this
指定了返回类型的包,而 this
指定了具有该方法的类型的包。
请参阅我需要 Spring AOP 切入点说明
The answer is: I messed up the Pointcut pattern. Looks like this
specifies the package of the return type, while this
specifies the package of the type which has the method.
see I need a Spring AOP pointcut explanation