Community   SpringSource   Projects    Downloads    Documentation    Forums    Training   Exchange   Blogs

Go Back   Spring Community Forums > Core Spring Projects > AOP (Aspect Oriented Programming)

Reply
 
Thread Tools Display Modes
  #11  
Old Aug 13th, 2006, 04:25 AM
gschmutz gschmutz is offline
Member
 
Join Date: Aug 2004
Location: Berne, Switzerland
Posts: 42
Default

I have @Configurable running with both build-time and load-time weaving. Although the LTW version has a problem with the Spring 2.0rc3 because of a bug in AspectJ 1.5.2 (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=153572).

I have just perpared a small eclipse project showing the build-time weaving in an Eclipse AJDT project. You need the same configuration in the spring context as with LTW.

Code:
   <aop:spring-configured/>
    
    <bean class="com.trivadis.aop.configurable.Address" singleton="false">
    	<property name="codeRepository" ref="codeRepository"/>
    </bean>
    
	<bean id="codeRepository" class="com.trivadis.aop.configurable.CodeRepositoryImpl"/>
Then you have to add spring-aspects.jar to the AspectJ Aspect Path, because that's where the aspect handling the @Configurable can be found. The same can of course also be done with Maven or Ant.

I've uploaded the sample eclipse project with this post. Just run the unit test in ConfigurableTest.

Hope it helps!
Attached Files
File Type: zip aop-at-configurable-btw.zip (24.5 KB, 263 views)
__________________
Guido Schmutz
Principal Consultant, Trivadis Switzerland
Email: guido.schmutz AT trivadis.com
Reply With Quote
  #12  
Old Aug 13th, 2006, 04:34 AM
thomasvdv thomasvdv is offline
Member
 
Join Date: Aug 2004
Location: Los Angeles, USA
Posts: 55
Default

That worked for me. Thanks a lot!
Reply With Quote
  #13  
Old Sep 3rd, 2007, 06:06 AM
kajh kajh is offline
Senior Member
 
Join Date: Oct 2004
Posts: 138
Default

Hi!

Thank you for posting this description and code example!

This made me understand how to make our unittests run from inside eclipse when built by eclipse.

Until now the unittests worked just fine when running them from maven. When running them from eclipse we had to let maven do the compiling before running the tests if we had changed any of the classes using @Configurable to get dependencies injected

The next step was to make maven generate correct .project og .classpass file for us and we almost do that now with the following in pom.xml:
Code:
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <configuration>
          <projectnatures>
            <java.lang.String>org.springframework.ide.eclipse.core.springnature</java.lang.String>
            <java.lang.String>org.eclipse.jdt.core.javanature</java.lang.String>
            <java.lang.String>org.eclipse.ajdt.ui.ajnature</java.lang.String>
          </projectnatures>
          <buildcommands>
            <buildcommand>org.eclipse.ajdt.core.ajbuilder</buildcommand>
          </buildcommands>
        </configuration>
      </plugin>
What is missing here is generating the org.eclipse.ajdt.aspectpath attribute for the classpathentry in the .classpath file i.e.

Code:
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-aspects/2.0.6/spring-aspects-2.0.6.jar">
     <attributes>
        <attribute name="org.eclipse.ajdt.aspectpath" value="true"/>
     </attributes>
  </classpathentry>
This is not possible today with maven-eclipse-plugin, but there is an issue for this feature in the jira for maven-eclipse-plugin, see

http://jira.codehaus.org/browse/MECLIPSE-270

Feel free to vote for this issue!

btw are we using the following aspectj-maven-plugin configuration:
Code:
      <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.0-beta-2</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>test-compile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
          <encoding>iso-8859-1</encoding>
          <verbose>true</verbose>
          <outxml>false</outxml>

          <showWeaveInfo>true</showWeaveInfo>
          <proceedOnError>true</proceedOnError>
 
          <weaveDependencies>
            <weaveDependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-aspects</artifactId>
            </weaveDependency>
          </weaveDependencies>

          <aspectLibrarys>
            <aspectLibrary>
              <groupId>org.springframework</groupId>
              <artifactId>spring-aspects</artifactId>
            </aspectLibrary>
          </aspectLibrarys>

        </configuration>
      </plugin>

-Kaj

Last edited by kajh; Sep 3rd, 2007 at 06:16 AM.
Reply With Quote
  #14  
Old Jan 23rd, 2008, 04:28 AM
anydoby anydoby is offline
Junior Member
 
Join Date: Jan 2008
Posts: 5
Default My solution to the problem

Here is the solution I am using to do weaving - http://anydoby.com/jblog/article.htm?id=61&lng=en
Reply With Quote
  #15  
Old Jan 24th, 2008, 09:44 AM
anydoby anydoby is offline
Junior Member
 
Join Date: Jan 2008
Posts: 5
Default

Quote:
Originally Posted by kajh View Post
Hi!

Thank you for posting this description and code example!

