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

做百科专用参考链接的网站安阳网站建设哪里最好

做百科专用参考链接的网站,安阳网站建设哪里最好,交友小程序源码,nike网站开发背景及意义目录 AOP概念代理模式引出AOP实现方式xml方式实现注解方式实现 AOP 概念 事务管理#xff1a;比如可以抽取try catch的重复代码 日志监控#xff1a;比如业务逻辑前后打印关于当前订单数量的日志#xff0c;了解业务做了什么 性能监控#xff1a;比如业务前后打印时间比如可以抽取try catch的重复代码 日志监控比如业务逻辑前后打印关于当前订单数量的日志了解业务做了什么 性能监控比如业务前后打印时间相减可查看业务跑完所需时间 代理模式引出 用aop实现扩展功能 aop用代理模式实现但是代理模式里的扩展功能还是需要我们自己写 静态代理相当于一个中介只代理一个固定的房东的房源基本不用 动态代理默认没有使用的时候动态生成 AOP以上大方向 SpringAOPAOP的spring实现方式用动态代理方式实现。它的实现方式又有两种jdkCGLIBspring自动选择用其中哪种方式代理类自动生成也不用管有接口的时候默认使用jdk没有的时候用cglib(第三方jar包)现在一般service都有接口 AOP实现方式 xml方式实现 1.编写TxManager用来提供业务逻辑外的扩展功能 - 如事务管理 /*我们自己的扩展功能*/ public class TxManager {public void open (){System.out.println(开启事务);}public void commit (){System.out.println(提交事务);}public void rollback(Throwable e){e.printStackTrace();//处理异常System.out.println(回滚事务);}public void close(){System.out.println(关闭事务);}public void around(ProceedingJoinPoint point){try {open();point.proceed();//执行真正的业务commit();} catch (Throwable e) {e.printStackTrace();rollback(e);} finally {close();}} }2.准备xmlAOP环境在Spring配置文件中引入头支持以支持aop标签 SpringTest-Context.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:aophttp://www.springframework.org/schema/aopxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi: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.xsd3.配置的三要素 何时如在业务的执行前、后、catch 何地指的是在哪一个方法 做什么执行我们自定义扩展业务类的方法 面向切面编程面向扩展功能编程 其他 spring通过动态代理实现aop配置aop后只能注入接口通过接口找到被引用的代理类Spring容器中就只有代理类没有实现类 RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration//回到当前类的包下 查找当前类名-Context.xml的配置文件 public class SpringTest {AutowiredIUserService userService;Testpublic void testUser(){System.out.println(userService.getClass());} }SpringTest-Context.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:aophttp://www.springframework.org/schema/aopxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi: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.xsdbean iduserService classcn.itsource._03aopxml.service.impl.UserServiceImpl/bean iddepartmentService classcn.itsource._03aopxml.service.impl.DepartmentServiceImpl/!--将扩展功能交给Spring容器管理方便AOP使用--bean idtxManager classcn.itsource._03aopxml.TxManager/!--SpringAOP的核心配置--aop:config!--配置切点 配置何地 在哪一个方法执行expression表达式 通过表达式我们找在哪一个方法执行第一个*任意返回值I*Service:所有以I开头 Service结尾的类里面的所有方法都加上事物第三个*任意方法save(..):任意参数--!--execution(* cn.itsource._03aopxml.service.impl.UserServiceImpl.save(..))execution(* cn.itsource._03aopxml.service.impl.UserServiceImpl.*(..))--aop:pointcut idtxPoint expressionexecution(* cn.itsource._03aopxml.service.I*Service.*(..))/!--配置切面 --aop:aspect reftxManager!--配置前置通知 配置何时做什么--!--aop:before methodopen pointcut-reftxPoint/--!--配置后置通知--!--aop:after-returning methodcommit pointcut-reftxPoint/--!--配置异常通知--!--aop:after-throwing methodrollback pointcut-reftxPoint throwinge/--!--配置最终通知--!--aop:after methodclose pointcut-reftxPoint/--!--配置环绕通知 环绕通知一行顶上面四行--aop:around methodaround pointcut-reftxPoint//aop:aspect/aop:config /beans测试 详细见工程代码 注解方式实现 A 引入容器扫描头 Spring AOP SpringTest-Context.xml ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:aophttp://www.springframework.org/schema/aopxmlns:contexthttp://www.springframework.org/schema/contextxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi: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.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd!--开启Spring注解扫描--context:component-scan base-packagecn.itsource._04aopanno/!--开启SpringAOP 注解扫描--aop:aspectj-autoproxy//beans后面的几步都是在TxManager中完成 B 将扩展业务交给容器管理 Component C 申明pointcutPointcut需要提供一个空方法 D 配置各种通知 只用Around环绕通知其他四种通知不能确定执行顺序 /*我们自己的扩展功能*/ Component //组件 把当前类交给Spring容器管理 Aspect // aop:aspect reftxManager 配置切面 public class TxManager {//配置切点 aop:pointcut idtxPointPointcut(execution(* cn.itsource._04aopanno.service.I*Service.*(..)))public void txPoint(){/*这个方法指明在业务类中的每个方法*/}/*配置前置通知*//*Before(txPoint())*/public void open (){System.out.println(开启事物);}/*AfterReturning(txPoint())*/public void commit (){System.out.println(提交事物);}/*AfterThrowing(value txPoint(), throwing e)*/public void rollback(Throwable e){e.printStackTrace();//处理异常System.out.println(回滚事务);}/*After(txPoint())*/public void close(){System.out.println(关闭事物);}Around(txPoint())public void around(ProceedingJoinPoint point){try {open();point.proceed();//执行真正的业务commit();} catch (Throwable e) {e.printStackTrace();rollback(e);} finally {close();}} }测试 详细见工程代码
http://www.hkea.cn/news/14376866/

相关文章:

  • 手机建站专家济南建设图审
  • 深圳网站设计公司 网络服务珠海市建设工程交易中心网
  • 网站空间什么意思网站建设交付物清单
  • 锐奇智能手机网站建设网站推广方法有几个
  • 免费代理上网ip地址企业官网优化
  • 个人网站的建设与管理网站网页设计的意义
  • ps制作网站首页面教程对网站开发与管理的分析
  • 汕头网站建设技术外包wordpress主题实现伪静态
  • 网站速度慢如何做优化网站建设公司 优势
  • 郑州网站seo技术自助网站建设系统软件
  • 怎么在中国移动做网站备案淘宝宝贝关键词排名查询工具
  • 成都学校网站建设公司wordpress主题字体大小
  • 社交网站建设网站宜昌 网站建设
  • 建站之星和凡科建站哪个系统好新手制作网站
  • 怎样查看网站是用什么cms 做的市场营销毕业后做什么工作
  • 湖北神润建设工程网站杭州专业做网站
  • 西宁做网站的公司力请君博d做一个平台网站的预算
  • 网络营销网站的功能成都网站设计的公司
  • 综合门户型网站有哪些怎么建网站做推广
  • 怎么做不用数据库的网站有限公司破产后债务谁承担
  • 菲律宾做网站好吗做网站需要看啥书
  • 网站备案经验信阳seo推广
  • 高要建设网站wordpress注册带密码
  • 网站title重复的后果施工员证查询官方网站
  • qq官方网站东莞厚街核酸检测点
  • 如何让自己做的网站让别人看到常用的网页制作软件有
  • 建设行业的门户网站企业网站管理系统设计报告
  • 网站建设报价 福州做网站自动赚钱吗
  • 网站建设 策划方案书郑州网站建设快速排名熊掌
  • 个人网站备案如何取名称做网站展示软件