本次代码基于代码笔记中的Spring_AOP_Annotation修改,命名为Spring _AOP_XML
将LogInterceptor.java中的注释销掉,现在就成为了只有切面,但切面没有运行的状态。现在让我们来配置beans.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: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.xsd">
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="main.com"></context:component-scan>
<aop:config>
<aop:pointcut id="servicePointcut" expression="execution(public * main.com.ly.service..*.add(..))"></aop:pointcut>
<aop:aspect id="logAspect" ref="logInterceptor">
<aop:before method="before" pointcut-ref="servicePointcut"></aop:before>
</aop:aspect>
</aop:config>
</beans>