ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
Spring + Hibernate4 integration, and transaction are managed by Spring AOP, example :
spring-hibernate.xml
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="userDaoPointCut"
expression="execution(* com.mkyong.users.service.*Dao.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="userDaoPointCut" />
</aop:config>
</beans>
The system shows ClassNotFoundException: org.aspect.weaver...
.
caused by: java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getDeclaredConstructor(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1030)
... 47 more
Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
... 53 more
Solution
To solve it, declares spring-aspects
, it will get the org.aspectj
library automatically.
pom.xml
<properties>
<spring.version>3.2.8.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
Display the project dependency
#project> mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] +- org.springframework:spring-aspects:jar:3.2.8.RELEASE:compile
[INFO] | \- org.aspectj:aspectjweaver:jar:1.7.4:compile
[INFO] +- org.springframework:spring-orm:jar:3.2.8.RELEASE:compile
[INFO] | +- org.springframework:spring-jdbc:jar:3.2.8.RELEASE:compile
[INFO] | \- org.springframework:spring-tx:jar:3.2.8.RELEASE:compile
Superb!
One stop solution 🙂
You are simply the best, it works!
Thank you very much!!
it is wotking !! thanks
great
Thanks
Hi,
When I added the spring-orm dependency in Eclipse Kepler. I got the following error:
ArtifactDescriptorException: Failed to read artifact descriptor for org.springframework:spring-orm:jar
However my code worked by adding the spring-aspects dependency. So thanks for that!
But any idea why I got the error for the orm dependency?
Thanks
Thank you very much!!
Thank you very much.