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

时间:2022-05-12 20:46:09

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

7 个解决方案

#1


Please do the following:

请执行以下操作:

  • remove all log4j related artifacts from your war file - includes log4j.jar/properties/xml;
  • 从war文件中删除所有与log4j相关的工件 - 包括log4j.jar / properties / xml;

  • include log4j.jar in common/lib or lib ( depending on your Tomcat version );
  • 在common / lib或lib中包含log4j.jar(取决于你的Tomcat版本);

  • add a log4j.properties file in common/classes ( not sure on Tomcat 6 ).
  • 在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 

#2


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

在ubuntu 12.04下,tomcat7系统日志存储在/var/lib/tomcat7/localhost. .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

#3


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

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

#4


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。你确定在classpath中加载了启动hibernate所需的所有类吗? Hibernate分为很多.jar包,我建议你检查文件.jar之间的依赖关系

#5


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).

日志中是否存在任何错误(在较早的时间点)?这并不是很重要(尽管如此,我不会感到惊讶)。

#6


Here is 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的共享文件夹中没有冲突的jar文件。

#7


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上下文侦听器和服务器配置。

#1


Please do the following:

请执行以下操作:

  • remove all log4j related artifacts from your war file - includes log4j.jar/properties/xml;
  • 从war文件中删除所有与log4j相关的工件 - 包括log4j.jar / properties / xml;

  • include log4j.jar in common/lib or lib ( depending on your Tomcat version );
  • 在common / lib或lib中包含log4j.jar(取决于你的Tomcat版本);

  • add a log4j.properties file in common/classes ( not sure on Tomcat 6 ).
  • 在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 

#2


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

在ubuntu 12.04下,tomcat7系统日志存储在/var/lib/tomcat7/localhost. .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

#3


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

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

#4


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。你确定在classpath中加载了启动hibernate所需的所有类吗? Hibernate分为很多.jar包,我建议你检查文件.jar之间的依赖关系

#5


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).

日志中是否存在任何错误(在较早的时间点)?这并不是很重要(尽管如此,我不会感到惊讶)。

#6


Here is 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的共享文件夹中没有冲突的jar文件。

#7


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上下文侦听器和服务器配置。