Jan 31st, 2013, 10:27 AM
I have a question on spring aspectj lTW integration.
If an app has two application contexts (one loaded by the context listener and one for the dispatcher servlet) , if I specify <context:load-time-weaver> tag in the main context file , will it do load time weaving for the beans loaded by the context file that is passed to the dispatcher servlet.
Looks like that since even though I dont specify this tag in the web context file , my controllers are getting weaved at load time . Any comments?
Jan 31st, 2013, 02:26 PM
Loadtimeweaving works by chancing the classloader (registering classfiletransformers on it) and as the same classloader is used the advices apply to both contexts. This in contrast to the default spring spring aop mechanism.
Feb 1st, 2013, 12:06 AM
Thanks Marten .
How does LTW work in the context of multiple class loaders.
Having a look at the load time weaver class (say WebSphereLoadTimeWeaver ) and also AspectJWeavingEnabler it looks like the transformation is done only to the default class loader which is the web class loader. But what if I have an application which has 2 class loaders one for the app and its dependent libraries and one for the web module.
Feb 1st, 2013, 02:32 AM
It only changes the current classloader, so only classes loaded by same classloader will be modified. Unless you enable LTW for the whole/server or app.
Feb 1st, 2013, 03:53 AM
Thanks Marten . I understand that only classes loaded by same class loader will be modified.
But what if my app itself runs in 2 class loaders. Even though I switch on spring ltw, it seems to only transform the class loader of the thread in which the spring context is running. Not the other class loader.
If my app runs in 2 class loaders , is it possible to tell spring to transform both the class loaders and not just that of the current thread?
Feb 1st, 2013, 04:12 AM
No... It is either a single classloader (the one spring is using) or everything by using the agent on your classpath and modify the server startup.
Feb 4th, 2013, 07:42 AM
Have not tried this , but would this work
In my app context 1 which is the root context have a line
and in my other app context which is the web context
where LoadTimeWeaver1 and LoadTimeWeaver 2 are classes extending the custom load time weaver (Websphereloadtimeweaver) and which are created by passing in the required class loader.
Then would this work and would this have transformed the passed in class loaders?