Announcement Announcement Module
Collapse
No announcement yet.
TomcatInstrumentableClassLoader Servlet ClassNotFoundException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • TomcatInstrumentableClassLoader Servlet ClassNotFoundException

    I using Tomcat 6 as the App Server for my web application which uses the AOP to inject DAO into servlet but the problem 1 is Tomcat still using the default server class loader rather than TomcatInstrumentableClassLoader to load the GenericServlet. From the stacktrace, Error loading org.springframework.instrument.classloading.tomcat .TomcatInstrumentableClassLoader. Why is it ?

    Problem 2 is Tomcast class loader tries to load GenericServlet from default package rather than custom defined package. Thus, I tried to put GenericServlet.class into default package and I realized the TomcatInstrumentableClassLoader complaints NoClassDefFoundError.

    Question 1:
    As mentione as above.

    Question 2:
    I create this project (DAO) as war dynamic project in eclipse ?
    How to use this DAO in another project such as war project using @Autowired GenericDAO ? Is it merge applicationContext.xml or configure contextConfigLocation ? Is it using XMLApplicationContext for jar project ?

    StackTrace:
    Code:
    INFO: Initializing Spring root WebApplicationContext
    17:21:02,477  INFO ContextLoader:272 - Root WebApplicationContext: initialization started
    17:21:02,571  INFO XmlWebApplicationContext:510 - Refreshing Root WebApplicationContext: startup date [Mon Dec 31 17:21:02 SGT 2012]; root of context hierarchy
    17:21:02,635  INFO XmlBeanDefinitionReader:315 - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
    17:21:02,967  INFO DefaultContextLoadTimeWeaver:89 - Using a reflective load-time weaver for class loader: org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
    17:21:03,614  INFO DefaultListableBeanFactory:577 - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@188c838: defining beans root of factory hierarchy
    17:21:03,944  INFO EhCacheManagerFactoryBean:100 - Initializing EHCache CacheManager
    17:21:04,263  INFO MLog:80 - MLog clients using log4j logging.
    17:21:04,330  INFO C3P0Registry:204 - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
    17:21:04,471  INFO ContextLoader:301 - Root WebApplicationContext: initialization completed in 1993 ms
    Dec 31, 2012 5:21:04 PM org.apache.coyote.http11.Http11Protocol start
    INFO: Starting Coyote HTTP/1.1 on http-8080
    Dec 31, 2012 5:21:04 PM org.apache.jk.common.ChannelSocket init
    INFO: JK: ajp13 listening on /0.0.0.0:8009
    Dec 31, 2012 5:21:04 PM org.apache.jk.server.JkMain start
    INFO: Jk running ID=0 time=0/11  config=null
    Dec 31, 2012 5:21:04 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 2354 ms
    Dec 31, 2012 5:21:08 PM org.apache.catalina.core.ApplicationContext log
    INFO: Marking servlet GenericServlet as unavailable
    Dec 31, 2012 5:21:08 PM org.apache.catalina.core.ApplicationContext log
    SEVERE: Error loading org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
    WebappClassLoader
      context: /BISDAO
      delegate: false
      repositories:
        /WEB-INF/classes/
    ----------> Parent Classloader:
    org.apache.catalina.loader.StandardClassLoader@3c0007
     GenericServlet
    java.lang.ClassNotFoundException: GenericServlet
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1128)
        at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Unknown Source)
    Dec 31, 2012 5:21:08 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Allocate exception for servlet GenericServlet
    java.lang.ClassNotFoundException: GenericServlet
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1128)
        at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Unknown Source)
    Below is my configuration:

    I have put spring-instrument-tomcat-3.1.2.RELEASE.jar into $CATALINA_HOME\lib and have context.xml inside my META-INF folder.

    Code:
    <?xml version='1.0' encoding='utf-8'?>
    <Context path="/BISDAO">
        <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" />
    </Context>
    applicationContext.xml
    Code:
    <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" 
        xmlns:tx="http://www.springframework.org/schema/tx"
        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-2.5.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    
        <context:annotation-config />
    
        <context:component-scan base-package="com.breeze.bis.core.service.jdbcTemplate" />
    
        <context:load-time-weaver aspectj-weaving="autodetect" />
    
        <tx:annotation-driven proxy-target-class="false" transaction-manager="transactionManager"/>
    
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
            <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/vbossdb" />
            <property name="driverClass" value="com.mysql.jdbc.Driver" />
            <property name="user" value="root" />
            <property name="password" value="root" />
        </bean>
    
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <constructor-arg type="javax.sql.DataSource" ref="dataSource"></constructor-arg>
        </bean>
    
        <bean id="genericDaoImpl" class="com.breeze.bis.core.service.jdbcTemplate.GenericDAOImpl">
            <property name="jdbcDao" ref="jdbcTemplate"></property> 
        </bean>
    
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource"></property> 
        </bean>
    </beans>
    Servlet.java
    Code:
    @Configurable
    public class GenericServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        @Autowired
        GenericDAO dao;
    }

    Please help.
    Thanks.
    Last edited by peterwkc; Jan 7th, 2013, 05:36 AM.

  • #2
    I suggest a read of the reference guide.

    First it is a bad idea to put classes in the default package simply put it in a package and reference it from the web.xml (as you should have done).

    Second your configuration is flawed as there is nothing indicating that you want to use spring to do dependency injection into other objects. You need to add context:spring-configured into your context file else your @Configurable is pretty much useless.).

    Comment


    • #3
      First, I did not put the classes in default package.
      Second, I had put context:spring-configured into your context file.

      The problem is why error loading TomcatInstrumentableClassLoader.

      Comment


      • #4
        Solved this problem by add servlet class in web.xml. Thread closed

        Comment

        Working...
        X