Spring AOP ignores some methods of Hessian Service

2019-07-19 08:14发布

问题:

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.