Eclipse: How to convert a web project into an AspectJ project and weave and run it using the AJDT pl
- by Kent
What I want to do:
I want to use the @Configured annotation with Spring. It requires AspectJ to be enabled. I thought that using the AJDT plugin for compile time weaving would solve this problem. Before installing the plug in the dependencies which were supposed to be injected into my @Configured object remained null.
What I have done:
Installed the AJDT: AspectJ Development Tools plug in for Eclipse 3.4.
Right clicked on my web project and converted it into a AspectJ project.
Enabled compile time weaving.
What doesn't work:
When I start the Tomcat 6 server now, I get an exception*.
Other information:
I haven't configured anything in the AspectJ Build and AspectJ Compiler parts of the project properties.
JDT Weaving under Preferences says weaving is enabled.
I still have Java build path and Java Compiler under project properties. And they look like I previously configured them (while the above two new entries are not configured).
The icon of my @Configured object file looks like any other file (i.e. no indication of any aspect or such, which I think there should be). The file name is MailNotification.java (and not .aj), but I guess it should still work as I'm using a Spring annotation for AspectJ?
I haven't found any tutorial or similar which teaches: How to turn a Spring web application project into an AspectJ project and weave aspects into the files using the AJDT plugin, all within Eclipse 3.4. If there is anything like that out there I would be very interested in knowing about it.
What I would like to know:
Where to go from here? I just want to use the @Configured annotation of Spring. I'm also using @Transactional which I think also needs AspectJ.
If it is possible I would like to study AspectJ as little as possible as long as my needs are met. The subject seems interesting, but huge, all I want to do is use the above two mentioned Spring annotations.
*** Exception when Tomcat 6 is started:
Caused by: java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:spring-agent.jar
at org.springframework.context.weaving.DefaultContextLoadTimeWeaver.setBeanClassLoader(DefaultContextLoadTimeWeaver.java:82)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1322)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473)
... 41 more