java 当 Tomcat 无法启动我的 Spring/Hibernate Web 应用程序时,如何找到错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1100489/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 15:11:10  来源:igfitidea点击:

How can I find the error when Tomcat fails to start my Spring/Hibernate web application?

javahibernatespringtomcatweb.xml

提问by James Adams

I have a Spring/Hibernate application which I have converted into a web application in order to provide RESTful web services (using Jersey). I am trying to deploy the web application onto Tomcat 6.0.20 and I get only a cryptic error message in the log file:

我有一个 Spring/Hibernate 应用程序,我已将其转换为 Web 应用程序以提供 RESTful Web 服务(使用 Jersey)。我正在尝试将 Web 应用程序部署到 Tomcat 6.0.20 上,但在日志文件中只收到一条神秘的错误消息:

Jul 8, 2009 2:25:22 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Jul 8, 2009 2:25:22 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/lmrest] startup failed due to previous errors

I have set my logging level to debug but there are no suspicious messages which show what went awry, other than this one, which looks pretty innocuous to me:

我已将我的日志记录级别设置为调试,但没有任何可疑消息显示出了什么问题,除了这个对我来说看起来很无害的消息:

1360 [http-8080-1] INFO  org.hibernate.cfg.search.HibernateSearchEventListenerRegister  - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.

I am using the latest versions of Spring and Hibernate. I am using a ContextLoaderListener in my web.xml. Could this be the listener that is failing to start? I assume it is running at least partially since I can see many Hibernate configuration log messages scroll past before the failure of the start of the web app. My main trouble is I can't see any error messages indicating what has failed to start the listener it's complaining about.

我正在使用最新版本的 Spring 和 Hibernate。我在 web.xml 中使用了 ContextLoaderListener。这可能是无法启动的侦听器吗?我认为它至少部分运行,因为我可以看到许多 Hibernate 配置日志消息在 Web 应用程序启动失败之前滚动过去。我的主要问题是我看不到任何错误消息,表明它抱怨的侦听器启动失败。

The web.xml I'm using looks like this:

我使用的 web.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- listener to pull in the Spring application context -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:appContext.xml</param-value>
    </context-param>

    <!-- Jersey servlet container to intercept all URIs -->
    <servlet>
        <servlet-name>JerseyContainer</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>JerseyContainer</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

If anyone can give me some ideas as to where to look for my error I'll really appreciate it, as I'm stumped. Thanks in advance!

如果有人能给我一些关于在哪里寻找我的错误的想法,我会非常感激,因为我很难过。提前致谢!

--James

- 詹姆士

回答by Robert Munteanu

Please do the following:

请执行以下操作:

  • remove all log4j related artifacts from your war file - includes log4j.jar/properties/xml;
  • include log4j.jar in common/lib or lib ( depending on your Tomcat version );
  • add a log4j.properties file in common/classes ( not sure on Tomcat 6 ).
  • 从您的War文件中删除所有与 log4j 相关的工件 - 包括 log4j.jar/properties/xml;
  • 在 common/lib 或 lib 中包含 log4j.jar(取决于您的 Tomcat 版本);
  • 在 common/classes 中添加一个 log4j.properties 文件(在 Tomcat 6 上不确定)。

This config should make sure that all log4j output is properly directed. Switch to debug if needed, but it should not be:

此配置应确保正确定向所有 log4j 输出。如果需要,切换到调试,但不应该是:

log4j.rootLogger=info, R 

log4j.appender.R=org.apache.log4j.RollingFileAppender 
log4j.appender.R.File=${catalina.home}/logs/catalina.out 
log4j.appender.R.MaxFileSize=10MB 
log4j.appender.R.MaxBackupIndex=10 
log4j.appender.R.layout=org.apache.log4j.PatternLayout 
log4j.appender.R.layout.ConversionPattern=%d %p %t %c - %m%n 

回答by Jennifer Wood

Under ubuntu 12.04, tomcat7 system logs are stored in /var/lib/tomcat7/localhost.<date>.log

ubuntu 12.04下,tomcat7系统日志存放在 /var/lib/tomcat7/localhost.<date>.log

This location is controlled by /etc/tomcat7/logging.properties:

该位置由/etc/tomcat7/logging.properties以下控制:

handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.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.

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

Since startup failed due to a Tomcat error, not an application error, this is where the detailed report ended up. In my case Tomcat was complaining about a missing class definition.

由于启动失败是由于 Tomcat 错误,而不是应用程序错误,因此详细报告到此结束。就我而言,Tomcat 抱怨缺少类定义。

SEVERE: Error configuring application listener of class com.foo.security.tomcat.CustomSessionListener
java.lang.ClassNotFoundException: com.alleni.zebra.security.tomcat.CustomSessionListener

回答by Gandalf

Check your log4j.properties or log4j.xml and make sure your logging level is set to DEBUG

检查您的 log4j.properties 或 log4j.xml 并确保您的日志记录级别设置为DEBUG

回答by Tommaso Taruffi

Apache can't find class org.hibernate.cfg.search.HibernateSearchEventListenerRegister. Are you sure that all classes needed to start hibernate are loaded in classpath? Hibernate is divided into many .jar package, I suggest you to check dependencies beetween files .jar

Apache 找不到类 org.hibernate.cfg.search.HibernateSearchEventListenerRegister。您确定启动休眠所需的所有类都已加载到类路径中吗?Hibernate分为很多.jar包,建议你查看.jar​​文件之间的依赖关系

回答by Jon Onstott

Are there any errors further up in the log (at an earlier point in time)? That's not much to go off of (though I wouldn't be surprised if that's it).

日志中是否有任何错误(在更早的时间点)?这没什么好说的(尽管如果是这样我也不会感到惊讶)。

回答by kgiannakakis

Hereis a similar discussion at the SprinSource forums. Since the applicationContext.xml works with a standard JAR, this is most probably a classpath problem. Double check the WEB-INF/lib folder and make sure there aren't conflicting jars in Tomcat's shared folder.

是 SprinSource 论坛上的类似讨论。由于 applicationContext.xml 使用标准 JAR,这很可能是类路径问题。仔细检查 WEB-INF/lib 文件夹并确保 Tomcat 的共享文件夹中没有冲突的 jars。

回答by Thomas W

Probably classpath, or something not loading.. as others say, get the logging working.

可能是类路径,或者没有加载的东西......正如其他人所说,让日志记录工作。

1) I recommend a 'binary search' approach to find the fault. Comment out the 'Jersey' section in your web.xml. See if it works (or at least starts up).

1)我建议使用“二分搜索”方法来查找故障。注释掉 web.xml 中的“Jersey”部分。看看它是否有效(或至少启动)。

2) If not, comment out the Spring ContextLoaderListener. See if it works.

2)如果没有,注释掉Spring ContextLoaderListener。看看它是否有效。

3) Once you've found the problematic item, you can 'binary search' into it's config files -- commenting out half the config, etc, until you find the problematic section or class reference.

3) 找到有问题的项目后,您可以对它的配置文件进行“二进制搜索”——注释掉一半的配置等,直到找到有问题的部分或类引用。

If removing both/all sections of web.xml, and your context still fails to load.. look into Tomcat/Catalina context listeners & server config.

如果删除 web.xml 的两个/所有部分,并且您的上下文仍然无法加载.. 查看 Tomcat/Catalina 上下文侦听器和服务器配置。