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

红色网站建设的比较好的高校公司简介优秀文案

红色网站建设的比较好的高校,公司简介优秀文案,深圳网站定制建设,淘客做网站多少钱基于xml配置的AOP xml方式AOP快速入门 在前面我们自己编写的AOP基础代码还存在一些问题#xff0c;主要是 被增强的范围写死了通知对象的方法在代码中写死了具体文章传送:Spring的AOP开发-AOP简介-CSDN博客 我们可以通过配置文件解决上述问题 配置增强的范围#xff08;配…基于xml配置的AOP xml方式AOP快速入门 在前面我们自己编写的AOP基础代码还存在一些问题主要是 被增强的范围写死了通知对象的方法在代码中写死了具体文章传送:Spring的AOP开发-AOP简介-CSDN博客   我们可以通过配置文件解决上述问题 配置增强的范围配置目标对象---切点表达式配置目标对象被哪些通知方法所增强以及执行的顺序配置文件的设计配置文件注解的解析工作Spring已经帮我们封装好了。在java web中设计到一些该知识点具体文章参照内容管理-CSDN创作中心其中AOP相关知识点。 xml方式配置AOP的步骤 导入AOP相关坐标 dependencygroupIdorg.aspectj/groupIdartifactIdaspectjweaver/artifactIdversion1.9.19/version/dependency 准备目标类、增强类、并配置给Spring管理 还是参考往期文章我是用的是注解的方式只需要在配置文件中设置组件扫描的范围即可。Spring的AOP开发-AOP简介-CSDN博客配置切点表达式哪些方法被增强配置织入切点被哪些通知方法增强是前置增强还是后置增强 运行测试类 package com.example.Test;import com.example.Service.UserService; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestMyAOP {public static void main(String[] args) {ApplicationContext applicationContext new ClassPathXmlApplicationContext(applicationContext.xml);UserService userService applicationContext.getBean(UserService.class);userService.show1();} }运行结果如下 xml方式AOP配置详解 xml配置AOP还是很简单的具体细节如下 切点表达式的配置方式切点表达式的配置语法 execution[访问修饰符] 返回类型 包名.类名.方法名参数访问修饰符可以省略不写返回值类型、某一级包名、类名、方法名可以使用表示*表示任意包名与类名之间使用单点.表示该包下的类使用双点..表示该包及其子包下的类参数列表可以使用两个点..表示任意参数也可以参考java web专栏往期文章AOP进阶-切入点表达式-execution-CSDN博客通知类型 AspectJ的通知由以下通知类型 通知类型描述Before在目标方法执行之前执行的通知用于进行准备工作或检查After在目标方法执行之后执行的通知用于进行清理工作或资源释放最终都会执行AfterReturning在目标方法正常执行并返回结果后执行的通知用于处理返回值或记录结果目标方法异常时不再执行AfterThrowing在目标方法抛出异常后执行的通知用于捕获和处理异常Around在目标方法执行前后都可以执行的通知用于包裹目标方法的执行过程、控制和干预目标方法异常时环绕后方法不再执行StaticInitialization静态初始化代码块的通知当类被加载时执行Initialization对象初始化代码块的通知当对象被创建时执行FieldGet字段读取操作的通知当访问字段时执行FieldSet字段赋值操作的通知当修改字段值时执行MethodExecution方法执行的通知包括Before、After、AfterReturning和AfterThrowing等通知的集合参考文章AOP进阶-通知类型-CSDN博客在该文章中使用的是注解方式来配置AOP。以下是通过xml方式来配置AOP前5种通知方式的代码示例 5种通知方法         package com.example.advice;import org.aspectj.lang.ProceedingJoinPoint;// 自定义增强类内部提供增强方法 public class MyAdvice {// todo 前置通知public void beforeAdvice() {System.out.println(前置通知);}// todo 后置通知public void afterAdvice() {System.out.println(后置通知);}// todo 环绕通知public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {// 前置通知System.out.println(环绕通知:前置通知);Object res proceedingJoinPoint.proceed(); // 执行目标方法System.out.println(环绕通知中目标方法执行了);// 后置通知System.out.println(环绕通知:后置通知);return res;}// todo 异常通知public void afterThrowingAdvice() {System.out.println(异常抛出通知...出现异常才会执行);}// todo 最终通知public void endAdvice() {System.out.println(最终通知....怎么样都会通知);}}xml配置文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd!-- 配置目标类 --bean iduserService classcom.example.Service.ServiceImpl.UserServiceImpl/!-- 配置通知类 --bean idmyAdvice classcom.example.advice.MyAdvice/!-- AOP配置 --aop:config!-- 切点表达式指定哪些方法被增强 --aop:pointcut idMyPointCutexpressionexecution(void com.example.Service.ServiceImpl.UserServiceImpl.*(..))/!-- 配置织入指定哪些切点与哪些通知进行结合 --aop:aspect refmyAdvice!-- 前置通知--aop:before methodbeforeAdvice pointcut-refMyPointCut/!-- 后置通知--aop:after-returning methodafterAdvice pointcut-refMyPointCut/!-- 环绕通知--aop:around methodaround pointcut-refMyPointCut/aop:around!-- 异常通知--aop:after-throwing methodafterThrowingAdvice pointcut-refMyPointCut/!-- 最终通知--aop:after methodendAdvice pointcut-refMyPointCut//aop:aspect/aop:config /beans测试代码 package com.example.Test;import com.example.Service.UserService; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestMyAOP {public static void main(String[] args) {ApplicationContext applicationContext new ClassPathXmlApplicationContext(applicationContext.xml);UserService userService applicationContext.getBean(UserService.class);userService.show1();} }运行结果如下 上述的运行结果也多多少少体现了各种通知类型的通知顺序 具体可以参照文章AOP进阶-通知顺序-CSDN博客同时由于目标方法没有运行错误所以异常通知类无法通知造出异常后 AOP的配置两种方式 使用advisor配置切面使用较少创建一个类实现不同的类型的通知接口从而不用在配置文件设置通知类型。 实现通知接口的类增强类指定通知类型 package com.example.advice;import org.springframework.aop.AfterReturningAdvice; import org.springframework.aop.MethodBeforeAdvice;import java.lang.reflect.Method;public class MyAdvice2 implements MethodBeforeAdvice, AfterReturningAdvice {Overridepublic void before(Method method, Object[] objects, Object o) throws Throwable {System.out.println(前置通知~~~~~~);}Overridepublic void afterReturning(Object o, Method method, Object[] objects, Object o1) throws Throwable {System.out.println(后置通知~~~~~~);}}配置文件该配置文件中并没有指定通知类型 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd!-- 配置目标类 --bean iduserService classcom.example.Service.ServiceImpl.UserServiceImpl/!-- 配置通知类 --bean idmyAdvice2 classcom.example.advice.MyAdvice2/aop:configaop:pointcut idMyPointCut expressionexecution(* com.example.Service.ServiceImpl.UserServiceImpl.*(..))/aop:advisor advice-refmyAdvice2 pointcut-refMyPointCut/aop:advisor/aop:config/beans测试类 package com.example.Test;import com.example.Service.UserService; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestMyAOP {public static void main(String[] args) {ApplicationContext applicationContext new ClassPathXmlApplicationContext(applicationContext2.xml);UserService userService applicationContext.getBean(UserService.class);userService.show1();} }运行结果如下 使用aspect配置切面上述配置中都是使用的该方法Spring定义了一个Advice接口实现该接口的类都可以作为通知类出现一般都是实现其子类 两种配置方案的比较 语法形式不同 advisor是通过实现接口来确认通知类型aspect是通过配置确认通知类型更加灵活可配置的切面数量不同 一个advisor只能配置一个固定通知和一个切点表达式一个aspect可以配置多个通知和多个切点表达式使用场景不同  运行任意搭配情况下可以使用aspect进行配置如果通知类型单一、切面单一的情况下可以使用advisor进行配置在通知类型已经固定不用人为指定通知类型时可以使用advisor进行配置例如后面会学习的Spring事务控制的配置。 明天再来p90 xml方式AOP原理剖析
http://www.zqtcl.cn/news/867027/

