Eclipse: how to convert a web project into an AspectJ project and bind and run it using the AJDT plugin?

What I want to do:

  • I want to use @Configured annotation with Spring. This requires that AspectJ be enabled. I thought that using the AJDT plugin to compile in time would solve this problem. Before installing the plug, the dependencies that were supposed to be injected into my @Configured object remained empty.

What I've done:

  • AJDT installed : AspectJ development tools for Eclipse 3.4.
  • Right click on my web project and turn it into an AspectJ project.
  • Compilation time weaving enabled.

What does not work:

  • When I start the Tomcat 6 server, I get an exception *.

Additional Information:

  • I did not configure anything in the AspectJ Build and AspectJ Compiler components of the project properties.
  • JDT Weaving in the "Preferences" section says that weaving is on.
  • I still have a Java build path and a Java compiler for the project properties. And they look as if I configured them before (while two new entries are not configured).
  • The icon of my @Configured object file looks like any other file (i.e. no sign of any aspect or one that I think should be). The file name is MailNotification.java (not .aj), but I think it should work anyway, since I'm using Spring annotation for AspectJ?
  • I have not found a single tutorial or the like that teaches: How to turn a Spring web application project into an AspectJ project and merge aspects into files using the AJDT plugin, all in Eclipse 3.4. If there is something like this, I would be very interested to know about it.

What I would like to know:

  • Where to go from here? I just want to use the @Configured Spring annotation. I also use @Transactional, which I think also needs AspectJ.
  • If possible, I would like to learn AspectJ as little as possible while my needs are met. The theme seems interesting, but huge, all I want to do is use the above two mentioned Spring annotations.

*** Exception when starting Tomcat 6:

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 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 
+4
source share
3 answers

Have you added spring -aspects.jar to your project path for the project?

In the project properties under "AspectJ Build" → "Aspect Path", try adding spring -aspects.jar and clear the project.

Sorry you already did this, but you didn’t say that.

+1
source

It seems that compilation time is not working. Try adding the lines below to your applicationcontext.xml

 <context:load-time-weaver /> <context:spring-configured/> 

You probably want to add the following xsd to the xml file as well

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd

See here for more details:

http://static.springframework.org/spring/docs/2.5.x/reference/aop.html#aop-aj-ltw

0
source

You can use @Transactional without AspectJ. Your configuration file should contain the following:

 <?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd" > <tx:annotation-driven/> 

tells spring to search for @transactional annotations when instantiating customized beans. When searching for such an annotation, spring returns a dynamic bean proxy to the application code. This dynamic proxy ensures that whenever annotated methods are called, spring can intercept it to provide the expected transactional behavior. But proxy-based AOPs require you to code interfaces, not specific classes.

0
source

Source: https://habr.com/ru/post/1285932/


All Articles