Tomcat啟動失敗問題解決
1. 系統框架加載正常,但是Tomcat啟動失敗,報錯如下:
Log代碼
- 2013-7-26 17:18:33 org.apache.catalina.core.StandardContext startInternal
- 嚴重: Error listenerStart
- 2013-7-26 17:18:34 org.apache.catalina.util.SessionIdGenerator createSecureRandom
- 信息: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [452
- 2013-7-26 17:18:34 org.apache.catalina.core.StandardContext startInternal
- 嚴重: Context [] startup failed due to previous errors
- 2013-7-26 17:18:34 org.apache.coyote.AbstractProtocol start
- 信息: Starting ProtocolHandler ["http-apr-8080"]
- 2013-7-26 17:18:34 org.apache.coyote.AbstractProtocol start
- 信息: Starting ProtocolHandler ["ajp-apr-8009"]
- 2013-7-26 17:18:34 org.apache.catalina.startup.Catalina start
- 信息: Server startup in 9576 ms
- diamond client log path : /home/admin/xxx/target/../logs/xx-client.log
- 2013-7-26 17:18:57 org.apache.catalina.loader.WebappClassLoader loadClass
- 信息: Illegal access: this web application instance has been stopped already. Could not load javax.xml.parsers.ParserConfigurationException. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
- java.lang.IllegalStateException
- at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1587)
- at com.taobao.tomcat.classloader.TomcatWebAppClassLoader.loadClass(TomcatWebAppClassLoader.java:37)
- at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546)
- at com.taobao.hsf.container.HSFClassLoaderDelegateHook.postFindClass(HSFClassLoaderDelegateHook.java:96)
- at org.eclipse.osgi.framework.internal.core.BundleLoader.searchHooks(BundleLoader.java:495)
- at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:461)
- at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:397)
- at org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader.java:385)
- at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:87)
2. 分析
查看上述日誌,可能會很明顯的看到下面很多的exception。都是this web application instance has been stopped already以及Could not load XX Class。但是不要被這些異常迷惑,他們只是結果而不是原因。
1). 細致一點可以查看到,哪些日誌是Tomcat是啟動完成之後報錯的。Server startup in 9576 ms
2). Tomcat日誌中有:嚴重: Error listenerStart。
3). 除了Error listenerStart沒有詳細日誌,但是可以知道是web.xml中listener初始化的時候出錯了。
3. 處理
1). 在WEB-INF/classes目錄下新建logging.properties
Log4j代碼
- handlers = org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
- ############################################################
- # Handler specific properties.
- # Describes specific configuration info for Handlers.
- ############################################################
- org.apache.juli.FileHandler.level = FINE
- org.apache.juli.FileHandler.directory = ${應用目錄}/logs
- org.apache.juli.FileHandler.prefix = error-debug.
- java.util.logging.ConsoleHandler.level = FINE
- java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
2). 重新啟動應用,指定目錄下會有一個error-debug.2013-07-07.log的錯誤日誌,或者錯誤日誌生成在jboss_stdout.log中。(日誌在Error listenerStart 到 Server startup in 9576 ms之間)
4. 結果
Tomcat log代碼
- 2013-7-29 9:58:11 org.apache.catalina.core.ApplicationContext log
- 信息: Initializing Spring root WebApplicationContext
- 2013-7-29 9:58:16 org.apache.catalina.core.StandardContext listenerStart
- 嚴重: Exception sending context initialized event to listener instance of class com.alibaba.citrus.webx.context.WebxContextLoaderListener
- org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:web/common/uris.xml]
- Offending resource: ServletContext resource [/WEB-INF/webx.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [web/common/uris.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionAttributes(Lorg/w3c/dom/Element;Ljava/lang/String;Lorg/springframework/beans/factory/config/BeanDefinition;Lorg/springframework/beans/factory/support/AbstractBeanDefinition;)Lorg/springframework/beans/factory/support/AbstractBeanDefinition;
- Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [web/common/uris.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionAttributes(Lorg/w3c/dom/Element;Ljava/lang/String;Lorg/springframework/beans/factory/config/BeanDefinition;Lorg/springframework/beans/factory/support/AbstractBeanDefinition;)Lorg/springframework/beans/factory/support/AbstractBeanDefinition;
- Caused by: java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseBeanDefinitionAttributes(Lorg/w3c/dom/Element;Ljava/lang/String;Lorg/springframework/beans/factory/config/BeanDefinition;Lorg/springframework/beans/factory/support/AbstractBeanDefinition;)Lorg/springframework/beans/factory/support/AbstractBeanDefinition;
- at com.alibaba.citrus.springext.util.SpringExtUtil.parseBeanDefinitionAttributes(SpringExtUtil.java:223)
- at com.alibaba.citrus.service.uribroker.impl.URIBrokerServiceDefinitionParser.doParse(URIBrokerServiceDefinitionParser.java:48)
- at org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser.parseInternal(AbstractSingleBeanDefinitionParser.java:81)
- at org.springframework.beans.factory.xml.AbstractBeanDefinitionParser.parse(AbstractBeanDefinitionParser.java:56)
- at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
- at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1123)
- at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1113)
- at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:133)
- at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:90)
- at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:468)
- at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:363)
5. 看到上述日誌,問題就很容易解決了,明顯是由於spring的類沖突導致,分析之後發現,是由於spring-2.0.7與spring-2.5.6的類沖突導致。
6. 如果上述不行,可以嘗試:
http://www.havenliu.com/web/298.html
http://grails.1312388.n4.nabble.com/Deployment-problems-td4628710.html
http://xpenxpen.iteye.com/blog/1545648
Tomcat啟動失敗問題解決