Results 1 to 7 of 7

Thread: AspectJ Question

  1. #1
    Join Date
    Sep 2012
    Posts
    11

    Default AspectJ Question

    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?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2012
    Posts
    11

    Default AspectJ Question

    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.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Sep 2012
    Posts
    11

    Default

    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?

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Sep 2012
    Posts
    11

    Default Aspectj Question

    Have not tried this , but would this work

    In my app context 1 which is the root context have a line
    <context:load-time-weaver weaver-class="example.LoadTimeWeaver1">

    and in my other app context which is the web context

    <context:load-time-weaver weaver-class="example.LoadTimeWeaver2">

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •