10

I am using Spring 4.2.4.RELEASE in my web application and I would like to remove the dependency on aspectjweaver.jar from it. I don't use AOP directly and I certainly don't use AspectJ. But my application fails with the following exception:

java.lang.ClassNotFoundException: org.aspectj.util.PartialOrder$PartialComparable
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:450)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:403)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at org.eclipse.jetty.webapp.WebAppClassLoader.findClass(WebAppClassLoader.java:510)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:441)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:403)
at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.sortAdvisors(AspectJAwareAdvisorAutoProxyCreator.java:73)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:91)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:346)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:298)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)

Is the any way to completely remove the dependency on aspectjweaver.jar ?

Nikem
  • 5,716
  • 3
  • 32
  • 59

4 Answers4

19

I encountered this problem when using the @Transactional annotation on a class annotated with @Component in Spring Boot similar to: https://spring.io/guides/gs/managing-transactions/

The easiest way to fix it is to add the proper Maven dependency:

<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjweaver</artifactId>
  <version>1.8.9</version>
</dependency>
jordiburgos
  • 5,964
  • 4
  • 46
  • 80
Adam C.
  • 191
  • 1
  • 3
  • I am also getting this issue when i use these anotations together but wasnt getting this error before i made some changes to my app but now I am. any idea whats causing it because i didn't even change code related to this class and if it worked without explicitly requiring dependency i would like to do so – yasgur99 Mar 11 '19 at 03:59
3

Adding spring-boot-starter-aop dependency would resolve the issue, if you are facing it in the springboot application.

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
</dependency>
1

Is there any way to completely remove the dependency on aspectjweaver.jar ?

No, you cannot. You are using Spring AOP. The Spring project spring-aop does have a hard dependency on aspectjweaver.jar. Read the Spring-aop docs that clearly identifies it as a dependency.

VHS
  • 9,534
  • 3
  • 19
  • 43
  • "At a minimum you will need the following libraries to use the Spring Framework’s support for AspectJ LTW". I don't want to use Spring's support for AspectJ LTW. So again, why do you need this library? Why there is a class level dependency? – Nikem Feb 22 '17 at 17:32
  • @Nikem, in your question you have tagged `spring-aop`. Do you use `spring-aop`? If you don't, you don't need aspectjweaver.jar. – VHS Feb 22 '17 at 18:14
  • Have you read my question at all? If I remove `aspectjweaver.jar`, then application crashed with above mentioned exception – Nikem Feb 22 '17 at 18:19
  • 1
    @Nikem, how can someone answer a question without reading it first? Read my previous comment again. I think you have not understood the point I was trying to make. I am trying to say that you are using Spring AOP which has a hard dependency on aspect weaver. If you want to get rid of aspect weaver, you need to get rid of Spring AOP first. E.g. if you are simply using the basic Spring (Spring context), you wouldn't need AOP or aspect weaver and hence you won't get the exception. – VHS Feb 22 '17 at 19:27
1

The answer is no. Spring AOP is syntactically an AspectJ subset, thus it uses AspectJ classes for parsing pointcuts. It also exposes AspectJ classes like JoinPoint, ProceedingJoinPoint and AspectJ annotations like @Poinctut, @Before, @After, @Around, @DeclareParents etc.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
  • But why then `spring-aop` module does not depend on `aspectjweaver`? – Nikem Apr 12 '17 at 08:55
  • But it does. Look at [mvnrepository.org](https://mvnrepository.com/artifact/org.springframework/spring-aop/4.3.7.RELEASE), it lists aspectjweaver as compile dependency. – kriegaex Apr 12 '17 at 10:36
  • org.aspectj » aspectjweaver (optional). It claims to be optional, but it is not. Without it an application fails – Nikem Apr 12 '17 at 11:53
  • 1
    Not my fault. Maybe a copy & paste error, it is also listed as optional for spring-core. Maybe you want to open a ticket and get it fixed. – kriegaex Apr 12 '17 at 12:22