项目服务端:Tomcat6.0.41
选用数据库:Mysql5.6.17
JDK环境:1.6.37
运行系统:Windows server 2008(64bit)
===========================================================
部署好Tomcat项目,运行startup.bat.提示错误(节选):
……
2014-8-20 15:59:13 org.apache.cxf.endpoint.ServerImpl initDestination
信息: Setting the server‘s publish address to be /pay
2014-8-20 15:59:13 org.apache.cxf.jaxrs.provider.ProviderFactory setDefaultProvider
信息: Problem with setting the default provider org.apache.cxf.jaxrs.provider.JSONProviderorg/codehaus/jettison/mapped/TypeConverter
2014-8-20 15:59:14 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2014-8-20 15:59:14 org.apache.catalina.core.StandardContext start
严重: Context [/xGameServer] startup failed due to previous errors
2014-8-20 15:59:14 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [/xGameServer] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
2014-8-20 15:59:14 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xGameServer] appears to have started a thread named [Thread-2] but has failed to stop it. This is very likely to create a memory leak.
2014-8-20 15:59:14 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xGameServer] appears to have started a thread named [Thread-3] but has failed to stop it. This is very likely to create a memory leak.
2014-8-20 15:59:14 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xGameServer] appears to have started a thread named [Thread-5] but has failed to stop it. This is very likely to create a memory leak.
2014-8-20 15:59:14 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [/xGameServer] appears to have started a thread named [NioSocketAcceptor-1-idleStatusChecker] but has failed to stop it. This is very likely to create a memory leak.
……
===========================================================
在这里,需要吐槽tomcat的错误提示。因为它的错误提示很表面。单纯看这错误提示内容,红色部分内容,我们简单地理解为web项目启动了JDBC驱动程序,但是在web项目停止时,JDBC驱动程序注销失败。为了防止内存泄漏,该驱动程序被强制干掉了....然后就引发了后面一大片的蓝色部分内容:提示好多好多线程被启动了,吓唬你不关闭线程的话可能会导致程序内存泄漏(也就是可能会导致程序挂掉)。
这个时候,你需要这样一份文件(Tomcat不自带):
============================文件内容===============================
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 = ${catalina.base}/logs
org.apache.juli.FileHandler.prefix = error-debug.
java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
============================文件内容===============================
新建一个记事本,将上面绿色字体内容C-V操作,然后保存文件为logging.properties
OK,完成。
将这份文件拷贝到部署项目目录的\WEB-INF\Classes目录下。
e.g.假设我的部署项目目录名为:HeHe
把文件放在:webapps\HeHe\WEB-INF\Classes\logging.properties
然后再次运行tomcat的startup.bat,界面显示的错误不变,我们要查看的是Tomcat根目录下的logs目录(例如:E:\tomcat6\logs),有一份文本文件:error-debug.xxxx-xx-xx
回到我们项目运行失败的问题上,从error-debug.xxxx-xx-xx文件中可以看到,最根本报错的地方是:
===========================================================
2014-8-20 16:25:46 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
2014-8-20 16:25:51 org.apache.cxf.endpoint.ServerImpl initDestination
信息: Setting the server‘s publish address to be /pay
2014-8-20 16:25:51 org.apache.cxf.jaxrs.provider.ProviderFactory setDefaultProvider
信息: Problem with setting the default provider org.apache.cxf.jaxrs.provider.JSONProviderorg/codehaus/jettison/mapped/TypeConverter
2014-8-20 16:25:52 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class com.linyun.xgame.listener.InitSystemListener
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1130];
--- The error occurred in com/linyun/xgame/dao/sqlmap/Global.xml.
--- The error occurred while executing query.
--- Check the SELECT VALUE_INT AS valueInt, VALUE_STR AS valueStr,PRO_1 AS pro_1,PRO_2 AS pro_2,PRO_3 AS pro_3,PRO_4 AS pro_4,PRO_5 AS pro_5,PARA_ID AS paraID,PARA_DESC AS paraDesc,ISCLIENT AS isclient FROM T_GLOBAL .
--- Check the SQL Statement (preparation failed).
--- Cause: java.sql.SQLException: null, message from server: "Host ‘iZ23e08c18sZ‘ is not allowed to connect to this MySQL server"; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/linyun/xgame/dao/sqlmap/Global.xml.
--- The error occurred while executing query.
--- Check the SELECT VALUE_INT AS valueInt, VALUE_STR AS valueStr,PRO_1 AS pro_1,PRO_2 AS pro_2,PRO_3 AS pro_3,PRO_4 AS pro_4,PRO_5 AS pro_5,PARA_ID AS paraID,PARA_DESC AS paraDesc,ISCLIENT AS isclient FROM T_GLOBAL .
--- Check the SQL Statement (preparation failed).
--- Cause: java.sql.SQLException: null, message from server: "Host ‘iZ23e08c18sZ‘ is not allowed to connect to this MySQL server"
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
……
===========================================================
红色部分就把问题暴露出来了:数据库访问失败了...
访问数据库失败原因:Mysql默认是不可以通过远程机器访问的,所以我们需要开启远程访问。
解决方式(网上有提供其他方法,这里只说我选择的方式):
1.进入到Mysql控制台。运行-CMD,一直cd进入到Mysql的bin目录,输入:mysql -uroot -p
2.提示输入mysql的访问密码。
3.输入密码后输入:use mysql;(记得分号)
4.输入:show tables;
5.输入:select host from user;
6.输入:update user set host = ‘%‘ where user = ‘root‘ and host = ‘loaclhost‘;
OK。。。大功告成。。。如果执行命令没出错的话,再次运行startup.bat,这回就可以运行妥妥的。