标签:utf-8 types version rgs oca framework 注解 增加 inter
没有不会做的事,只有不想做的事。
在Java配置中我们借助AspectJde @DeclareParents注解为被通知的方法引入新的方法,在XML中我们可以使用Spring aop命名空间的
<aop:declare-parents>元素。
<?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" xmlns:c="http://www.springframework.org/schema/c" xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd 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-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd"> <bean id="audience" class="chapter4.practice1.Audience"/> <aop:config> <!-- 声明切面 --> <aop:aspect ref="audience"> <!-- 定义切点 --> <aop:pointcut expression="executionexecution(** chapter4.practice1.Performance.perform(..))"
id="performance"/> <!-- 定义前置通知 --> <aop:before pointcut-ref="performance" method="perform"/> <!-- 定义返回通知 --> <aop:after-returning pointcut-ref="performance" method="performReturn"/> <!-- 定义异常通知 --> <aop:after-throwing pointcut-ref="performance" method="performThrowing"/> <!-- 定义环绕通知 --> <aop:around pointcut-ref="performance" method="aroundPerformance"/> <!-- 定义一个存在参数的切点,为通知传参数 --> <aop:pointcut expression="executionexecution(** chapter4.practice1.Performance.play(String)) and
args(gameName)" id="game"/> <!-- 为audience引入新的功能 --> <aop:declare-parents types-matching="chapter4.practice1.Audience+"
implement-interface="chapter4.practice2.EnableFly" default-impl="chapter4.practice2.EnableFlyIntroducer"/> </aop:aspect> </aop:config> </beans>
<aop:declare-parents>元素声明了切面所统治的bean要在它的对象层次结构中拥有新的父类型,即类型匹配types-matching属性的那些bean在父类的结构中会增加implement-interface属性指定的接口,而default-impl指定了默认实现该接口的类或通过delegate-ref属性指定具体实现的bean ID。
标签:utf-8 types version rgs oca framework 注解 增加 inter
原文地址:https://www.cnblogs.com/dandelZH/p/8964739.html