自定义注解

来源:互联网 发布:ubuntu maven m2 编辑:程序博客网 时间:2024/04/30 03:20

注解:

@Target({java.lang.annotation.ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Job {<span style="white-space:pre"></span>String jobName();}

业务实现:

@Aspect @Component public class MonitorAspect {//后置通知,当目标方法执行成功后执行该方法体      @AfterReturning("within(com.test..*) && @annotation(jm)")      public void jobMonitorSuccess(JoinPoint jp, Job jm){  <pre name="code" class="java"><span style="white-space:pre"></span>System.out.println(String.format("成功执行 %s", jm.jobName()));
} @AfterThrowing(pointcut="within(com.test..*) && @annotation(jm)", throwing="ex") public void jobMonitorFial(JoinPoint jp, JobMonitor jm, Exception ex){ System.out.println(String.format("异常啦 %s", jm.jobName())); }}


配置切入:

<aop:aspectj-autoproxy/>  


0 0