相关文章:

  • 网站建设与运营的预算方案淘宝禁止了网站建设类
  • 做网站的顺序编写app的软件
  • 站长联盟个人网站不备案
  • 惠州建设工程交易网站网站服务器失去响应
  • 网站下拉广告iphone app wordpress
  • 网站图片怎样做seo优化如何重新安装wordpress
  • python做网站源码长沙建设网站制作
  • wordpress调用分类的所有子目录龙岩seo公司首荐3火星
  • 聊城市建设工程质量监督站网站wordpress 头部
  • 低价郑州网站建设wordpress是外网吗
  • 互联网门户网站有哪些win10优化大师是官方的吗
  • 深圳品牌做网站公司有哪些公司名称变更网站要重新备案吗
  • 网站网页建设实训心得体会二类电商平台都有哪些
  • 兰州免费网站建设上海城隍庙要门票吗
  • 如何做外贸soho做网站中型网站建设
  • 冠县品牌网站建设推广外贸企业网站管理系统
  • 信息管理的基本原理分析网站建设南阳网站建设制作
  • 网站一直百度上搜不到是怎么回事啊网站建设首保服务
  • 解决网站兼容性问题福州房产网站建设
  • 怀化百度整站优化服务wap网站前景
  • 临沂制作网站企业施工企业汛期工作实施方案
  • 82家合法现货交易所名单永康关键词优化
  • 郑州市建设工程造价信息网站浙江省建设工程质量管理协会网站
  • 乌兰浩特市建设局网站永州微网站建设
  • 做网站的用什么电脑好wordpress首页调用指定分类
  • 网站域名申请好了怎么建设网站室内设计培训班哪个学校好
  • 东莞厚街网站建设网页设计代码字号px
  • 网站建站免费淘宝优惠券网站建设总代
  • 茶叶网站设计建设工程监理招标网站
  • 网站建设发展历程做网站要多少钱 知乎