Results 1 to 6 of 6

Thread: Setting up AspectJ in webapp

  1. #1
    Join Date
    Dec 2008
    Posts
    14

    Default Setting up AspectJ in webapp

    I have a jar file with some aspectJ aspects in it that I want to have load time weave with the code in another jar file. The goal is to have these aspect be optional by adding/removing the jar file.

    In following the docs I have created an aop.xml in the jar files META-INF directory.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE aspectj PUBLIC
    "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">

    <aspectj>
    <weaver options="-showWeaveInfo
    -XmessageHandlerClass:org.springframework.aop.aspec tj.AspectJWeaverMessageHandler">
    <include within="com.company.product..*"/>
    </weaver>
    </aspectj>

    I have also create a file named audit.xml at the root of the jar file
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <!-- this switches on the load-time weaving -->
    <context:load-time-weaver/>

    </beans>

    This jar file is in the webapp/WEB-INF/lib directory.

    In the servlet container I added the 1.5.3 version of all the aspectj libraries. My webapp comes up and works, but none of the aspects in this jar file are being weaved... Did I miss a step? Or do something incorrectly?

  2. #2
    Join Date
    Dec 2008
    Posts
    14

    Default Tanuki

    In case it matters, we use Jetty and Tanuki for starting/stopping. Do I need to include the spring-agent.jar in the config when starting the server? This webapp already makes use of spring security and other parts of spring. 2.5

  3. #3
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    Add <aspects> element with the list of aspects to use for weaving to your aop.xml. Feel free to check aspectj documentation about ltw setup.

  4. #4
    Join Date
    Dec 2008
    Posts
    14

    Default

    I added the aspect portion, but still no difference.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE aspectj PUBLIC    
      "-//AspectJ//DTD//EN"    "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">    
    
    <aspectj>    
       <weaver options="-showWeaveInfo
                  -XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler">
    	 <include within="com.mycompany.product.aspects.*"/>
       </weaver>
       <aspects>
      	 <aspect name="com.mycompany.product.aspects.MyLoggingAspect"/>
       </aspects>
    </aspectj>
    I also added aspectj-weaving=on in the bean definition because I saw it on another forum post and decided to give it a try
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    
        <!-- this switches on the load-time weaving -->
        <context:load-time-weaver aspectj-weaving="on"/>
    </beans>
    Should that be removed? is it needed?

    I also tried adding the following to the tanuki wrapper config
    Code:
    wrapper.java.additional.7=-javaagent:./lib/spring-agent.jar
    Should that be removed? is it needed?

  5. #5
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    Quote Originally Posted by cudaguy View Post
    I added the aspect portion, but still no difference.
    ...
    Why did you add '-XmessageHandlerClass:org.springframework.aop.aspec tj.AspectJWeaverMessageHandler' to the config? If there is no necessity just drop it out.


    Quote Originally Posted by cudaguy View Post
    I also added aspectj-weaving=on in the bean definition because I saw it on another forum post and decided to give it a try
    ...
    Should that be removed? is it needed?
    The reference is happy to explain what does that attribute mean (table 8.2)


    Quote Originally Posted by cudaguy View Post
    I also tried adding the following to the tanuki wrapper config
    Code:
    wrapper.java.additional.7=-javaagent:./lib/spring-agent.jar
    Should that be removed? is it needed?
    [/QUOTE]

    Don't know. I've never worked with that framework.

    Here is complete standalone working example that illustrates aspectj ltw usage with spring. You can try it in order to check if it works for you. In the case of the positive answer you can compare the mentioned configuration with the yours and sort the problem out.

  6. #6

    Default Try moving aop.xml

    You might want to try moving you aop.xml from /web/META-INF to /web/WEB-INF/classes/META-INF.

    I found that the aop.xml has to be in a META-INF directory on the classpath otherwise spring won't pick it up.

Tags for this Thread

Posting Permissions

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