There are several places that need to be modified in this configuration file:
1. xmlns:aop=" http://www.springframework.org/schema/aop "
http://www.springframework.org/schema/aop
http:// www.springframework.org/schema/aop/spring-aop.xsd
2. The points that need to be understood in this
* connection points are the methods in all implementation classes
* core code: the code that must be executed in a program
* entry point: the point that needs to be emphasized
* notification/enhancement point : Pre-notification and post-notification
* Entry surface: When the notification point/enhancement point and the entry point are combined, it becomes the entry surface, that is, the enhanced part.
<?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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!--
AOP
1、目标类
2、增强类
3、织入
-->
<!-- 目标类 -->
<bean id="bocDao" class="com.whpu.k16035.aop.dao.impl.BOcDaoImpl"></bean>
<!--增强类 -->
<bean id="security" class="com.whpu.k16035.aop.security.Security"></bean>
<bean id="logger" class="com.whpu.k16035.aop.log.Logger"></bean>
<bean id="cc" class="com.whpu.k16035.aop.cache.ClearCache"></bean>
<!--aop织入-->
<aop:config>
<!--配置切入点 要被增强的方法
id:切入点的名称
expression : 切入点表达式
-->
<aop:pointcut id="pointCut" expression="execution(* com.whpu.k16035.aop.dao.impl.*.*(..) )"></aop:pointcut>
<!--切面
前置切面中:
ref:引入增强类/通知类
order:前置通知,值越小越先执行
后置通知,值越大越先执行
-->
<!--配置安全模块切面-->
<aop:aspect ref="security" order="1">
<!--前面通知-->
<aop:before method="isSecurity" pointcut-ref="pointCut"></aop:before>
</aop:aspect>
<!--配置日志管理模块切面-->
<aop:aspect ref="logger" order="2">
<!--后置通知-->
<aop:after method="log" pointcut-ref="pointCut"></aop:after>
</aop:aspect>
<!--配置缓存管理模块切面-->
<aop:aspect ref="cc" order="1">
<!--后置通知-->
<aop:after method="clear" pointcut-ref="pointCut"></aop:after>
</aop:aspect>
</aop:config>
</beans>
test code
@Test
public void proxyAopTest(){
//动态代理
ApplicationContext app = new ClassPathXmlApplicationContext("aop/beans_aop..xml");
BOcDao bOcDao = (BOcDao)app.getBean("bocDao");
bOcDao.select();
}