【问题标题】:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener issuejava.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener 问题
【发布时间】:2012-09-16 20:00:36
【问题描述】:

当我尝试启动我的应用程序时,控制台会显示下一个堆栈跟踪:

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

我读过同样的问题,但是没有 spring-web jars,但是在我的 pom.xml 中我已经包含了 spring 依赖项,问题仍然存在:

         <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

这里是 web.xml 文件(只是为了确定):

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:/context/webContext.xml
        </param-value>
    </context-param>

    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.xml</param-value>
    </context-param>



    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>springServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>springServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
     <filter-mapping>
            <filter-name>springSecurityFilterChain</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

    <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>

我清理了..,清理了 tomcat 工作目录......,我用 project->clean.. 清理了工作区,但没有任何帮助.. 我非常绝望......

更新============= 经过一些操作和魔术:)我成功地没有出现这样的异常,但出现了下一个:

java.lang.ClassCastException: org.springframework.web.filter.DelegatingFilterProxy cannot be cast to javax.servlet.Filter

【问题讨论】:

  • 听起来您正试图从 Eclipse 中运行?不是100%确定。如果是,请打开运行配置并查看您尝试部署到的服务器的“参数”选项卡。这将告诉部署的位置。它通常在 .../.metadata/somewhere.... 去那里,查看 catalina.out 和 localhost.todaydate.log 的“logs”目录,看看报告了哪些错误。
  • 是的,我正在使用 Eclipse。我没有发现任何日志。我在许多文件夹中寻找它们,但没有结果:(
  • 必须添加一个“答案”来告诉您如何启用它 - 抱歉,我之前忘记了详细信息。尝试一下,看看是否有任何错误。
  • john,我昨天遇到了一个非常相似的问题,并在 stackoverflow.com/questions/10046654/… 上发布了一些提示

标签: java spring spring-mvc spring-security web.xml


【解决方案1】:

这本身不是答案,但需要输入的内容超出我的评论范围。这仅告诉您如何启用 Eclipse Tomcat 实例的日志记录。启用 Eclipse Tomcat 实例的登录比我记得的要混乱。您仍然编辑运行时配置。在 VM 参数下的“参数”选项卡上添加 2 个属性:

-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 
-Djava.util.logging.config.file=/path_to_your/logging.properties

这应该会根据 logging.properties 文件启用您的日志记录(可以放在任何地方 - 我很少更改我的 Eclipse 服务器,所以我只是将副本放在那里的“conf”目录中)。

如果您需要一个方便的工具,这里是一个 logging.properties 文件的副本:


# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler,     3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

1catalina.org.apache.juli.FileHandler.level = FINE
1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.

2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.

3manager.org.apache.juli.FileHandler.level = FINE
3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.FileHandler.prefix = manager.

4host-manager.org.apache.juli.FileHandler.level = FINE
4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.FileHandler.prefix = host-manager.

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter


############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers =   2localhost.org.apache.juli.FileHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.FileHandler

org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.FileHandler

# For example, set the org.apache.catalina.util.LifecycleBase logger to log
# each component that extends LifecycleBase changing state:
#org.apache.catalina.util.LifecycleBase.level = FINE

# To see debug messages in TldLocationsCache, uncomment the following line:
#org.apache.jasper.compiler.TldLocationsCache.level = FINE

【讨论】:

    【解决方案2】:

    你的春季版本是什么?

    在您的项目上运行 mvn clean install

    然后mvn tomcat:run 显示结果日志。

    您需要将 war-file 与您的项目打包并尝试将其部署在独立的 Tomcat 上

    【讨论】:

    • spring 版本是 3.0.6.Release
    • 可能是maven找不到jar,但是在repository里面,类和方法调用正常。但是问题项目无法启动让我更担心
    • 也许这个问题有关联?更重要的是您的项目必须在没有任何 IDE 的情况下运行。
    • @JohnSmith 您需要将 war-file 与您的项目打包并尝试将其部署在独立的 Tomcat 上。
    • @JohnSmith 在我看来,你在类路径中弄乱了库。某些库可能与其他库发生冲突。例如,如果你有两个版本的 spring-web.jar
    【解决方案3】:

    您的应用程序似乎存在一些配置问题。你可以参考这个链接 http://www.mkyong.com/spring/spring-error-classnotfoundexception-org-springframework-web-context-contextloaderlistener/

    【讨论】:

    • 我用的是maven,链接里的spring版本太旧了
    猜你喜欢
    • 2011-09-06
    • 2018-09-02
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 2021-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多