java – NoClassDefFoundError:org / aopalliance / intercept / MethodInterceptor
My new spring and hibernate I don't know what I'm doing wrong
Project structure: –
library
On the web xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>SimpleSpringHibApp</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <!-- Spring Functionality --> <servlet> <servlet-name>Employee</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Employee</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/Employee-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
Employee servlet In 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:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p" 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.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <context:component-scan base-package="com.manoj.springprac" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/" /> <property name="suffix" value=".jsp" /> </bean> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basename" value="classpath:messages"></property> <property name="defaultEncoding" value="UTF-8"></property> </bean> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:location="/WEB-INF/jdbc.properties"></bean> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}"></bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionfactorybean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation"> <value>classpath:hibernate.cfg.xml</value> </property> <property name="configurationClass"> <value>org.hibernate.cfg.AnnotationConfiguration</value> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${jdbc.dialect}</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <bean id="employeeDAO" class="com.manoj.springprac.EmployeeDaoImpl"></bean> <bean id="employeeService" class="com.manoj.springprac.EmployeeServiceImpl"></bean> <tx:annotation-driven /> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> </beans>
Hibernate cfg. xml
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <mapping class="com.manoj.springprac.Employee"></mapping> </session-factory> </hibernate-configuration>
Error: –
SEVERE: Context initialization Failed org.springframework.beans.factory.BeanDeFinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/Employee-servlet.xml]; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor at org.springframework.beans.factory.xml.XmlBeanDeFinitionReader.doLoadBeanDeFinitions(XmlBeanDeFinitionReader.java:413) at org.springframework.beans.factory.xml.XmlBeanDeFinitionReader.loadBeanDeFinitions(XmlBeanDeFinitionReader.java:335) at org.springframework.beans.factory.xml.XmlBeanDeFinitionReader.loadBeanDeFinitions(XmlBeanDeFinitionReader.java:303) at org.springframework.beans.factory.support.AbstractBeanDeFinitionReader.loadBeanDeFinitions(AbstractBeanDeFinitionReader.java:180) at org.springframework.beans.factory.support.AbstractBeanDeFinitionReader.loadBeanDeFinitions(AbstractBeanDeFinitionReader.java:216) at org.springframework.beans.factory.support.AbstractBeanDeFinitionReader.loadBeanDeFinitions(AbstractBeanDeFinitionReader.java:187) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDeFinitions(XmlWebApplicationContext.java:125) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDeFinitions(XmlWebApplicationContext.java:94) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshbeanfactory(AbstractRefreshableApplicationContext.java:129) at org.springframework.context.support.AbstractApplicationContext.obtainFreshbeanfactory(AbstractApplicationContext.java:540) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1566) at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1556) at java.util.concurrent.FutureTask$Sync.innerRun(UnkNown Source) at java.util.concurrent.FutureTask.run(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(UnkNown Source) at java.lang.Thread.run(UnkNown Source) Caused by: java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(UnkNown Source) at java.security.SecureClassLoader.defineClass(UnkNown Source) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2889) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) at org.springframework.transaction.config.AnnotationDrivenBeanDeFinitionParser$AopAutoProxyConfigurer.configureAutoProxyCreator(AnnotationDrivenBeanDeFinitionParser.java:127) at org.springframework.transaction.config.AnnotationDrivenBeanDeFinitionParser.parse(AnnotationDrivenBeanDeFinitionParser.java:84) at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74) at org.springframework.beans.factory.xml.BeanDeFinitionParserDelegate.parseCustomElement(BeanDeFinitionParserDelegate.java:1424) at org.springframework.beans.factory.xml.BeanDeFinitionParserDelegate.parseCustomElement(BeanDeFinitionParserDelegate.java:1414) at org.springframework.beans.factory.xml.DefaultBeanDeFinitionDocumentReader.parseBeanDeFinitions(DefaultBeanDeFinitionDocumentReader.java:187) at org.springframework.beans.factory.xml.DefaultBeanDeFinitionDocumentReader.doRegisterBeanDeFinitions(DefaultBeanDeFinitionDocumentReader.java:141) at org.springframework.beans.factory.xml.DefaultBeanDeFinitionDocumentReader.registerBeanDeFinitions(DefaultBeanDeFinitionDocumentReader.java:110) at org.springframework.beans.factory.xml.XmlBeanDeFinitionReader.registerBeanDeFinitions(XmlBeanDeFinitionReader.java:508) at org.springframework.beans.factory.xml.XmlBeanDeFinitionReader.doLoadBeanDeFinitions(XmlBeanDeFinitionReader.java:391) ... 23 more Caused by: java.lang.ClassNotFoundException: org.aopalliance.intercept.MethodInterceptor at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) ... 40 more Mar 09,2014 5:35:47 PM org.apache.catalina.core.StandardContext listenerStart SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanDeFinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/Employee-servlet.xml]; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor at org.springframework.beans.factory.xml.XmlBeanDeFinitionReader.doLoadBeanDeFinitions(XmlBeanDeFinitionReader.java:413) at org.springframework.beans.factory.xml.XmlBeanDeFinitionReader.loadBeanDeFinitions(XmlBeanDeFinitionReader.java:335) at org.springframework.beans.factory.xml.XmlBeanDeFinitionReader.loadBeanDeFinitions(XmlBeanDeFinitionReader.java:303) at org.springframework.beans.factory.support.AbstractBeanDeFinitionReader.loadBeanDeFinitions(AbstractBeanDeFinitionReader.java:180) at org.springframework.beans.factory.support.AbstractBeanDeFinitionReader.loadBeanDeFinitions(AbstractBeanDeFinitionReader.java:216) at org.springframework.beans.factory.support.AbstractBeanDeFinitionReader.loadBeanDeFinitions(AbstractBeanDeFinitionReader.java:187) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDeFinitions(XmlWebApplicationContext.java:125) at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDeFinitions(XmlWebApplicationContext.java:94) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshbeanfactory(AbstractRefreshableApplicationContext.java:129) at org.springframework.context.support.AbstractApplicationContext.obtainFreshbeanfactory(AbstractApplicationContext.java:540) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1566) at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1556) at java.util.concurrent.FutureTask$Sync.innerRun(UnkNown Source) at java.util.concurrent.FutureTask.run(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(UnkNown Source) at java.lang.Thread.run(UnkNown Source) Caused by: java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(UnkNown Source) at java.security.SecureClassLoader.defineClass(UnkNown Source) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2889) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) at org.springframework.transaction.config.AnnotationDrivenBeanDeFinitionParser$AopAutoProxyConfigurer.configureAutoProxyCreator(AnnotationDrivenBeanDeFinitionParser.java:127) at org.springframework.transaction.config.AnnotationDrivenBeanDeFinitionParser.parse(AnnotationDrivenBeanDeFinitionParser.java:84) at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74) at org.springframework.beans.factory.xml.BeanDeFinitionParserDelegate.parseCustomElement(BeanDeFinitionParserDelegate.java:1424) at org.springframework.beans.factory.xml.BeanDeFinitionParserDelegate.parseCustomElement(BeanDeFinitionParserDelegate.java:1414) at org.springframework.beans.factory.xml.DefaultBeanDeFinitionDocumentReader.parseBeanDeFinitions(DefaultBeanDeFinitionDocumentReader.java:187) at org.springframework.beans.factory.xml.DefaultBeanDeFinitionDocumentReader.doRegisterBeanDeFinitions(DefaultBeanDeFinitionDocumentReader.java:141) at org.springframework.beans.factory.xml.DefaultBeanDeFinitionDocumentReader.registerBeanDeFinitions(DefaultBeanDeFinitionDocumentReader.java:110) at org.springframework.beans.factory.xml.XmlBeanDeFinitionReader.registerBeanDeFinitions(XmlBeanDeFinitionReader.java:508) at org.springframework.beans.factory.xml.XmlBeanDeFinitionReader.doLoadBeanDeFinitions(XmlBeanDeFinitionReader.java:391) ... 23 more Caused by: java.lang.ClassNotFoundException: org.aopalliance.intercept.MethodInterceptor at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) ... 40 more Mar 09,2014 5:35:47 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Error listenerStart Mar 09,2014 5:35:47 PM org.apache.catalina.core.StandardContext startInternal SEVERE: Context [/SimpleSpringHibApp] startup Failed due to prevIoUs errors Mar 09,2014 5:35:47 PM org.apache.catalina.core.ApplicationContext log INFO: Closing Spring root WebApplicationContext Mar 09,2014 5:35:47 PM org.springframework.context.support.AbstractApplicationContext doClose INFO: Closing Root WebApplicationContext: startup date [Sun Mar 09 17:35:47 IST 2014]; root of context hierarchy Mar 09,2014 5:35:47 PM org.springframework.context.support.AbstractApplicationContext doClose WARNING: Exception thrown from ApplicationListener handling ContextClosedEvent java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Sun Mar 09 17:35:47 IST 2014]; root of context hierarchy at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:346) at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:333) at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:880) at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841) at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579) at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115) at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4819) at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5466) at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160) at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1566) at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1556) at java.util.concurrent.FutureTask$Sync.innerRun(UnkNown Source) at java.util.concurrent.FutureTask.run(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(UnkNown Source) at java.lang.Thread.run(UnkNown Source) Mar 09,2014 5:35:47 PM org.springframework.context.support.AbstractApplicationContext doClose WARNING: Exception thrown from LifecycleProcessor on context close java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Sun Mar 09 17:35:47 IST 2014]; root of context hierarchy at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:359) at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:888) at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841) at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579) at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115) at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4819) at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5466) at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160) at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1566) at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1556) at java.util.concurrent.FutureTask$Sync.innerRun(UnkNown Source) at java.util.concurrent.FutureTask.run(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(UnkNown Source) at java.lang.Thread.run(UnkNown Source) Mar 09,2014 5:35:47 PM org.apache.catalina.core.StandardContext listenerStop SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener java.lang.IllegalStateException: beanfactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext at org.springframework.context.support.AbstractRefreshableApplicationContext.getbeanfactory(AbstractRefreshableApplicationContext.java:170) at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:921) at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841) at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579) at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115) at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4819) at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5466) at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160) at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1566) at org.apache.catalina.core.ContainerBase$startChild.call(ContainerBase.java:1556) at java.util.concurrent.FutureTask$Sync.innerRun(UnkNown Source) at java.util.concurrent.FutureTask.run(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(UnkNown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(UnkNown Source) at java.lang.Thread.run(UnkNown Source)
I don't know what I'm doing wrong Please help me. Any suggestion will help me
Thank you in advance
Solution
The first stacktrace says an exception
Is caused by an exception:
The Javadoc of the latter wrote:
That is, even if spring uses this class, the JVM cannot find the class org aopalliance. intercept. Class file for methodinterceptor
The most likely reason is that the jar file containing this class file is not part of the classpath because you have not added it to the library of your eclipse project
to update
The Spring Framework Reference Manual has a section on dependency management, but their description assumes that you use dependency management tools, such as maven, gradle, or ivy Therefore, I suggest you use such a tool This is not very difficult (Maven is used out of the box by eclipse. You only need to use the "new Maven project" Wizard instead of the "new Java project" wizard to create the project), and make sure you have all the dependencies