@Aspect
public class MyAspect {
@Before("execution(* com.example.MyService.*(..))")
public void beforeAdvice() {
}
}
<aspectj>
<aspects>
<aspect name="com.example.MyAspect"/>
</aspects>
<weaver options="-verbose -showWeaveInfo">
<include within="com.example.*"/>
</weaver>
</aspectj>
import org.aspectj.bridge.*;
import org.aspectj.tools.*;
...
AspectJTools.createWeaver(new String[]{ "-verbose", "-showWeaveInfo", "-xmlConfigFile", "aop.xml" }).run()
@Component
public class MyService {
@Autowired
private MyDao myDao;
@MyCustomAnnotation
public void doSomething() {
}
}
<bean id="myService" class="com.example.MyService">
<property name="myDao" ref="myDao"/>
<aop:before method="doSomething" pointcut="execution(* com.example.MyService.*(..))"/>
<aop:advice id="myAspect" ref="myAspect">
<aop:before method="beforeAdvice" pointcut-ref="myPointcut"/>
</aop:advice>
</bean>