课程链接:

本节主要讲了在xml中配置切面的demo

1    解析

1.1  配置切面xml

1.2  运用什么原理

 

2    代码演练

2.1  配置切面xml

 

 

 

1    解析

1.1  配置切面xml

spring的所有切面和通知器必须放在一个<aop:config>内(可以配置多个<aop:config>元素),每一个<aop:config>可以包含point、advisor和aspect元素(必须按照顺序声明)

 

1.2  运用什么原理?

<aop:config> 使用了Spring的自动代理机制

 

2    代码演练

2.1  配置切面xml

xml配置:

<?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-4.0.xsd">


<bean id = "logAspect" class = "com.imooc.aop.schema.advice.MoocAspect"></bean>
<bean id = "AspectBiz" class = "com.imooc.aop.schema.advice.biz.AspectBiz"></bean>

<aop:config>
    <aop:aspect  id="moocAspectAOP" ref="logAspect"></aop:aspect>
</aop:config>

</beans>

 

切面类:

package com.imooc.aop.schema.advice;

public class MoocAspect {

}

 

目标对象类:

package com.imooc.aop.schema.advice.biz;

public class AspectBiz {

}

 

posted on 2019-04-10 05:50  菜鸟乙  阅读(506)  评论(0编辑  收藏  举报