当前位置: 首页 > news >正文

什么样的网站利于优化银川网站制作公司

什么样的网站利于优化,银川网站制作公司,东莞专业网站建设公司,潮州网络推广公司一、什么是AOP?在不修改源代码的情况下 增加功能二、底层是什么?动态代理aop是IOC的一个扩展功能,现有IOC,再有AOP,只是在IOC的整个流程中新增的一个扩展点而已:BeanPostProcessorbean的创建过程中有一个步…

一、什么是AOP?

在不修改源代码的情况下 增加功能

二、底层是什么?

动态代理

aop是IOC的一个扩展功能,现有IOC,再有AOP,只是在IOC的整个流程中新增的一个扩展点而已:BeanPostProcessor

bean的创建过程中有一个步骤可以对bean进行扩展实现,AOP本身就是一个扩展功能,所以BeanPostProcessor的后置处理方法来进行实现

三、术语

①、连接点

在一个类里面哪些方法可以被增强,这些方法就称为连接点

②、切入点

实际被真正增强的方法,称为切入点

③、通知(增强)

实际增强的逻辑部分称为通知(增强)

通知有多种类型

  • 前置通知

  • 后置通知

  • 环绕通知

  • 异常通知

  • 最终通知

④、切面

把通知应用到切入点的过程


四、AOP操作

Spring框架一般都是基于AspectJ实现AOP操作

什么是AspectJ?

不是Spring组成部分,独立AOP框架,一般把AspectJ和Spring框架一起使用,进行AOP操作

基于AspectJ实现AOP操作

  1. 基于xml配置方式

  1. 基于注解方式

一、注解方式

引入AOP依赖

开启注解扫描

开启Aspect生成代理对象

User类

package com.atguigu.spring5.AOP;import org.springframework.stereotype.Component;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.AOP* @Author: dengLiMei* @CreateTime: 2023-02-11  19:54* @Description: TODO* @Version: 1.0*/
//被增强类
@Component
public class User {public void add() {System.out.println("add……");}
}

UserProxy类

package com.atguigu.spring5.AOP;import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.AOP* @Author: dengLiMei* @CreateTime: 2023-02-11  19:55* @Description: TODO* @Version: 1.0*/
//增强的类
@Component
@Aspect   //生成代理对象
public class UserProxy {//前置通知//@Before注解表示作为前置通知@Before(value = "execution(* com.atguigu.spring5.AOP.User.add())")public void before() {System.out.println("before.....");}//最终通知:方法之后就执行;有异常也执行@After(value = "execution(* com.atguigu.spring5.AOP.User.add())")public void After() {System.out.println("After.....");}//后置通知(返回通知):在返回结果之后执行:有异常不执行@AfterReturning(value = "execution(* com.atguigu.spring5.AOP.User.add())")public void AfterReturning() {System.out.println("AfterReturning.....");}//异常通知:有异常了才执行,没异常不执行@AfterThrowing(value = "execution(* com.atguigu.spring5.AOP.User.add())")public void AfterThrowing() {System.out.println("AfterThrowing.....");}//环绕通知//表示在方法之前和方法之后都执行@Around(value = "execution(* com.atguigu.spring5.AOP.User.add())")public void Around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {System.out.println("环绕之前.....");//被增强的方法执行proceedingJoinPoint.proceed();System.out.println("环绕之后.....");}
}

Main类

package com.atguigu.spring5.AOP;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.AOP* @Author: dengLiMei* @CreateTime: 2023-02-11  20:05* @Description: TODO* @Version: 1.0*/
public class Main {public static void main(String[] args) {ApplicationContext context = new ClassPathXmlApplicationContext("aopbean.xml");User user = context.getBean("user", User.class);user.add();}
}

输出结果:

问题:对指定类的指定方法做增强

解决:对相同切入点进行抽取

PersonProxy类

在上面例子基础上增加一个新类

