Spring AOP ignores some methods of Hessian Service

江枫思渺然 提交于 2019-12-24 03:29:23

问题


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?


回答1:


The answer is: I messed up the Pointcut pattern. Looks like this

@Pointcut("execution(public de.company.project..* *(..))")

specifies the package of the return type, while this

@Pointcut("execution(public de.company.project..*(..))")

specifies the package of the type which has the method.

see I need a Spring AOP pointcut explanation




回答2:


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.



来源:https://stackoverflow.com/questions/5141359/spring-aop-ignores-some-methods-of-hessian-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!