JAVA-Spring AOP Detailed

The basic concept of 1.Spring AOP

  Connection point ( Joinpoint ): during program execution in a particular point, such as when an exception processing method or the time. In Spring AOP, a join point always represents a method execution.

    Popular talk:

       Procedure calls between the layers, the method calls for the target layer, it is called the point of attachment.

 

 

  Entry point ( Pointcut ): matching connection point of the assertion. And a notification associated pointcut expression, and this operation is satisfied (e.g., when the method is performed with a certain name) to the connection point of entry points. How pointcut expressions and the connection point matching is central to AOP: Spring uses the AspectJ pointcut default syntax.

    Popular talk:

       On the basis of the connection point, to increase the cutting rule, the need for reinforcing the selected connection point, the cutting rule chosen based on the point of attachment is called an entry point.

 

 

  Section ( Aspect ): a modular concern, this concern that cuts across multiple objects. J2EE application transaction management is a good example of crosscutting concerns. In Spring AOP, based on the mode section may be used, or be implemented based annotation @Aspect manner.

    Popular talk:

       In a narrow sense it is, when the Spring interception at the entry point, entry point to deal with these classes enhancements, this process it is called class section.

       Broadly speaking, the underlying Spring speaking point and agents for handling calls between classes plus mechanisms layers together to achieve enhanced process, called section.

 

 

  Notification ( the Advice ): action performed on a particular section of the connection point. These include the "around", different types of "before" and "after" and the like notification (notification of the type discussed in the later section). Many AOP frameworks (including Spring) interceptors are doing since notification model, and maintain a connection point of a chain of interceptors center.

    Popular talk:

       After the interception at the bottom of the entry point in the Spring agent, the entry point to cut classes, cut class will have to deal with this method to write an entry point, which process is called notification (also known as enhanced enhancement). The starting point for the process of being executed, the notification also divided into different types, are concerned about the timing of different entry points during execution.

 

 

  Audience ( the Target Object ): Object to be notified of one or more section, also known to be notified (the Advised) object. Since Spring AOP is achieved by running a proxy, this object is always to be a proxy (Proxied) objects.

    Popular talk:

       It is the true hope of the object to be accessed. Spring underlying dynamic proxy proxy for him, can not really access to specific target object, or before and after the implementation of the target object is actually whether to do some extra work, depending on the cut surface.

 

 2.Spring case of AOP entry

  a. Import aop Related Development Kit

     

  b. Czech Republic, a class section

    

  c. the definition notice

    

  d. define a connection point

  

  e. Configure connection point

    Introducing the aop schema file in MyEclipse constraints, in order to label configuration file may prompt.

    Where you can configure the entry point:

    

  f. the definition section

     

  g. execution method, we found that section does work

    

 

3. pointcut expression

  a.within expression

    Coarse-grained matching pointcut expressions by class name

      within (package name. class name)

    All the connection points in this class are identified by the expression, be an entry point.

    

    在within表达式中可以使用*号匹配符,匹配指定包下所有的类,注意,只匹配当前包,不包括当前包的子孙包。

    

    在within表达式中也可以用*号匹配符,匹配包

     

    在within表达式中也可以使用..*匹配符,匹配指定包下及其子孙包下的所有类

    

    b.  execution()表达式

         细粒度的切入idan表达式,可以以方法为单位定义切入点规则

      语法:execution(返回值类型   包名.类名.方法名(参数列表,参数类型。。。))

        

 

 

      

Guess you like

Origin www.cnblogs.com/xiaoluohao/p/11286111.html