有没有办法创建自定义或使用现有注释来在调用带注释的方法时触发代码运行?最好,我想使用 Spring 库。
例如:
@SendEmail("templateName")
public void doSomething() {
log.info("Something is happening");
}
public void sendEmail(String templateName) {
// This method is called everytime doSomething() is called
log.info("Sending email using template " + templateName);
}
@Component
@Aspect
public class Mail {
@After("execution (@com.yourdirectoryofyourcustomAnnotation.SendMail * *(..))")
public void sendEmail(JointPoint jp){
// it will send a mail after every method which tagged by your annotation
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)