首页
统计
关于
Search
1
Sealos3.0离线部署K8s集群
1,082 阅读
2
类的加载
741 阅读
3
Spring Cloud OAuth2.0
726 阅读
4
SpringBoot自动装配原理
691 阅读
5
集合不安全问题
584 阅读
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
登录
Search
标签搜索
Java
CSS
mysql
RabbitMQ
JavaScript
Redis
JVM
Mybatis-Plus
Camunda
多线程
CSS3
Python
Spring Cloud
注解和反射
Activiti
工作流
SpringBoot
Mybatis
Spring
html5
蘇阿細
累计撰写
388
篇文章
累计收到
4
条评论
首页
栏目
笔记
Java
多线程
注解和反射
JVM
JUC
设计模式
Mybatis
Spring
SpringMVC
SpringBoot
MyBatis-Plus
Elastic Search
微服务
Dubbo
Zookeeper
SpringCloud
Nacos
Sentinel
数据库
MySQL
Oracle
PostgreSQL
Redis
MongoDB
工作流
Activiti7
Camunda
消息队列
RabbitMQ
前端
HTML5
CSS
CSS3
JavaScript
jQuery
Vue2
Vue3
Linux
容器
Docker
Kubernetes
Python
页面
统计
关于
搜索到
1
篇与
的结果
2020-12-16
AOP
AOPAOP(Aspect Oriented Programing),面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术。AOP是OOP的延续,利用AOP可以对业务逻辑的各个部分进行隔离,从而使业务逻辑各部分之间的耦合降低,提高程序的可重用性。1、Aop在Spring中的作用==提供声明式事务;允许用户自定义切面==横切关注点:跨越应用程序多个模块的方法或功能,即:与业务逻辑无关,但需要关注的部分就是横切关注点,如:日志、缓存、事务等切面(Aspect):横切关注点被模块化的都特殊对象,具体为一个类通知(Advice):切面必须要完成的工作,类中的一个方法目标(Target):被通知对象代理(Proxy):向目标对象应用通知之后创建的对象切入点(PointCut):需要执行切面通知的”地点“连接点(JoinPoint):与切入点匹配的执行点在SpringAop中,通过Advice定义横切逻辑,Spring中支持5中类型的Advice:通知类型连接点实现接口前置通知方法前org.springframework.aop.MethodBeforeAdvice后置通知方法后org.springframework.aop.AfterReturningAdvice环绕通知方法前后org.springframework.aop.MethodInterceptor异常抛出通知方法抛出异常org.springframework.aop.ThrowsAdvice引介通知类中增加新的方法属性org.springframework.aop.IntroductionInterceptor2、使用Spring实现AOP在pom.xml中导入依赖<dependencies> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.9.4</version> </dependency> </dependencies>3、使用Spring实现Aop方式一:使用Spring的API接口方式二:自定义实现AOP【定义切面】方式三:使用注解<?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" xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd"> <!--注册bean--> <bean id="userService" class="com.sw.service.UserServiceImpl"/> <bean id="log" class="com.sw.log.Log"/> <bean id="afterLog" class="com.sw.log.AfterLog"/> <!--方式一:使用原生Spring API配置--> <!--配置aop:需导入AOP约束--> <aop:config> <!--切入点:execution(要执行的位置)--> <aop:pointcut id="pointcut" expression="execution(* com.sw.service.UserServiceImpl.*(..))"/> <!--执行环绕增强--> <aop:advisor advice-ref="log" pointcut-ref="pointcut"/> <aop:advisor advice-ref="afterLog" pointcut-ref="pointcut"/> </aop:config> <!--方式二:自定义--> <bean id="diy" class="com.sw.diy.DiyLog"/> <aop:config> <!--自定义切面,ref:要引用的类--> <aop:aspect ref="diy"> <!--切入点--> <aop:pointcut id="pointcut" expression="execution(* com.sw.service.UserServiceImpl.*(..))"/> <!--通知--> <aop:before method="before" pointcut-ref="pointcut"/> <aop:after method="after" pointcut-ref="pointcut"/> </aop:aspect> </aop:config> <!--方式三:通过注解--> <bean id="annotationPointCut" class="com.sw.diy.AnnotationPointCut"/> <!--开启注解 JDK:expose-proxy="false"(默认) cglib:expose-proxy="true" --> <aop:aspectj-autoproxy /> </beans>
2020年12月16日
182 阅读
0 评论
0 点赞