"Core Spring" three, AOP

Source: Internet
Author: User

Some basic concepts of AOP

  Enhancement (Advice): Enhanced defines what the slices do and when. Spring slicing has the following 5 enhancements

      1. before--enhancements occur before an enhanced function call
      2. after--enhancements occur after the enhanced function is completed, regardless of completion (normal rollout, throw exception)
      3. after-returning--enhancements occur after the enhanced function is successfully completed
      4. after-throwing--enhancements occur after an exception is thrown by an enhanced function
      5. around--Enhanced packaging is enhanced to provide some functionality before and after an enhanced function call

  connection point (join points): Your application may have thousands of opportunities to be enhanced. These opportunities are connection points. A connection point is the point at which a slice can be inserted during program execution. This point can be called by a method, an exception is thrown, or even a domain (member variable) is modified. The code for your slices can be inserted into the normal process of the application to add new behavior.

  pointcut (pointcuts): If the enhancement defines what the slice does and when, then the pointcut defines where to do it. The definition of a pointcut includes one or more connection points that can be woven into the enhancement. You can specify connection points by explicit class and method names or by regular expressions that match the class and method name model.

  facets (aspects): A facet is a collection of enhancements and pointcuts.

  Introduction (Introductions): Introduction allows you to add new methods or properties to an existing class.

  Weaving (Weaving): Weaving is the process of applying a slice to a target object to create a new proxy object. Slices are woven into the target object at a specific connection point. Weaving can occur on nodes of the following target object life cycles.

        • Compile period-slices are woven after the target object is compiled. This requires a special compiler. The ASPECTJ weave the compiler into the slices.
        • Class load period-slices are woven after the target object is loaded into the JVM. This requires a special ClassLoader (the bit code of the target object is enhanced before the class is introduced into the application). The AspectJ 5 load-time weaving (LTW) supports this weaving method.
        • Runtime-The slice is woven at some time when the application is running. Typically, an AOP container dynamically generates a proxy object that is a delegate to a target object to weave a slice into. This is how spring AOP is implemented.
Spring's AOP support

Not all AOP frameworks are the same, and they may be differentiated by the richness of the connection point model, or by the way they are woven into slices. In any case, the ability to create pointcuts to define connection points that the tiles weave into is key to the AOP framework.

Spring's support for AOP has the following 4 ways:

        • Classic Spring proxy-based AOP
        • Pure-pojo aspects
        • @AspectJ Annotation-driven aspects
        • Injected AspectJ aspects (available in all versions of Spring)

The first 3 ways are spring's own implementations. Spring implements AOP through dynamic proxies. Therefore, Spring AOP is limited by method interception.

The first way is too much achievement, has been seldom applied, here no longer repeat.

With the AOP namespace, you can turn pure pojos into slices. In fact, these pojos only provide methods to respond to pointcut calls. Unfortunately, this technique requires an XML configuration, but this is a simple declarative way to turn any object into a slice.

"Core Spring" three, AOP

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.