I want to monitor all public methods of all Classes with specified annotation (say @Monitor) (note: Annotation is at class level). What could be a possible pointcut for this? Note: I am using @AspectJ style Spring AOP.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
The simplest way seems to be :
It will intercept execution of all methods specifically annotated with '@MyHandling' in 'YourService' class. To intercept all methods without exception, just put the annotation directly on the class.
No matter of the private / public scope here, but keep in mind that spring-aop cannot use aspect for method calls in same instance (typically private ones), because it doesn't use the proxy class in this case.
We use @Around advice here, but it's basically the same syntax with @Before, @After or any advice.
By the way, @MyHandling annotation must be configured like this :
You could use Spring's PerformanceMonitoringInterceptor and programmatically register the advice using a beanpostprocessor.
Something like that:
Note that you must not have any other advice on the same class before this one, because the annotations will be lost after proxying.
You can also define the pointcut as
it should be enough to mark your aspect method like this:
have a look at this for a step by step guide on this.
You should combine a type pointcut with a method pointcut.
These pointcuts will do the work to find all public methods inside a class marked with an @Monitor annotation:
Advice the last pointcut that combines the first two and you're done!
If you're interested, I have written a cheat sheet with @AspectJ style here with a corresponding example document here.