Uses Spring AOP to register a good idea?

I am reading Spring now, and one example used to use AOP registers the beginning and end of method calls.

I also read that using AOP can affect performance.

Does Spring AOP use a good idea for this type of logging? I understand that Spring uses Dynamic AOP, it would be better to use Static AOP (Like AspectJ) for this type of AOP.

In short, the coding policy of the company I work for requires a ridiculous amount of logging, and I want to reduce the amount of registration code I need to write and improve the readability of my code.

Am I barking the wrong tree?

+28
java spring spring-aop logging aop
Jan 15 '10 at 11:22
source share
3 answers

Read this blog post about your performance issues.

The way to think about AOP is to first deliver the provided functional benefits. If automatic logging is your requirement and AOP is right for it, go for it.

However, time rewinding time is, of course, preferable if fine-grained logging is required.

+13
Jan 15 '10 at 11:45
source share

I used Spring AOP to implement logging, so I share my observations:

  • The performance impact is not sufficient; it is less than the impact of logging itself
  • With aspects configured in your Spring configuration, you can completely disable logging code if necessary.
  • Debugging becomes more problematic as stack traces become longer
  • This decision affects the design enough. Itโ€™s not only that you get a bunch of interfaces and aspect classes, but you production classes must be very โ€œsubtleโ€. Remember that you cannot intercept calls for non-public methods. Independent calls (even public methods) also cannot be intercepted (since you are working with a bare this handle instead of a handle wrapped by AOP) and therefore cannot be registered. Thus, all entries can only occur at the boundaries of the interface. (This concerns the use of proxy-based testing, it is possible to subclass cglib runtime there, but I did not use it).
  • Writing a pointcut can be very difficult. IntelliJ Idea helps you significantly determine which methods pointcut should recommend.
  • In general, I liked this approach and I think that it is worth using, but it turned out to be much more complicated than I expected
+32
Jan 15 '10 at 11:52
source share

I did it the same way as described in this blog post . This is the best I have found, and it also has a sample that perfectly shows the difference between using and using AOP.

Imho it is not worth it if you do not do something more fun, and then register as error management with saving. If you have a good hierarchy of exceptions (domain, system) and logging boundaries are set correctly, you cannot significantly reduce the logging code.

+3
Jul 20 2018-11-21T00:
source share



All Articles