Reputation: 26860
After reviewing the AOP pattern, I'm overwhelmed with the ways of how and what to use it for in my spring project.
I'd like to use it as audit log system of all the financial business logic. It just seems to be easy to integrate. But I'd like to hear your take on this.
The question is - what other uses should I consider that are common for this pattern? I would not mind refactoring my current logic to be used with AOP as long as there is benefits to it.
Upvotes: 26
Views: 22324
Reputation: 790
It can be used to expose custom metrics (Instrumentation of service) for Alerting and Monitoring of service using client libraries like dropwizard, prometheus.
It helped us, to
Keep these cross-cutting concerns at one single place.
Declaratively apply them wherever required.
For example, To expose
Upvotes: 2
Reputation: 4177
The most common usage is where your application has cross cutting concerns i.e. a piece of logic or code that is going to be written in multiple classes/layers.
And this could vary based on your needs. Some very common examples of these could be:
Hope that helps.
Upvotes: 25
Reputation: 845
You can use AOP for your security concerns, for example allow/disallow method access. Another usage of aop is to test your application performance.
Upvotes: 2
Reputation: 35169
The most common use is probably the declarative transaction handling using @Transactional
.
Upvotes: 10
Reputation: 35598
As an answer slightly different from what @Axel said, using it to automatically intercept all of your data access calls and apply transactions appropriately is phenomenal. I have mine set up to implement all calls to my dao package that don't start with "get" in a transaction and then anything performed in a method starting with "get" is treated as read only. It's fantastic because aside from the initial setup, I don't have to worry about it, just follow the naming convention.
Upvotes: 1
Reputation: 6229
Using AOP for audit logging is a perfectly valid use of AOP. You can turn it off for testing and change it as requirements change in production.
The only downside in this case is if you were planning on doing the audit log via SQL. It may be more performant to implement this kind of auditing as triggers directly in the DB.
Upvotes: 2
Reputation: 20800
Besides logging/auditing and declarative transaction handling as mentioned by Axel, I would say another usage of AOP is as a request interceptor. For example, let's say you need all requests coming of a server to be intercepted so that you can do something with it (may be to keep track of which app is sending what request to what other app or what database, etc).
Upvotes: 15