Should I use AOP to solve this cross-cutting issue?

I used to use Spring AOP, but I'm not sure if this is the best method to solve this problem.

There is a service level class that has auto-updated DAOs to save the object. When the object is successfully saved, a message should be sent (SMS) to the phone number provided to the object.

Is it a standard practice for a service to not recognize bean messages using AOP or inject a bean into the service and send a message?

+4
source share
2 answers

It completely depends on the requirements of the business, you can achieve the same using Interceptors. After saving the object, you can call the interceptor after saving and send a message through it so that the service does not know about sending part of the message.

+2
source

I am not fully sold if this is the actual use of AOP (see options for using AOP? )

Personally, I have no problem with the fact that the level of service is known to the SMS message. However, as mentioned in this article, to avoid code duplication, I would look at the Entity Listener: http://www.mastertheboss.com/jboss-frameworks/hibernate-jpa/interceptors/jpa-entity-listeners

0
source

All Articles