Main Tutorials

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

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
10 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Unknown1
2 years ago

Superb!

One stop solution 🙂

Pablo
3 years ago

You are simply the best, it works!

Ana
5 years ago

Thank you very much!!

thamizh
6 years ago

it is wotking !! thanks

Chaturanga Kasun Bamunusingha
7 years ago

great

??
7 years ago

Thanks

Ketan
9 years ago

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?

arloz
9 years ago

Thanks

Oscar
9 years ago

Thank you very much!!

Oat
9 years ago

Thank you very much.