spring 注解方式实现aop
2017-04-01 11:05
465 查看
spring xml配制
注解类
切面类
切面使用
<context:component-scan base-package="com.meizu.spring.controller,com.meizu.spring.service,com.meizu.spring.annotation_aop" > <context:include-filter type="annotation" expression="org.aspectj.lang.annotation.Aspect" /> </context:component-scan> <!-- Configures the @Controller programming model --> <!-- annotation-driven 扫描指定包中类上的注解 --> <mvc:annotation-driven /> <!-- 通过cblib去生成代理类 --> <aop:aspectj-autoproxy proxy-target-class="true"/>
注解类
@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface InfoAop { String name() default ""; }
切面类
@Aspect public class InfoAopIml { @Before("@annotation(infoAop)") public void before(InfoAop infoAop) throws Throwable { System.out.print("before"); } @Around("@annotation(infoAop)") public void around(ProceedingJoinPoint proceedingJoinPoint, InfoAop infoAop) throws Throwable { System.out.print("around before"); proceedingJoinPoint.proceed(); System.out.print("around after"); } @After("@annotation(infoAop)") public void after(InfoAop infoAop) throws Throwable { System.out.print("after"); } }
切面使用
@Service public class ServiceInfo { @InfoAop() public void info(){ System.out.print("info function"); } }
相关文章推荐
- 使用Spring的注解方式实现AOP
- Spring整理11 -- 面对切面(AOP)1 -- 注解配置的方式实现AOP
- spring学习笔记7--使用spring进行面向切面的(AOP)编程(1)注解方式实现
- Spring学习笔记(三)Spring注解方式实现AOP
- 使用spring注解方式实现AOP(一)
- (9) 使用Spring的注解方式实现AOP入门 以及 细节
- 使用Spring的注解方式实现AOP的细节
- SpringAOP拦截Controller,Service实现日志管理(自定义注解的方式)
- 使用Spring的注解方式实现AOP
- Spring_6_使用注解的方式实现AOP
- 使用Spring的注解方式实现AOP
- Spring学习笔记(14)----使用Spring的注解方式实现AOP
- 使用Spring的注解方式实现AOP
- Spring学习笔记(15)----使用Spring的注解方式实现AOP
- ITCAST视频-Spring学习笔记(使用Spring的注解方式实现AOP的细节)
- 用Spring配置文件或者注解方式实现AOP
- 第五章 Spring进阶-注解方式实现AOP(2)
- 第五章 Spring进阶-注解方式实现AOP(3)-全文完
- java SpringAOP拦截Controller,Service实现日志管理(自定义注解的方式)
- 使用Spring的注解方式实现AOP