package com.atguigu.spring5.AOP;import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.AOP* @Author: dengLiMei* @CreateTime: 2023-02-11  20:21* @Description: TODO* @Version: 1.0*/
@Component
@Aspect
@Order(1)
public class PersonProxy {//后置通知(返回通知)@Before(value = "execution(* com.atguigu.spring5.AOP.User.add(..))")public void afterReturning(){System.out.println("Person Before……");}
}

输出结果:

有多个增强类对同一个方法进行增强,设置增强类优先级

在增强类上面增加注解@Order(数字类型值),数字类型值越小优先级越高

二、AspectJ配置方式

创建对象

配置aop增强

切入点

配置切面

Book类

package com.atguigu.spring5.AOP.AOPConfigue;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.AOP.AOPConfigue* @Author: dengLiMei* @CreateTime: 2023-02-11  20:38* @Description: TODO* @Version: 1.0*/
public class Book {public void buy(){System.out.println("买");}
}

BookProxy类

package com.atguigu.spring5.AOP.AOPConfigue;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.AOP.AOPConfigue* @Author: dengLiMei* @CreateTime: 2023-02-11  20:40* @Description: TODO* @Version: 1.0*/
public class BookProxy {public void before(){System.out.println("before……");}
}

Main类

package com.atguigu.spring5.AOP.AOPConfigue;import com.atguigu.spring5.AOP.AOPAnnotation.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;/*** @BelongsProject: 02-Spring* @BelongsPackage: com.atguigu.spring5.AOP.AOPConfigue* @Author: dengLiMei* @CreateTime: 2023-02-11  20:44* @Description: TODO* @Version: 1.0*/
public class Main {public static void main(String[] args) {ApplicationContext context = new ClassPathXmlApplicationContext("aopbean2.xml");Book book = context.getBean("book", Book.class);book.buy();}
}

输出结果:


Spring系列文章:

Spring——是什么?作用?内容?用到的设计模式?

Spring——Bean管理-xml方式进行属性注入

Spring——Bean管理-注解方式进行属性注入

Spring——什么是IOC?

Spring——AOP是什么?如何使用?

Spring——什么是事务?传播行为?事务隔离级别有哪些?

Spring——整合junit4、junit5使用方法

如果有想要交流的内容欢迎在评论区进行留言,如果这篇文档受到了您的喜欢那就留下你点赞+收藏脚印支持一下博主~

http://www.yayakq.cn/news/769962/

相关文章:

  • 萍乡网站seo门户网站开发报价
  • 二手房中介网站建设网站首页大图素材
  • 天津建设注册执业中心网站上海川沙网站建设
  • 站点地址和wordpress区别自助外贸英文网站建设
  • 三亚住房和城乡建设厅网站常德网站建设企业
  • 广西响应式网站制作浙江省城乡建设厅官网
  • 网站建设三剑客双峰做网站
  • 宁波网站建设模板下载免费南昌网站建设公司价位
  • asp.net网站的数据库配置wordpress的开发框架
  • 网站编排页面网站开发后期维护更新
  • 类似k站的网站7c框架 网站建设
  • 天津圣辉友联网站建设seo的工具有哪些
  • 一浪网站建设局域网
  • 网站功能定制合同一条视频可以多平台发布吗
  • 自建网站访问报错衡水市网站建设
  • 小伙做钓鱼网站 背警方带走长沙网站建设王道下拉惠
  • 贵州省住房与城乡建设部网站域名备案和网站备案的区别
  • 河北世达建设集团有限公司网站数据分析师前景
  • 浙江省建设投资集团有限公司网站wordpress标签是什么
  • 建设公司需要网站吗企业网站程序
  • 北京网站建设公司现状wordpress去除顶部工具栏
  • 文字壁纸做背景处理的网站网站建设地图怎么设置
  • 学校网站建设的安全策略硬件开发属于什么行业
  • 手表网站域名网站页面制作视频
  • 可信赖的武进网站建设制作网站电话
  • 佛山p2p网站建设重庆住房城乡建设厅官方网站
  • 零食网站色调搭配怎么做做网站多少钱特惠西宁君博s
  • 网站要交钱吗安卓app用什么开发
  • 网站免费软件阿里主机 wordpress
  • 低成本做网站 百知电影网站开发api