AspectJ之Advice定义之Before Advice
2016-12-08 09:26
239 查看
1、Before Advice:
示例步骤如下:
1、配置文件如下:
2、定义切面类:
3、定义业务类:
4、测试类:
示例步骤如下:
1、配置文件如下:
<context:component-scan base-package="com.wuyonghu" /> //这里的aop:aspectj-autoproxy标签必须有,否则无效,相当于是aspectj的自动代理 <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
2、定义切面类:
package com.wuyonghu.aspectj; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.springframework.stereotype.Component; @Component("aspect") @Aspect public class MoocAspect { @Before("execution(* com.wuyonghu.aspectj.AspectjBiz.*(..))") public void before(){ System.out.println("切面类中的before方法执行了。。。"); } }
3、定义业务类:
package com.wuyonghu.aspectj; import org.springframework.stereotype.Service; @Service public class AspectjBiz { public String save(String arg){ System.out.println("AspectBiz中的save方法执行了"); return "success"; } }
4、测试类:
package com.wuyonghu.aspectj; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.BlockJUnit4ClassRunner; import org.springframework.context.support.ClassPathXmlApplicationContext; @RunWith(BlockJUnit4ClassRunner.class) public class AspectjTest { @Test public void test1() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); AspectjBiz biz=(AspectjBiz) context.getBean("aspectjBiz"); biz.save("海賊王"); } }
相关文章推荐
- AspectJ之Advice定义之Around advice
- AspectJ之Advice定义之After returning advice
- AspectJ之Advice定义之After throwing advice
- AspectJ之Advice定义之finally advice
- 跟我学aspectj之九----- advice
- Spring AOP中定义切点(PointCut)和通知(Advice)
- 19Spring_AOP编程(AspectJ)_使用@Pointcut注解来定义切点
- Spring2.0 AOP @AspectJ注解定义切面学习示例。
- AspectJ学习笔记之Advice
- Spring定义事物通知tx:advice
- 学习记录 - Advice定义以及实例
- Aspectj切入点语法定义
- aspectj的切入点语法定义细节
- Aspectj切入点语法定义
- 顾问(Advisor),通知 advice ,注解Aspectj
- 使用@ControllerAdvice和@ExceptionHandler定义全局捕获异常
- Spring 【Aspectj】【注解】定义切入点(重用)
- AspectJ切点语法定义
- @Controller @ResponseBody @ControllerAdvice @RestController @RestControllerAdvice 注解定义
- AspectJ-基于注解的实现-切入点的定义