I have a Spring AOP pointcut execution(* someService.*(..)).

Will this pointcut match constructor and bean get/set property methods?

THIS is not my intention, and also maybe this behaviour will hurt performance.

I just want to advise REAL service methods, such us getUserByID etc.

How do I exclude those methods (get/set/constructor)?

有帮助吗?

解决方案

That pointcut will match public methods in Spring AOP. So getters and setters, but not constructors.

The Spring reference for this is here. Section 8.2.3, look for "even constructors".

A clean way to only reference a group of methods is to apply the pointcut to an interface implemented by your service, instead of the service itself. This assumes your interface only contains business methods you want to advise.

其他提示

in case it's a third party library and you don't want to use a marker interface for some reason, you can always base yourself on naming conventions of the methods. For example this applies the aspect to getters only:

execution(* someService.get*(..))

this expression applies the aspect to both getters and setters:

execution(* someService.get*(..)) && execution(* someService.set*(..))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top