Spring课程 Spring入门篇 5-2 配置切面aspect

课程链接:

本节主要讲了在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 {

}

 

转载于:https://www.cnblogs.com/1446358788-qq/p/10681023.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值