4

I've used Spring AOP before, but I'm not sure if that's the best method to go about this problem.

There's a service-layer class that has autowired DAOs to save an object. When an object is successfully saved, a message should be sent (SMS) to the object's supplied phone number.

Is it standard practice to keep the service unaware of the of the messaging bean using AOP, or to inject the bean into the service and send the message?

therealscifi
  • 362
  • 5
  • 12

2 Answers2

2

It totally depends on Business requirement, you can achieve the same thing using Interceptors too. Once object is saved you can call the interceptor after save and can send the message through it, making the service unaware of message sending part.

Arpit Aggarwal
  • 27,626
  • 16
  • 90
  • 108
0

I'm not totally sold on this being a valid use of AOP (see AOP use cases? )

Personally, I have no problem with the service layer being aware of the SMS message. However, as also mentioned in this thread, to avoid code duplication, I would look at an Entity Listener: http://www.mastertheboss.com/jboss-frameworks/hibernate-jpa/interceptors/jpa-entity-listeners

Community
  • 1
  • 1
Brian Kates
  • 480
  • 4
  • 14