I have declared the following Aspect which advices a dao call, I'm trying to run @Before advice but its not working.
Here goes the aspect.
package com.hedgebenefits.aop;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class AccessControlAspect {
@Before("within(com.hedgebenefits.daos..*) && execution(public * *(..))")
public void daoCall() {
System.out.println("Before advice invoked for DAO method called ");
}
}
My application-context.xml has the following tag
<aop:aspectj-autoproxy/>
My Dao class is as follows:
package com.hedgebenefits.daos.impl;
import com.hedgebenefits.daos.AdminDao;
import com.hedgebenefits.domain.Admin;
import org.springframework.stereotype.Repository;
@Repository
public class AdminDaoImpl implements AdminDao{
@Override
public void save(Admin admin) {
}
}
I put a breakpoint but I can see that its not active, I'm definitely doing some silly mistake here but can't figure out. Pl. advice.
Your aspect needs to be a part of your application context.
component-scan
, either add @Component
to your AccessControllerAspect
, or setup the component-scan
filters to include @Aspect
annotations. To setup the filters, take a look at section 3.10.3 of the Spring documentation (Using filters to customize scanning).AccessControllerAspect
.The act of adding aop:aspectj-autoproxy
is not enough. This tells beans that are already a part of your application context how to do the aspecting, it does not automatically include them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With