Chapter 1 AOP and chapter 1 aop

Source: Internet
Author: User

Chapter 1 AOP and chapter 1 aop

We usually use the AspectJ annotation for AOP. There are 6 middle-Cut sections in total.

  • Front: @ Before
  • Post: @ After
  • Returned value: @ AfterReturing
  • Exception: @ AfterThrowing
  • Surround: @ Around: can be understood as a set of the above four types
  • Reference (not commonly used)

Two difficult parts:

  • Connection points: JoinPoint and ProceedJoinPoint
    • The connection point is actually a method that overwrites the line expression. Multiple information can be obtained based on the connection point, which is commonly used as follows:
      • GetSignature (): Get the return value, full class name, and parameter type of the current method, for example: Shop com. xxx. firstboot. dao. ShopDao. getShop (int)
      • GetTarget (): obtains the class instance of the current method, for example, com. xxx. firstboot. dao. ShopDao @ 72f97c4f.
      • GetArgs (): Get the parameters of the current method, for example, [Ljava. lang. Object; @ 6fbd538a
    • JoinPoint is habitually used in addition to @ Around, And ProceedJoinPoint is habitually used in @ Around (because the ProceedJoinPoint proceed () method must be used to execute the target method)
  • Cut expression:
    • Execution (* com. xxx. firstboot. dao. *. * (...)
      • First *: represents any permission and return type, for example, public Shop. If you need to specify it explicitly, specify
      • The second *: represents all classes in this package, for example, ShopDao. If you need to specify it explicitly, specify
      • Third *: all methods under the class, for example, getShop. If you need to specify it explicitly, specify
      • ...: Indicates that the input parameter type of the method can be any type or any number (including 0), for example, int. If you need to specify it explicitly, specify
    • The tangent expression is the matching expression of the method (connection point ).

Two supplements:

    • The @ Order (number) annotation can be used to specify the weaving Order. For example, @ Order (1). The smaller the number, this annotation is used on the cut surface (that is, the cut surface class)
    • The cut-point expression can be reused.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.