Announcement Announcement Module
Collapse
No announcement yet.
java.lang.NoClassDefFoundError: When using springs Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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(EmpBean.java: 49)
    at org.apache.jsp.Emp_jsp._jspService(Emp_jsp.java:58 )
    at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:97)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
    at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:334)
    at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314)
    at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:202)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:178)
    at org.jboss.web.tomcat.security.SecurityAssociationV alve.invoke(SecurityAssociationValve.java:175)
    at org.jboss.web.tomcat.security.JaccContextValve.inv oke(JaccContextValve.java:74)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
    at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve .invoke(CachedConnectionValve.java:156)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread .run(MasterSlaveWorkerThread.java:112)
    at java.lang.Thread.run(Thread.java:595)


    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" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName">
    <value>oracle.jdbc.driver.OracleDriver</value>
    </property>
    <property name="url">
    <value>jdbc:oracle:thin:@localhost:1521:oracle</value>
    </property>
    <property name="username">
    <value>scott</value>
    </property>
    <property name="password">
    <value>tiger</value>
    </property>
    </bean>
    <bean id="factory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="mappingResources">
    <list>
    <value>com/lms/Employee.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.Orac le9Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    <property name="dataSource" ref="dataSource"/>
    </bean>
    <bean id="employeeDao" class="com.lms.EmployeeSpringDao">
    <property name="sessionFactory">
    <ref bean="factory" />
    </property>
    </bean>
    </beans>


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

    package com.lms;

    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlAp 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, 02: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

    Comment


    • #3
      Re:

      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?

      Comment


      • #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.

        Comment


        • #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, 01:10 PM.

          Comment

          Working...
          X