0

我正在构建一个 Spring Web 应用程序。使用 Spring AOP 的切面做审计日志。

我有如下方法的商务舱,我想在某些情况下审核日志

  • 在方法执行期间
  • 方法返回后

    @Aspect  
    public class MyBusinessClass {...
    
    public void registerUser() {  
           // do some business logic here...  
          userId = // userService.saveUser(...).getId(); // etc...  
          if(successful) {  
              // then send Email notification  
             audit.log(userId, "success sending email notification"... some other params);  
          else {
              audit.log(userId, "fail to send email notification"...);  
          }  
          //do some more logic before returning method  
          audit.log(userId,"successfully registered user...." ...);  
          ..// method returns   
          }
    

我已经在一个单独的类中定义了 Aspects。

我遇到了问题,因为我在这里和其他文章中看到的所有常见简单示例似乎都非常简单。例如,它们很容易工作,因为我见过的最复杂的只是将方法参数提取到方面的建议中。

但我的问题是,我不想以某种方式不仅将局部变量提取到 Aspect 的建议中,而且还要根据某些条件多次进行审计日志记录。

不要误会我的意思,我们已经让 Log4j 日志记录到相同位置的文件,但我们也需要将这些审计日志记录到数据库。

我只想知道什么是解决方案来实现我想要在高水平上做的事情。

对代码格式稍差的道歉......(主要是伪代码)。我只是无法让这种代码格式在 StackOverflow 上工作。在 Github markdown 上要容易得多。

4

0 回答 0