Search code examples
springaopaspectjspring-aop

When we used aop compile and classloader weaving?


What better use or maybe when we use : weaving as compile time , classload time or runtime which is default spring strategy? Could someone give me a practical example using weaving as compile time or classload time? Thanks for any help .


Solution

  • What is better depends on your situation, e.g.:

    • For production aspects it usually makes sense to weave them during compile-time because that way they are right in your class files, you have no overhead for load-time weaving and all you need during runtime is aspectjrt.jar on your classpath.
    • For development or debugging aspects which might mean overhead in production (specific types of fine-grained logging, tracing, monitoring necessary to support bug tracking in production) are more flexibly applied on demand via load-time weaving.
    • If you want to weave (third-party) class files for which you do not have the sources, you can either use post compile time (binary) weaving and create new, woven classes or JARs replacing the original ones and deploy those, or you can also use LTW. Do whatever makes more sense in your situation and also dependent on whether the aspects are for production or debugging/monitoring.

    This list is incomplete, there are more factors and situations which can lead to a decision. LTW can make sense for production aspects, CTW can make sense for debugging aspects. Sometimes your technical environment limits your options.