使用xml的方式配置aop
需要在xml文件头添加命名空间
xmlns:aop="http://www.springframework.org/schema/aop"
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd"
有些麻烦
<bean id="logUtilg" class="com.mashibing.util.LogUtil"></bean>
<bean id="securityUtil" class="com.mashibing.util.SecurityUtil"></bean>
<bean id="mycalculator" class="com.mashibing.service.Mycalculator"></bean>
<!--设置aop的xml配置方法-->
<aop:config>
<!--抽象表达式-->
<aop:pointcut id="mycal" expression="execution(public * com..*(..))"></aop:pointcut>
<!--设置切面 ,关联bean -->
<aop:aspect ref="logUtilg">
<!--设置通知-->
<aop:before method="start" pointcut="execution(Integer com..*(..))"></aop:before>
<aop:after-returning method="stop" pointcut="execution(* com..*(..))" returning="result"></aop:after-returning>
<aop:after method="logFinally" pointcut="execution(Integer com.mashibing.service.Mycalculator.*(..))" ></aop:after>
<aop:after-throwing method="logException" pointcut="execution(* com..*(..))" throwing="e"></aop:after-throwing>
<aop:around method="around" pointcut="execution(* com..*(..))" ></aop:around>
</aop:aspect>
<aop:aspect ref="securityUtil">
<aop:after method="logFinally" pointcut-ref="mycal"></aop:after>
<aop:after-throwing method="logException" pointcut-ref="mycal" throwing="e"></aop:after-throwing>
<aop:before method="start" pointcut-ref="mycal"></aop:before>
<aop:after-returning method="stop" pointcut-ref="mycal" returning="result"></aop:after-returning>
</aop:aspect>
</aop:config>