I want to configure my spring project to work with AspectJ load time weaving. I've done following:
- added a
<context:load-time-weaver aspectj-weaving="on"/>
in my application contex - added aspectj in cache
added lines in my pom.xml
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-instrument</artifactId> <version>${springframework.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${springframework.version}</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>${org.aspectj.version}</version> </dependency> ........... <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <goals> <project>test</project> </goals> <configuration> <detail>true</detail> <forkMode>once</forkMode> <argLine>-javaagent:"${settings.localRepository}/org/springframework/spring-instrument/3.1.4.RELEASE/spring-instrument-3.1.4.RELEASE.jar"</argLine> </configuration> </plugin> </plugins> </build>
I have a test, and it fails.
@Cacheable(value = CacheConstants.FORM_TEMPLATE)
public int getRandomInt(){
return new Random().nextInt();
}
@Test
public void test(){
int i = getRandomInt();
assertEquals(i, getRandomInt());
}
Can somebody explain why it fails? It obvious that load time weaving isn't work.
Thanks, M. Deinum! Your comment is very useful! I've rewrited my test as follows
DaoObject
DaoObjectImpl
And my test now looks like
All fine. Thanks!