Spring的AOP的基于AspectJ的注解开发
创建项目,引入jar包
编写目标类、切面类
配置目标类、切面类
在注解文件里开启AOP的开发
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 注解形式开启AOP开发 --> <aop:aspectj-autoproxy /> <!-- 配置目标类 --> <bean id="orderDao" class="com.springaoc.demo1.OrderDao"></bean> <!-- 配置切面类 --> <bean id="myAspect" class="com.springaoc.demo1.MyAspectAnno"></bean> </beans>
编写测试类