基于Schema-based配置的AOP实现
Spring所有的切面和通知器都必须放在<aop:config>内(可以配置多个<aop:config>元素),每一个<aop:config>可以包含aspect,pointcout和advisor元素(它们必须按照这个顺序进行声明)。
<aop:config>的配置大量使用了Spring的自动代理机制。
该配置的含义:一个类作为切面来声明,切面Id是myAspect,也就是说程序执行某个功能模块时,通过pointcut和Joinpoint执行该切面的功能。
案例:两个类,一个类作为切面类,另一个作为业务类。(注意:<beans>中添加约束,xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
)
代码:
<?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"
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-4.0.xsd">
<bean id="aspectImooc" class="aspect.AspectImooc"></bean>
<bean id="ServiceImooc" class="aspect.ServiceImooc"></bean>
<aop:config>
<aop:aspect id="aspectImoocAop" ref="aspectImooc"></aop:aspect>
</aop:config>
aspect例子
<aop:config>风格的配置大量使用了Spring的自动代理机制
Schema - based AOP
Spring所有的切面和通知器都必须放在一个<aop:config>内
(可以配置包含多个<aop:config>元素),每一个<aop:config>可以包含pointcut,advisor和aspect元素
(他们必须按照这个顺序进行声明)
5-2 配置切面aspect
基于Schema-based配置的AOP实现
Spring所有的切面和通知器都必须放在<aop:config>内(可以配置多个<aop:config>元素),每一个<aop:config>可以包含aspect,pointcout,advisor元素(它们必须按照这个顺序进行声明)。
<aop:config>的配置大量使用了Spring的自动代理机制。
该配置的含义:一个类作为切面来声明,切面Id是myAspect,也就是说程序执行某个功能模块时,通过pointcut和Joinpoint执行该切面的功能。
案例:两个类,一个类作为切面类,另一个作为业务类。(注意:<beans>中添加约束,xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
)
代码:
<?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"
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-4.0.xsd">
<bean id="aspectImooc" class="aspect.AspectImooc"></bean>
<bean id="ServiceImooc" class="aspect.ServiceImooc"></bean>
<aop:config>
<aop:aspect id="aspectImoocAop" ref="aspectImooc"></aop:aspect>
</aop:config>
基于Schema-based配置的AOP实现
Spring所有的切面和通知器都必须放在<aop:config>内(可以配置多个<aop:config>元素),每一个<aop:config>可以包含aspect,pointcout和advisor元素(它们必须按照这个顺序进行声明)。
<aop:config>的配置大量使用了Spring的自动代理机制。
该配置的含义:一个类作为切面来声明,切面Id是myAspect,也就是说程序执行某个功能模块时,通过pointcut和Joinpoint执行该切面的功能。
案例:两个类,一个类作为切面类,另一个作为业务类。(注意:<beans>中添加约束,xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
)
代码:
<?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"
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-4.0.xsd">
<bean id="aspectImooc" class="aspect.AspectImooc"></bean>
<bean id="ServiceImooc" class="aspect.ServiceImooc"></bean>
<aop:config>
<aop:aspect id="aspectImoocAop" ref="aspectImooc"></aop:aspect>
</aop:config>
AOP的aspect配置范例,在XML中配置,id为自定义id,ref为切面的bean的id
AOP声明规则一
注:这种风格的配置大量使用了Spring的自动代理机制
配置切面aspect
MoocAspect 切面类
AspectBiz 业务类
Schema--based AOP
Spring所有的切面和通知器都必须放在一个<aop:config>内
每一个<aop:config>可以包含pointcut,advisor和aspect元素(必须 按这个顺序进行声明)
<aop:config>风格的配置大量使用了Spring的自动代理机制
使用<aop:config>进行配置,按照一定顺序进行声明
AOP aspect配置
aspect
Spring——Schema-based AOP
Schema based AOP 基于配置的AOP使用
Spring所有的切面和通知器都必须放在一个<aop:config>内(可以配置多个<aop:config>元素),每一个<aop:config>可以包含pointcut,advisor,aspect元素(它们必须按照这个顺序进行声明)
=========
<aop:config>风格的配置大量使用了Spring的自动代理机制
<aop:config>
<aop:aspect id="myAspect" ref="aBean">
... //把aBean作为一个切面来声明,切面的id为myAspect
</aop:aspect>
</aop:config>
<bean id="aBean" class="..."></bean>
<aop:config>大量使用spring自动代理机制
aspect
放在<aop:config> 内,必须按照这个顺序进行声明
Schema--based AOP
Schema-based AOP
Schema——based AOP——2
<aop:config>
<aop:aspect id=
"myAspect"
ref=
"aBean"
>
......
</aop:aspect>
</aop:config>
配置切面aspect
配置切面aspect
配置切面aspect
Schema-based AOP:
aspect切面的配置