JAVA全系列 教程
3762个小节阅读:7094.3k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
环绕通知可以实现前置通知和后置通知两种功能。
新建com.bjsxt.advice.MyAround。
MethodInterceptor接口中必须重写invoke方法,方法中参数:
xxxxxxxxxx
package com.bjsxt.advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
public class MyAround implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
System.out.println("环绕通知-前置增强");
Object result = invocation.proceed();// 执行切入点
System.out.println("环绕通知-后置增强");
return result;
}
}
xxxxxxxxxx
<?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
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd">
<context:component-scan base-package="com.bjsxt.mapper,com.bjsxt.service.impl"></context:component-scan>
<bean id="mybefore" class="com.bjsxt.advice.MyBefore"></bean>
<bean id="myafter" class="com.bjsxt.advice.MyAfter"></bean>
<!-- 配置环绕通知bean -->
<bean id="myaround" class="com.bjsxt.advice.MyAround"></bean>
<aop:config>
<aop:pointcut id="mypoint" expression="execution(* com.bjsxt.service.impl.PeopleServiceImpl.test())"/>
<!-- 只织入环绕,没有织入前置通知和后置通知。 -->
<aop:advisor advice-ref="myaround" pointcut-ref="mypoint"></aop:advisor>
</aop:config>
</beans>