Announcement Announcement Module
No announcement yet.
java.lang.NoClassDefFoundError: When using springs Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.lang.NoClassDefFoundError: When using springs

    Hello....I am using Spring to access hibernate, and I am receiving the following error message:

    10:35:47,962 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
    java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
    at employee.ejb.EmpBean.getEmployeeName( 49)
    at org.apache.jsp.Emp_jsp._jspService( )
    at org.apache.jasper.runtime.HttpJspBase.service(Http
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
    at org.apache.jasper.servlet.JspServletWrapper.servic e(
    at org.apache.jasper.servlet.JspServlet.serviceJspFil e(
    at org.apache.jasper.servlet.JspServlet.service(JspSe
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
    at ternalDoFilter(
    at Filter(
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(
    at ternalDoFilter(
    at Filter(
    at org.apache.catalina.core.StandardWrapperValve.invo ke(
    at org.apache.catalina.core.StandardContextValve.invo ke(
    at alve.invoke(
    at oke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke (
    at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve .invoke(
    at org.apache.catalina.core.StandardEngineValve.invok e(
    at org.apache.catalina.connector.CoyoteAdapter.servic e(
    at org.apache.coyote.http11.Http11Processor.process(H
    at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt
    at Socket(
    at .run(

    I am using Eclipse 3.2 with JBoss. I have included all the hibernate jar files which I could find and also spring.jar.

    my applicationContext file is as mentioned below...

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "">
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName">
    <property name="url">
    <property name="username">
    <property name="password">
    <bean id="factory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="mappingResources">
    <property name="hibernateProperties">
    <prop key="hibernate.dialect">org.hibernate.dialect.Orac le9Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <property name="dataSource" ref="dataSource"/>
    <bean id="employeeDao" class="com.lms.EmployeeSpringDao">
    <property name="sessionFactory">
    <ref bean="factory" />

    I am calling the applicationcontext from the below mentioned program...

    package com.lms;

    import org.springframework.context.ApplicationContext;
    import plicationContext;
    import org.hibernate.SessionFactory;

    public class EmployeeRegistry {

    public ApplicationContext ctx;

    public EmployeeRegistry(){

    ctx = new ClassPathXmlApplicationContext("applicationContext .xml");


    public SessionFactory getSessionFactory(){

    return (SessionFactory) ctx.getBean("factory", SessionFactory.class);

    public EmployeeSpringDao getEmployeeDao(){

    return (EmployeeSpringDao)ctx.getBean("employeeDao", EmployeeSpringDao.class);


    Is there anything more to be done? Any other jar files,other than spring.jar? I am using hibernate3.jar. I am using a jsp to call the hibernate functions. The hibernate part is working fine, as I tested it as a sample java application. But when I am using springs, I am receiving the error.
    Last edited by naveentsnts; Jun 22nd, 2007, 01:33 AM. Reason: forgot to add some details

  • #2
    It's a classpath error, I don't know which "spring.jar" you are using (btw, which version of Spring?), but :

    - either this "spring.jar" isn't a complete Spring distribution.
    - either you messed up your EAR classpath (I note the use of EJBs) : maybe you put "spring.jar" into the WEB-INF/lib of your War, but not in the EJBs' classpath


    • #3

      Hi julien,

      I am using Spring 2 only. I have included spring.jar into the Web module as well as inside the EJB module. Actually, I have gone to the project build path in Eclipse, and has imported all the jars. I am having one more doubt. I have imported all the jar files which I found out in my hibernate folder. Will such an action cause this problem? Can you suggest where all should I look, so as to make sure that all my classpaths are proper or not? Any "Required" classpath settings which you suggest would be of great help. And should anything be added in the web.xml or any other xml file regarding this?


      • #4
        I don't think "spring.jar" is everything you need. My copy of Spring 2.0.5 has "spring.jar", "spring-aspects.jar" and "spring-mock.jar" as well as a "modules" directory containing 21 other jar files. From that directory, I expect you will need at least "spring-core.jar", and probably a few others as well.


        • #5
          Originally posted by julesh View Post
          I don't think "spring.jar" is everything you need. My copy of Spring 2.0.5 has "spring.jar", "spring-aspects.jar" and "spring-mock.jar" as well as a "modules" directory containing 21 other jar files. From that directory, I expect you will need at least "spring-core.jar", and probably a few others as well.
          The choice is down to what you are using. If you are only using little bits of Spring, you might want to include on the modules you need. Other people just drop the full JAR in and be done with it.
          Last edited by karldmoore; Aug 29th, 2007, 12:10 PM.