What is 'weaving'?

Viewed 17660

I've seen this term when read about how Spring works and I've just read the article about JPA implementation performance and it has the next statistics:

EclipseLink                                                           3215 ms
(Run-time weaver - Spring ReflectiveLoadTimeWeaver weaver  )
EclipseLink (Build-time weaving)                                      3571 ms
EclipseLink (No weaving)                                              3996 ms

So, could someone explain in plain English, what is weaving?

Thanks!

8 Answers

In nutshell, we could say

Weaving is the process of applying the Advices to the Target objects at given pointcuts to get the Proxy Objects.

Weaving is the process of linking aspects with other application types or objects to create an advised object. Weaving can be done at compile time, at load time, or at runtime.

There are two ways in which classes and aspects can be woven: static or dynamic.

Spring AOP does dynamic weaving of aspects by creating proxy of the target objects.

It uses either JDK dynamic proxies or CGLIB to create the proxy for a given target object. (JDK dynamic proxies are preferred whenever you have a choice).

For more details..

I‌ found this description useful:

Weaving: This is the process of inserting aspects into the application code at the appropriate point. For compile-time AOP solutions, this weaving is generally done at build time. Likewise, for runtime AOP solutions, the weaving process is executed dynamically at runtime [using JDK‌ dynamic proxy and CGLIB proxy]. AspectJ supports another weaving mechanism called load- time weaving (LTW), in which it intercepts the underlying JVM class loader and provides weaving to the bytecode when it is being loaded by the class loader.

reference: Pro Spring 5: An In-Depth Guide to the Spring Framework and Its Tools

Weaving is the process of linking aspect with other application types or objects to create an advised object. Weaving can be done at compile time, load time or runtime. Spring AOP performs weaving at runtime.

Related