ServletContextListener SEVERE:配置类marktest.Config的应用程序侦听器时出错

时间:2013-01-09 16:58:35

标签: java web-services tomcat jersey tomcat7

我的Java servlet似乎在抱怨它无法找到包中包含的文件(marktest)。我正在使用Eclipse(Indigo)开发和Tomcat7。

这是错误:

SEVERE: Error configuring application listener of class marktest.Config
java.lang.ClassNotFoundException: marktest.Config
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)

这是Config.java,它包含实现ServletContextListener的类,它说它在错误中找不到:

package marktest;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;


public class Config implements ServletContextListener 
{

    private ExecutorService executor;

    @Override
    public void contextInitialized(ServletContextEvent event) 
    {
        System.out.println("########################## ServletContextListener started ###############################");

    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
    }

}

这是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_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>de.vogella.jersey.first</display-name>
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>marktest</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>

    <listener>
        <listener-class>marktest.Config</listener-class>
    </listener>

</web-app> 

即使经过谷歌搜索,我也很难过。在此先感谢您的帮助。

标记

----编辑----

以下是完整的控制台日志

10-Jan-2013 15:45:18 org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:nlpServer' did not find a matching property.
10-Jan-2013 15:45:18 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:18 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 661 ms
10-Jan-2013 15:45:18 org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
10-Jan-2013 15:45:18 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.21
########################## ServletContextListener started ###############################
10-Jan-2013 15:45:19 org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [1,052] milliseconds.
10-Jan-2013 15:45:19 com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  marktest
10-Jan-2013 15:45:19 com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class marktest.hello
10-Jan-2013 15:45:19 com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
10-Jan-2013 15:45:19 com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.16 11/28/2012 02:09 PM'
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class marktest.Config
java.lang.ClassNotFoundException: marktest.Config
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4660)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5226)
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5221)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:679)
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
10-Jan-2013 15:45:20 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [] startup failed due to previous errors
10-Jan-2013 15:45:20 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:20 org.apache.catalina.startup.Catalina start
INFO: Server startup in 2538 ms
10-Jan-2013 15:45:24 org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
10-Jan-2013 15:45:24 org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:25 org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
10-Jan-2013 15:45:25 org.apache.catalina.util.LifecycleBase stop
INFO: The stop() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] after stop() had already been called. The second call will be ignored.
10-Jan-2013 15:45:25 org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8080"]
10-Jan-2013 15:45:25 org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8080"]

4 个答案:

答案 0 :(得分:11)

向我看,好像你的类没有通过WTP正确部署到Tomcat(再次清理/发布)。

答案 1 :(得分:1)

即使在给定快照中突出显示的是在Tomcat服务器web.xml中配置的侦听器类条目时,我早些时候也得到了相同的ClassNotFoundException- Journal of Statistical Software 87:9, 1–27

收到此错误后,我将相同的条目从tomcat config Web.xml 替换为 {Project_Path} /WebContent/WEB-INF/web.xml。

在Tomcat服务器启动时指出错误已解决。

答案 2 :(得分:0)

这个问题可以被关闭,事实证明,eclipse是错误的,而不是发布我的更改。

答案 3 :(得分:0)

导致删除库源或在构建路径中移动库源。确保你在构建路径中没有任何错过的库&gt;库。

清理项目并再次运行tomcat。这将有所帮助。