hello all, i wrote a small application to test spring + aspectJ LTW... my post in the spring forums is here
http://forum.springframework.org/showthread.php?t=55168 i posted in the spring forums coz my test (ran using maven surefire plugin) resulted in the code not being intercepted by the aspect... However, when i ran my application from the commandline, the aspect gets intercepted properly.... here's my pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>TestAspectJ</groupId> <artifactId>TestAspectJ</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>TestAspectJ</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>2.5.4</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-mock</artifactId> <version>2.0.6</version> <!-- <exclusions> <exclusion> <groupId>ehcache</groupId> <artifactId>ehcache</artifactId> </exclusion> </exclusions> --> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.13</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>spring</version> <scope>system</scope> <systemPath>/home/marco/TestAspectJ/aspectj/aspectjrt-spring.jar</systemPath> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>spring</version> <scope>system</scope> <systemPath>/home/marco/TestAspectJ/aspectj/aspectjweaver-spring.jar</systemPath> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> </configuration> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <forkMode>pertest</forkMode> <argLine>-javaagent:spring-agent.jar</argLine> <!-- system class loader required to pass javaagent to all tests--> <useSystemClassLoader>true</useSystemClassLoader> </configuration> </plugin> </plugins> </build> </project> when i ran my app from commandline java -javaagent:spring-agent.jar -cp log4j-1.2.15.jar:aspectjweaver-spring.jar:commons-logging-api-1.0.4.jar:commons-logging-1.11.jar:target/TestAspectJ-1.0-SNAPSHOT.jar:spring-2.5.4.jar:. TestAspectJ.App the bean method gets intercepted successfully.... so this make me think that mayb my surefire configuration is not right? here's code i have in my Main class ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath*:beanContext.xml"); SimpleBean bean = (SimpleBean)context.getBean("simpleBean"); String result = bean.method1("foo"); System.err.println("call mehtod1 resulted in:" + result); i have tried to put exactly the same code in my test, to validate the behaviour... when i ran application i got following 07-Jun-2008 18:27:52 org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing [EMAIL PROTECTED]: display name [EMAIL PROTECTED]; startup date [Sat Jun 07 18:27:52 BST 2008]; root of context hierarchy 07-Jun-2008 18:27:52 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from URL [jar:file:/home/marco/TestAspectJ/target/TestAspectJ-1.0-SNAPSHOT.jar!/beanContext.xml] 07-Jun-2008 18:27:53 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory INFO: Bean factory for application context [EMAIL PROTECTED]: [EMAIL PROTECTED] 07-Jun-2008 18:27:53 org.springframework.context.weaving.DefaultContextLoadTimeWeaver setBeanClassLoader INFO: Found Spring's JVM agent for instrumentation 07-Jun-2008 18:27:53 org.springframework.aop.aspectj.AspectJWeaverMessageHandler handleMessage INFO: [AspectJ] AspectJ Weaver Version 1.5.4 built on Thursday Dec 20, 2007 at 13:44:10 GMT 07-Jun-2008 18:27:53 org.springframework.aop.aspectj.AspectJWeaverMessageHandler handleMessage INFO: [AspectJ] register classloader [EMAIL PROTECTED] 07-Jun-2008 18:27:53 org.springframework.aop.aspectj.AspectJWeaverMessageHandler handleMessage INFO: [AspectJ] using configuration file:/home/marco/TestAspectJ/target/TestAspectJ-1.0-SNAPSHOT.jar!/META-INF/aop.xml 07-Jun-2008 18:27:53 org.springframework.aop.aspectj.AspectJWeaverMessageHandler handleMessage INFO: [AspectJ] register aspect com.mm.aspectj.TestAspect 07-Jun-2008 18:27:54 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in [EMAIL PROTECTED]: defining beans [org.springframework.context.weaving.AspectJWeavingEnabler#0,loadTimeWeaver,simpleBean]; root of factory hierarchy 07-Jun-2008 18:27:54 org.springframework.aop.aspectj.AspectJWeaverMessageHandler handleMessage INFO: [AspectJ] Join point 'method-execution(java.lang.String com.mm.beans.SimpleBean.method1(java.lang.String))' in Type 'com.mm.beans.SimpleBean' (SimpleBean.java:18) advised by around advice from 'com.mm.aspectj.TestAspect' (TestAspect.java) log4j:WARN No appenders could be found for logger (com.mm.beans.SimpleBean). When i ran the tests, it seems nothing is happening.. this is the output of running mvn -X test INFO] [surefire:test] [DEBUG] dummy:dummy:jar:1.0 (selected for null) [DEBUG] org.apache.maven.surefire:surefire-booter:jar:2.3:runtime (selected for runtime) [DEBUG] org.apache.maven.surefire:surefire-api:jar:2.3:runtime (selected for runtime) [DEBUG] org.codehaus.plexus:plexus-utils:jar:1.1:runtime (selected for runtime) [DEBUG] commons-lang:commons-lang:jar:2.1:runtime (selected for runtime) [DEBUG] org.codehaus.plexus:plexus-utils:jar:1.1:runtime (selected for runtime) [DEBUG] org.codehaus.plexus:plexus-archiver:jar:1.0-alpha-7:runtime (selected for runtime) [DEBUG] org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-8:runtime (selected for runtime) [DEBUG] org.codehaus.plexus:plexus-utils:jar:1.0.4:runtime (removed - nearer found: 1.1) [DEBUG] junit:junit:jar:3.8.1:runtime (selected for runtime) [DEBUG] classworlds:classworlds:jar:1.1-alpha-2:runtime (selected for runtime) [DEBUG] org.codehaus.plexus:plexus-utils:jar:1.2:runtime (removed - nearer found: 1.1) [DEBUG] Adding to surefire booter test classpath: /home/marco/.m2/repository/org/codehaus/plexus/plexus-archiver/1.0-alpha-7/plexus-archiver-1.0-alpha-7.jar [DEBUG] Adding to surefire booter test classpath: /home/marco/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar [DEBUG] Adding to surefire booter test classpath: /home/marco/.m2/repository/org/codehaus/plexus/plexus-container-default/1.0-alpha-8/plexus-container-default-1.0-alpha-8.jar [DEBUG] Adding to surefire booter test classpath: /home/marco/.m2/repository/org/apache/maven/surefire/surefire-api/2.3/surefire-api-2.3.jar [DEBUG] Adding to surefire booter test classpath: /home/marco/.m2/repository/classworlds/classworlds/1.1-alpha-2/classworlds-1.1-alpha-2.jar [DEBUG] Adding to surefire booter test classpath: /home/marco/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar [DEBUG] Adding to surefire booter test classpath: /home/marco/.m2/repository/commons-lang/commons-lang/2.1/commons-lang-2.1.jar [DEBUG] Adding to surefire booter test classpath: /home/marco/.m2/repository/org/apache/maven/surefire/surefire-booter/2.3/surefire-booter-2.3.jar [DEBUG] dummy:dummy:jar:1.0 (selected for null) [DEBUG] Retrieving parent-POM: org.apache.maven.surefire:surefire-providers::2.3 for project: null:surefire-junit:jar:2.3 from the repository. [DEBUG] Retrieving parent-POM: org.apache.maven.surefire:surefire::2.3 for project: null:surefire-providers:pom:null from the repository. [DEBUG] Retrieving parent-POM: org.apache.maven:maven-parent::5 for project: org.apache.maven.surefire:surefire:pom:2.3 from the repository. [DEBUG] Retrieving parent-POM: org.apache:apache::3 for project: org.apache.maven:maven-parent:pom:5 from the repository. [DEBUG] org.apache.maven.surefire:surefire-junit:jar:2.3 (selected for null) [DEBUG] org.apache.maven.surefire:surefire-api:jar:2.3:compile (selected for compile) [DEBUG] org.codehaus.plexus:plexus-utils:jar:1.1:compile (selected for compile) [DEBUG] commons-lang:commons-lang:jar:2.1:compile (selected for compile) [DEBUG] junit:junit:jar:3.8.1:compile (selected for compile) [DEBUG] Adding to surefire test classpath: /home/marco/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar [DEBUG] Adding to surefire test classpath: /home/marco/.m2/repository/org/apache/maven/surefire/surefire-api/2.3/surefire-api-2.3.jar [DEBUG] Adding to surefire test classpath: /home/marco/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar [DEBUG] Adding to surefire test classpath: /home/marco/.m2/repository/commons-lang/commons-lang/2.1/commons-lang-2.1.jar [DEBUG] Adding to surefire test classpath: /home/marco/.m2/repository/org/apache/maven/surefire/surefire-junit/2.3/surefire-junit-2.3.jar [DEBUG] Test Classpath : [DEBUG] /home/marco/TestAspectJ/target/classes [DEBUG] /home/marco/TestAspectJ/target/test-classes [DEBUG] /home/marco/TestAspectJ/aspectj/aspectjweaver-spring.jar [DEBUG] /home/marco/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar [DEBUG] /home/marco/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar [DEBUG] /home/marco/.m2/repository/org/springframework/spring-mock/2.0.6/spring-mock-2.0.6.jar [DEBUG] /home/marco/TestAspectJ/aspectj/aspectjrt-spring.jar [DEBUG] /home/marco/.m2/repository/org/springframework/spring/2.5.4/spring-2.5.4.jar [DEBUG] /home/marco/.m2/repository/log4j/log4j/1.2.13/log4j-1.2.13.jar [DEBUG] Setting system property [localRepository]=[/home/marco/.m2/repository] [DEBUG] Setting system property [basedir]=[/home/marco/TestAspectJ] [DEBUG] Using JVM: /usr/lib/jvm/java-1.5.0-sun-1.5.0.11/jre/bin/java [INFO] Surefire report directory: /home/marco/TestAspectJ/target/surefire-reports [INFO] Building jar: /tmp/surefirebooter25681.jar Forking command line: /usr/lib/jvm/java-1.5.0-sun-1.5.0.11/jre/bin/java -javaagent:spring-agent.jar -jar /tmp/surefirebooter25681.jar /tmp/surefire25679tmp /tmp/surefire25680tmp anyone could help me out? i really like to test my aspect rather than 'trusting' the fact that it'lll be applied at runtime anyone could help? thanks and regards marco
