title: How to implement Aspect on Spring crud repository methods
body: <p>I'm doing a project in which we have lot of entities on which we will be doing CRUD operations. I have created a base entity class and in all the other entities i have extended the base entity class which is having common fields like created_date, created_by, last_updated_date, last_updated_by etc. Now, i want to implement aspect on Spring CrudRepository methods and set the above mentioned fields while saving.</p>
  
  <p>I've tried implementing something like this but not working.</p>
  
  <pre><code>package com.cerium.aop;
  
  import java.util.Date;
  
  import org.aspectj.lang.ProceedingJoinPoint;
  import org.aspectj.lang.annotation.Around;
  import org.aspectj.lang.annotation.Aspect;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.stereotype.Component;
  
  import com.cerium.datamodel.AccountDataModel;
  import com.cerium.domain.Account;
  import com.cerium.domain.BaseEntity;
  import com.cerium.util.Constants;
  
  /**
   * @author Manikanta B Cerium
   *
   */
  @Component
  @Aspect
  public class SampleAspect {
  
      private static final Logger LOG = LoggerFactory.getLogger(SampleAspect.class);
  
      @Around("execution(* com.cerium.repository.*.save (com.cerium.domain.BaseEntity)) &amp;&amp; args(saveData)")
      public Object beforeSave(ProceedingJoinPoint proceedingJoinPoint, Object saveData) throws Throwable {
  
          LOG.debug("Into aspect before save: {}", saveData);
  
          BaseEntity baseEntity = (BaseEntity) proceedingJoinPoint.proceed(new Object[] { saveData });
  
          // set the fields here......
          baseEntity.setCreatedDate(new Date());
  
          System.out.println(saveData);
  
          return baseEntity;
  
      }
  }
  </code></pre>