Got java.lang.NoClassDefFoundError while learning Spring framework -
i've been searching reason why failed long time, couldn't figure out.
the structure of files
src |__com.learn.spring.beans.annotation | |__main.java | |__testobject.java | |__beans.annotation.xml
main.java
package com.learn.spring.beans.annotation; import org.springframework.context.applicationcontext; import org.springframework.context.support.classpathxmlapplicationcontext; public class main { public static void main(string[] args) { applicationcontext ctx = new classpathxmlapplicationcontext("beans-annotation.xml"); testobject = (testobject)ctx.getbean("testobject"); system.out.println(to); } }
testobject.java
package com.learn.spring.beans.annotation; import org.springframework.stereotype.component; @component public class testobject { }
beans-annotation.xml
<?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:context="http://www.springframework.org/schema/context" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <context:component-scan base-package="com.learn.spring.beans.annotation"></context:component-scan> </beans>
i got following error:
picked java_tool_options: -javaagent:/usr/share/java/jayatanaag.jar sep 21, 2015 4:08:51 afternoon org.springframework.context.support.classpathxmlapplicationcontext preparerefresh info: refreshing org.springframework.context.support.classpathxmlapplicationcontext@1a6c5a9e: startup date [mon sep 21 16:08:51 cst 2015]; root of context hierarchy sep 21, 2015 4:08:51 afternoon org.springframework.beans.factory.xml.xmlbeandefinitionreader loadbeandefinitions info: loading xml bean definitions class path resource [beans-annotation.xml] exception in thread "main" org.springframework.beans.factory.beandefinitionstoreexception: unexpected exception parsing xml document class path resource [beans-annotation.xml]; nested exception java.lang.noclassdeffounderror: org/springframework/aop/targetsource @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.doloadbeandefinitions(xmlbeandefinitionreader.java:414) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:336) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:304) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:181) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:217) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:188) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:252) @ org.springframework.context.support.abstractxmlapplicationcontext.loadbeandefinitions(abstractxmlapplicationcontext.java:127) @ org.springframework.context.support.abstractxmlapplicationcontext.loadbeandefinitions(abstractxmlapplicationcontext.java:93) @ org.springframework.context.support.abstractrefreshableapplicationcontext.refreshbeanfactory(abstractrefreshableapplicationcontext.java:129) @ org.springframework.context.support.abstractapplicationcontext.obtainfreshbeanfactory(abstractapplicationcontext.java:604) @ org.springframework.context.support.abstractapplicationcontext.refresh(abstractapplicationcontext.java:509) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:139) @ org.springframework.context.support.classpathxmlapplicationcontext.<init>(classpathxmlapplicationcontext.java:83) @ com.learn.spring.beans.annotation.main.main(main.java:13) caused by: java.lang.noclassdeffounderror: org/springframework/aop/targetsource @ org.springframework.context.annotation.annotationconfigutils.registerannotationconfigprocessors(annotationconfigutils.java:154) @ org.springframework.context.annotation.componentscanbeandefinitionparser.registercomponents(componentscanbeandefinitionparser.java:150) @ org.springframework.context.annotation.componentscanbeandefinitionparser.parse(componentscanbeandefinitionparser.java:88) @ org.springframework.beans.factory.xml.namespacehandlersupport.parse(namespacehandlersupport.java:74) @ org.springframework.beans.factory.xml.beandefinitionparserdelegate.parsecustomelement(beandefinitionparserdelegate.java:1411) @ org.springframework.beans.factory.xml.beandefinitionparserdelegate.parsecustomelement(beandefinitionparserdelegate.java:1401) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.parsebeandefinitions(defaultbeandefinitiondocumentreader.java:168) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.doregisterbeandefinitions(defaultbeandefinitiondocumentreader.java:138) @ org.springframework.beans.factory.xml.defaultbeandefinitiondocumentreader.registerbeandefinitions(defaultbeandefinitiondocumentreader.java:94) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.registerbeandefinitions(xmlbeandefinitionreader.java:508) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.doloadbeandefinitions(xmlbeandefinitionreader.java:392) ... 14 more caused by: java.lang.classnotfoundexception: org.springframework.aop.targetsource @ java.net.urlclassloader.findclass(urlclassloader.java:381) @ java.lang.classloader.loadclass(classloader.java:424) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:331) @ java.lang.classloader.loadclass(classloader.java:357) ... 25 more
add following pom.xml (if using maven)
<dependency> <groupid>org.springframework</groupid> <artifactid>spring-aop</artifactid> <version>4.2.1.release</version> </dependency>
Comments
Post a Comment