Announcement Announcement Module
No announcement yet.
Need help in @Around advise Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help in @Around advise

    I wrote one @Around advise like following

    HTML Code:
    @Around("execution(* com.virtusa.base.dao.*.*(..)) && @annotation(logAction)" + "args(logAction)")
    	public Object logAuditTrail(ProceedingJoinPoint runtimeInstance, AuditTrailInterface logAction) throws Throwable {
    		LOGGER.debug("Inside logAuditTrail method ....");
    		// Action performed in DAO level
    		String actionPerformed = DataAccessFactory.getOperationsMap().get(logAction.logAuditTrail());
    		// join point arguments
    		for (Object object : runtimeInstance.getArgs()) {
    			com.virtusa.domainobjects.AuditTrail auditTrail = new com.virtusa.domainobjects.AuditTrail();
    			auditTrail.setAction(object.toString() + actionPerformed);
    			auditTrail.setTimestamp(new Timestamp(Calendar.getInstance().getTime().getTime()));
    			LOGGER.debug("INSERT INTO AUDIT TRAIL: " + object.toString() + actionPerformed);
    		LOGGER.debug("End logAuditTrail method ....");
    		return runtimeInstance.proceed();
    I have a EmployeeDAOImpl which extends an abstract Base DAO class, following is the Base DAO class which include a method to insert a record in to database ("public int create(final T domainObject)").

    In addition, public int create(final T domainObject) method is a Transactional enabled and I defined an annotation interface @AuditTrailInterface(logAuditTrail = "create") to log an audit trail in to database

    HTML Code:
    public abstract class BaseDaoImpl<T extends Entity> implements BaseDao<T> {
    	/** Holds the Logger object for logging. */
    	private static final Logger LOGGER = Logger.getLogger(BaseDaoImpl.class);
    	/** Holds Session Factory. */
    	protected SessionFactory sessionFactory;
    	 * @param sessionFactory
    	 *            the sessionFactory to set
    	public void setSessionFactory(SessionFactory sessionFactory) {
    		this.sessionFactory = sessionFactory;
    	 * Method to insert domain specific objects.
    	 * @param domainObject
    	 *            - Entity type instance.
    	 * @return generated domain id.
    	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackForClassName = "DataAccessException")
            @AuditTrailInterface(logAuditTrail = "create")
    	public int create(final T domainObject) {
    		LOGGER.debug("New " + ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0] + " type object created with id " + domainObject.getId());
    		return domainObject.getId();
    On the other hand, Employee DAO Impl class will be like following:

    HTML Code:
    public class EmployeeDaoImpl extends BaseDaoImpl<Employee> implements IEmployeeDao {
    	 * (non-Javadoc)
    	 * @see com.virtusa.base.dao.BaseDaoImpl#create(com.virtusa.domainobjects.Entity)
    	public int createEmployee(final Employee domainObject) {
    		return create(domainObject);
    Furthermore, @AuditTrailInterface interface implementation like following:

    HTML Code:
    public @interface AuditTrailInterface {
    	public String logAuditTrail();
    My Questions is if I defined my interceptor @AuditTrailInterface(logAuditTrail = "create") inside BaseDAOImpl it is not working as expected. However if I include it in my EmployeeDAOImp it is working fine.

    I appreciate if someone can advise me on this ?

  • #2
    Self class are not intercepted by Spring AOP. I am assuming that call to super class methods will be considered as self call.


    • #3
      That means, during the runtime it will create a proxy for only EmployeeDAOImpl class ? But if I add a @Before advise it is working for me.

      If we consider this scenario do you think is there any difference between @Around and @Before ?


      • #4
        There isn't and the Before advice shouldn't work either if it works you defined either a different pointcut or your annotation is on the other method. Due to proxy based aop internal method calls will not be intercepted, this is a limitation of proxy based aop (which exists already since the days of EJB 1.0).


        • #5
          Thanks for your advise...

          I went through the "8.6.1 Understanding AOP proxies" reference provided in Spring documentation.