2. Declare a slice
In spring AOP, which is based on an AOP namespace, to declare a slice, you need to use the child label <aop:aspect> of <aop:config/>. The <aop:aspect> label has a ref attribute that must be assigned to specify the managed bean (backing bean) associated with that section, and we will use the backing bean to address the bean later. As the following example shows, the Java class for the Bean is a normal Java class in which the notification method for the slice is defined. Additionally, the,<aop:aspect> label also has two optional order and ID attributes, which are used to specify the load sequence of the section, and the id attribute is used to identify the slice. Examples are as follows:
Code
<?xml version="1.0" encoding="UTF-8"?>
<beans ……>
<bean id="MyAspect" class="aop.test.MyAspect" />
<aop:config proxy-target-class="true">
<aop:aspect ref="MyAspect" order="1" id="TestAspectName">
……切面其他配置
</aop:aspect>
</aop:config>
……其他配置
</beans>
3. Declare an entry point
To declare a pointcut, you can use the <aop:pointcut> of <aop:aspect>, and in Spring2.5 it has two property IDs and expression, which are used to mark the Pointcut and set the pointcut expression. For example:
Code
<?xml version="1.0" encoding="UTF-8"?>
<beans ……>
<bean id="MyAspect" class="aop.test.MyAspect"/>
<aop:config proxy-target-class="true">
<aop:aspect ref="MyAspect" order="1" id=”TestAspectName”>
<aop:pointcut id="test"
expression="execution(* aop.test.TestBean.*(..))"/>
<aop:before pointcut="aop.test.MyAspect.Pointcut1()"
method="beforeAdvice" />
</aop:aspect>
</aop:config>
……其他配置
</beans>
The expression property of the Aop:pointcut> label uses the pointcut expression language described earlier, which means that the ASPECTJ pointcut expression is supported. But because the XML to "&&", "| |", "!" Such logical operators are unfriendly, and the logical operators that are used in @AspectJ pointcut expression languages need to be replaced with "and", "or" and "not" in the XML configuration, respectively.
Sometimes we also need to use the pointcut of the @pointcut annotation declaration in XML, so what? As you may recall, we can refer to another pointcut in the pointcut expression. Right, right here, we use this feature to accomplish this task as follows:
Code
<aop:pointcut id= "test" expression= "aop.test.MyAspect.Pointcut1 ()"/>
Note: Here we must use the full path to mark the referenced pointcut.