TomcatInstrumentableClassLoader Servlet ClassNotFoundException

时间:2012-12-31 09:41:58

标签: spring tomcat servlets aop

我使用Tomcat 6作为我的Web应用程序的App Server,它使用AOP将DAO注入servlet。

Dec 31, 2012 5:21:01 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre6\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Common Files\Acronis\SnapAPI\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin;C:\Program Files (x86)\Java\jdk1.6.0_26\bin;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\eclipse-jee-indigo-SR2-win32\eclipse;;.
Dec 31, 2012 5:21:02 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:BISDAO' did not find a matching property.
Dec 31, 2012 5:21:02 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context/Loader} Setting property 'useSystemClassLoaderAsParent' to 'false' did not find a matching property.
Dec 31, 2012 5:21:02 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Dec 31, 2012 5:21:02 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 288 ms
Dec 31, 2012 5:21:02 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Dec 31, 2012 5:21:02 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.35
Dec 31, 2012 5:21:02 PM org.apache.catalina.core.ApplicationContext log
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 [org.springframework.context.config.internalBeanConfigurerAspect,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,genericDAOImpl,org.springframework.context.weaving.AspectJWeavingEnabler#0,loadTimeWeaver,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.cache.annotation.AnnotationCacheOperationSource#0,org.springframework.cache.interceptor.CacheInterceptor#0,org.springframework.cache.config.internalCacheAdvisor,org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#0,dataSource,jdbcTemplate,genericDaoImpl,transactionManager,ehcache,cacheManager,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; 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)

以下是我的配置:

我已将spring-instrument-tomcat-3.1.2.RELEASE.jar放入$ CATALINA_HOME \ lib并在我的META-INF文件夹中安装了context.xml。

<?xml version='1.0' encoding='utf-8'?>
<Context path="/BISDAO">
    <Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" />
</Context>

的applicationContext.xml

<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">

    <!-- Enable @Required @Autowired @PreDestroy @PostConstruct @Resource -->
    <context:annotation-config />

    <!-- Scan class file in class path for annotated component -> @Component, @Repository, @Service, and @Controller  -->
    <context:component-scan base-package="com.breeze.bis.core.service.jdbcTemplate" />

    <!-- Enable load time weaving for @Configurable -->
    <context:load-time-weaver aspectj-weaving="autodetect" />

    <!--  -->
    <tx:annotation-driven proxy-target-class="false" transaction-manager="transactionManager"/>

    <!-- ==================================================================================================== -->

    <!-- Alternate method to enable @Autowired -->
    <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>

    <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

@Configurable
public class GenericServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Autowired
    GenericDAO dao;
}

请帮忙。

感谢。

2 个答案:

答案 0 :(得分:0)

您的servlet不应该在默认包中。把它移到一个合适的包中,它可能会起作用。

答案 1 :(得分:0)

使用web.xml中的自定义包定义servlet类