Spring AOP - Invoking advice from catch block

前端 未结 4 492
我在风中等你
我在风中等你 2020-12-19 16:26

Purpose: Send an email to admin every time an exception occurs while executing business logic.

Till now I have come across \"throwing advice\" which is fine and gets

4条回答
  •  無奈伤痛
    2020-12-19 16:36

    AFAIK there is no pointcut expression for this...

    You should consider configuring your logger to do what you need. Replace ae.printStackTrace(); by something like logger.warn(ae) (to print stacktraces to the console is quite bad practice anyways), and configure one of the email-sending appenders of your logging tool, e.g. log4j's or logback's SMTPAppender. Additionally, to make your configuration easier, you may use a business-dedicated logger.

    If you really want to use aspects here, I think you'll have to expect all your business exceptions to bubble up at least one method, in order to use afterThrowing advices.

提交回复
热议问题