Aspect weaving at runtime

后端 未结 3 762
旧时难觅i
旧时难觅i 2021-02-15 12:21

I\'m looking for a Java solution that would allow me to use AOP to weave new code on top of already running code at runtime. The key is not to require the restart of the JVM. Al

3条回答
  •  清酒与你
    2021-02-15 13:20

    Aspect

    An aspect is the cross-cutting functionality you are implementing. It is the aspect, or area, of your application you are modularizing. The most common (albeit simple) example of an aspect is logging. Logging is something that is required throughout an application. However, because applications tend to be broken down into layers based on functionality, reusing a logging module through inheritance

    does not make sense. However, you can create a logging aspect and apply it throughout your application using AOP.


    Weaving

    Weaving is the process of applying aspects to a target object to create a new, proxied object. The aspects are woven into the target object at the specified joinpoints. The weaving can take place at several points in the target class’s lifetime:

    • Compile time :Aspects are woven in when the target class is compiled. This requires a special compiler.
    • Classload time :Aspects are woven in when the target class is loaded into the JVM. This requires a special ClassLoader that enhances that target class’s bytecode before the class is introduced into the application.
    • Runtime :Aspects are woven in sometime during the execution of the application. Typically, an AOP container will dynamically generate a proxy class that will delegate to the target class while weaving in the aspects.

    enter image description here
    enter image description here

    (Source)

提交回复
热议问题