Sobes.tech
Middle

If a bean C calls a method of bean A with logging aspect, and inside A, private methods B, C, D are called — are the calls to B, C, D logged?

sobes.tech AI

Answer from AI

If the bean method A with logging aspect is called from bean C, then the call to method A itself will be logged, as the aspect triggers on the public method A.

However, if private methods B, C, D are called within method A, these calls will not be automatically logged by the aspect if it is configured only for public methods and applied through proxies.

The reason is that calls to private methods within a class occur directly, bypassing the proxy, and aspects do not intercept internal method calls of the same class.

Therefore, to log calls to private methods, you need to either:

  • Make these methods public or protected and configure the aspect for them,
  • Or call them through a proxy,
  • Or add manual logging inside these methods.