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:
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.
The web.xml I'm using looks like this:
<?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
Please do the following:
This config should make sure that all log4j output is properly directed. Switch to debug if needed, but it should not be:
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
Under ubuntu 12.04, tomcat7 system logs are stored in /var/lib/tomcat7/localhost.<date>.log
This location is controlled by /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.
SEVERE: Error configuring application listener of class com.foo.security.tomcat.CustomSessionListener
java.lang.ClassNotFoundException: com.alleni.zebra.security.tomcat.CustomSessionListener
检查log4j.properties或log4j.xml,确保您的日志记录级别设置为DEBUG
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
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).
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.
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).
2) If not, comment out the Spring ContextLoaderListener. See if it works.
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.
If removing both/all sections of web.xml, and your context still fails to load.. look into Tomcat/Catalina context listeners & server config.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.