• spring简介


    Spring简介: spring是一个框架,spring2003兴起的一个轻量级开发框架,由Rod Johnson

    框架的优势:分层架构(MVC   M:模型   v:视图  c:控制层)

    Spring优势:融合性强(spring相当于一个容器,一个大熔炉),IOC(控制反转,属性注入),Aop(面向切面编程,“oopAop就是oop的补充和完善)

    何为切面:

    例如

    Jdbc

    加载驱动

    创建连接

    ----------------------------------------------------------------------------------------

    操作数据

    -------------------------------------------------------------------------------------------

    关闭资源

    Aop核心概念:

    1. 横向关注点

      对那些方法进行拦截,拦截后怎么处理,这些关注点就是横向切入点

    2. 切面(aspect

          类是对事物特征的抽象,切面就是对横向关注点的抽象

    3. 连接点

      被拦截到的点,因为spring只支持方法类型的连接点,所以连接点就是被拦截的方法,还可以是字段或者构造器

    4. 切入点

      对连接点进行拦截的定义

    5. 通知

      所谓通知值得就是连接点之后要执行的代码,通知分为:前置、后置、异常、环形通知、最终

      6、目标对象

      代理的目标对象

    Aop配置

    1、命名空间

    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

    xmlns="http://www.springframework.org/schema/beans" 

    xmlns:aop="http://www.springframework.org/schema/aop" 

    xmlns:tx="http://www.springframework.org/schema/tx" 

    xsi:schemaLocation="http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd

    http://www.springframework.org/schema/aop

    http://www.springframework.org/schema/aop/spring-aop-4.2.xsd

    http://www.springframework.org/schema/tx

    http://www.springframework.org/schema/tx/spring-tx-4.2.xsd ">

    2Aop配置

    <aop:aspect id="times" ref="time">

    <!-- execution(* jinghang.Spring2.TimeHandler.*(..))     execution:方法执行时触发  *:括号里边第一个表示返回任意类型

    jinghang.Spring2.TimeHandler(方法属于哪个类)printTime*:指定方法   (..):使用任意参数

    -->

    <aop:pointcut  expression="execution(* jinghang.Spring2.TimeHandler.printTime*(..))" id="mytimes"></aop:pointcut>

    <!-- 设置通知

    前置:aop:before

    后置:aop:after

    环绕通知:aop:around

    异常通知:aop:after-throwing

    最终:aop:after-returning

    -->

    <aop:before method="printTime" pointcut-ref="mytimes"></aop:before>

    <aop:after method="printTime" pointcut-ref="mytimes"/>

    <aop:around method="printTime" pointcut-ref="mytimes"/>

    <aop:after-throwing method="printTime" pointcut-ref="mytimes"/>

    <aop:after-returning method="printTime" pointcut-ref="mytimes"/>

    </aop:aspect>

  • 相关阅读:
    react_瞎敲
    linux 删除类似文件
    mysql建立dblink 视图,无法查询到数据的问题
    Guava-Retrying 请求重试机制
    Command line is too long. Shorten command line for WebServiceUtilsTest.callMethod or also for JUnit default
    @Scheduled 定时任务注解不能运行
    jq拷贝表单$("#searchForm").clone(true),无法将select2数据value拷贝的问题
    正则表达式的lookaround(lookahead/lookbehind)以及密码复杂度检查
    MYSQL列的长度,NUMERIC_PRECISION和COLUMN_TYPE
    Qira-docker安装与使用
  • 原文地址:https://www.cnblogs.com/liqian-/p/12069623.html
Copyright © 2020-2023  润新知