springcachingaspectjcompile-time-weaving

Compile time weaving with Cache Abstraction in Spring


Currently i am using cache abstraction using proxy. Problem with proxy is that internal method calls don't work . Now, I want to use the compile time weaving instead of proxy as internal method calls works it. I have searched on google, but i didn't find any substantial link which explains how to use compile time weaving. There are many links for load time weaving. Can anyone give any example for compile time weaving with cache abstraction or some relevant link ??

Thanks in Advance.


Solution

  • You could add the spring aspect for caching using the maven aspectj plugin, by identifying the aspect class and applying it manually to the classes you want (check inside spring-aspects and spring-cache jars for the aspect).

    This mechanism is not directly linked to spring, it could be done with any aspect, not only spring aspects.

    The reason why it's not used is that it's not very convenient, because we need to know the classes we want to advise at compile time and cannot rely on spring annotation scanning mechanism.

    Load time weaving solves the problem you mention of making reentrant calls work in a more transparent way, without the inconveniences of compile time weaving. Load time weaving is the recommended way spring has put in place for using aspectJ weaving, enabled by annotation @EnableLoadTimeWeaving.

    For the concrete use case that you mentioned, there does not seem to be a good case to introduce compile-time weaving, in general there is no good use case for compile time weaving, which explains the lack of documentation available online.

    I believe your best option for the use case you mention would be to use load time weaving instead.