This made me understand how to make our unittests run from inside eclipse when built by eclipse.

Until now the unittests worked just fine when running them from maven. When running them from eclipse we had to let maven do the compiling before running the tests if we had changed any of the classes using @Configurable to get dependencies injected

The next step was to make maven generate correct .project og .classpass file for us and we almost do that now with the following in pom.xml:
Code:
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <configuration>
          <projectnatures>
            <java.lang.String>org.springframework.ide.eclipse.core.springnature</java.lang.String>
            <java.lang.String>org.eclipse.jdt.core.javanature</java.lang.String>
            <java.lang.String>org.eclipse.ajdt.ui.ajnature</java.lang.String>
          </projectnatures>
          <buildcommands>
            <buildcommand>org.eclipse.ajdt.core.ajbuilder</buildcommand>
          </buildcommands>
        </configuration>
      </plugin>
What is missing here is generating the org.eclipse.ajdt.aspectpath attribute for the classpathentry in the .classpath file i.e.

Code:
  <classpathentry kind="var" path="M2_REPO/org/springframework/spring-aspects/2.0.6/spring-aspects-2.0.6.jar">
     <attributes>
        <attribute name="org.eclipse.ajdt.aspectpath" value="true"/>
     </attributes>
  </classpathentry>
This is not possible today with maven-eclipse-plugin, but there is an issue for this feature in the jira for maven-eclipse-plugin, see

http://jira.codehaus.org/browse/MECLIPSE-270

Feel free to vote for this issue!

btw are we using the following aspectj-maven-plugin configuration:
Code:
      <groupId>org.codehaus.mojo</groupId>
        <artifactId>aspectj-maven-plugin</artifactId>
        <version>1.0-beta-2</version>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
              <goal>test-compile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
          <encoding>iso-8859-1</encoding>
          <verbose>true</verbose>
          <outxml>false</outxml>

          <showWeaveInfo>true</showWeaveInfo>
          <proceedOnError>true</proceedOnError>
 
          <weaveDependencies>
            <weaveDependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-aspects</artifactId>
            </weaveDependency>
          </weaveDependencies>

          <aspectLibrarys>
            <aspectLibrary>
              <groupId>org.springframework</groupId>
              <artifactId>spring-aspects</artifactId>
            </aspectLibrary>
          </aspectLibrarys>

        </configuration>
      </plugin>

-Kaj
Your solution will also include Spring aspects into the resulting jar file. How do you fix that?
Reply With Quote
  #16  
Old Jan 24th, 2008, 11:04 AM
kajh kajh is offline
Senior Member
 
Join Date: Oct 2004
Posts: 138
Default

Quote:
Originally Posted by anydoby View Post
Your solution will also include Spring aspects into the resulting jar file. How do you fix that?
I'm not sure

I include part of our pom.xml bellow. You might try to add that and see if it helps.

btw... feel free to vote for http://jira.codehaus.org/browse/MECLIPSE-270

Code:
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-aspects</artifactId>
         <version>2.5.1</version>
      </dependency>
     
     <dependency>
         <groupId>aspectj</groupId>
         <artifactId>aspectjweaver</artifactId>
         <version>1.5.3</version>
      </dependency>
      <dependency>
         <groupId>aspectj</groupId>
         <artifactId>aspectjrt</artifactId>
         <version>1.5.3</version>
      </dependency>

...     
     
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>aspectj-maven-plugin</artifactId>
          <version>1.0-beta-2</version>
            <executions>
               <execution>
                  <goals>
                     <goal>compile</goal>
                     <goal>test-compile</goal>
                  </goals>
               </execution>
            </executions>
            <configuration>
               <source>1.5</source>
               <target>1.5</target>
               <encoding>utf-8</encoding>
               <verbose>true</verbose>
               <outxml>false</outxml>

               <showWeaveInfo>true</showWeaveInfo>
               <proceedOnError>true</proceedOnError>

               <weaveDependencies>
                  <weaveDependency>
                     <groupId>org.springframework</groupId>
                     <artifactId>spring-aspects</artifactId>
                  </weaveDependency>
               </weaveDependencies>

               <aspectLibrarys>
                  <aspectLibrary>
                     <groupId>org.springframework</groupId>
                     <artifactId>spring-aspects</artifactId>
                  </aspectLibrary>
               </aspectLibrarys>

            </configuration>
         </plugin>
-Kaj
Reply With Quote
  #17  
Old Jan 29th, 2008, 04:03 AM
anydoby anydoby is offline
Junior Member
 
Join Date: Jan 2008
Posts: 5
Default new aspectj plugin

I have investigated the issue of aspectj plugin including 3rd party aspects into my jars and realized that the plugin does not work for me. I was able to write my own plugin http://anydoby.com/jblog/article.htm?id=68&lng=en

which works as I expect it to work
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:07 AM.


Contegix provides first-class managed hosting and partial sponsorship of these forums.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.