2015異常問題解決方案經驗總結(一)
1. could not find java.dll
C:\Users\admin>java
Error: Registry key 'Software\JavaSoft\JavaRuntime
has value '1.6', but '1.8' is required.
Error: could not find java.dll
Error: Could not find Java SE RuntimeEnvironment.
問題原因:機器上裝了多個版本的JDK,或者曾經裝過不同版本的JDK,解除安裝不完全
解決方法:新增JAVA_HOME環境變數
新增JAVA_HOME環境變數,而且一定要放在系統變數裡,不要用使用者變數。
2. liquibase.exception.ValidationFailedException:Validation Failed:
Error occurred while trying to get theupdates needed for the database. Validation Failed: 1 change sets check sumliquibase-update-to-latest.xml::200902142213::ewolodzko is now:3:ace82a1ecb3a0c3246e39f0bebe38423
java.lang.RuntimeException: Error occurredwhile trying to get the updates needed for the database. Validation Failed:
1 change sets check sum
liquibase-update-to-latest.xml::200902142213::ewolodzko is now:3:ace82a1ecb3a0c3246e39f0bebe38423
atorg.openmrs.util.DatabaseUpdater.getUnrunDatabaseChanges(DatabaseUpdater.java:631)
atorg.openmrs.util.DatabaseUpdater.getUnrunDatabaseChanges(DatabaseUpdater.java:590)
atorg.openmrs.util.DatabaseUpdater.updatesRequired(DatabaseUpdater.java:262)
atorg.openmrs.web.Listener.setupNeeded(Listener.java:170)
atorg.openmrs.web.Listener.contextInitialized(Listener.java:142)
atorg.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4210)
atorg.apache.catalina.core.StandardContext.start(StandardContext.java:4709)
atorg.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:802)
atorg.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
atorg.apache.catalina.core.StandardHost.addChild(StandardHost.java:583)
atorg.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
atorg.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
atorg.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
atorg.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
atorg.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
atorg.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1068)
atorg.apache.catalina.core.StandardHost.start(StandardHost.java:822)
atorg.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060)
atorg.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
atorg.apache.catalina.core.StandardService.start(StandardService.java:525)
atorg.apache.catalina.core.StandardServer.start(StandardServer.java:759)
atorg.apache.catalina.startup.Catalina.start(Catalina.java:595)
atsun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
atjava.lang.reflect.Method.invoke(Method.java:597)
atorg.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
atorg.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by:liquibase.exception.ValidationFailedException: Validation Failed:
1 change sets check sum
liquibase-update-to-latest.xml::200902142213::ewolodzko is now:3:ace82a1ecb3a0c3246e39f0bebe38423
atliquibase.changelog.DatabaseChangeLog.validate(DatabaseChangeLog.java:141)
atliquibase.Liquibase.listUnrunChangeSets(Liquibase.java:625)
atorg.openmrs.util.DatabaseUpdater.getUnrunDatabaseChanges(DatabaseUpdater.java:619)
...28 more
Caused by: java.lang.Exception: Unable toget a connection to the database. Pleasecheck your openmrs runtime properties file and make sure you have the correctconnection.username and connection.password set
atorg.openmrs.util.DatabaseUpdater.getLiquibase(DatabaseUpdater.java:368)
atorg.openmrs.util.DatabaseUpdater.getUnrunDatabaseChanges(DatabaseUpdater.java:617)
...28 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:Could not create connection to database server. Attempted reconnect 3 times.Giving up.
atsun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
atjava.lang.reflect.Constructor.newInstance(Constructor.java:513)
atcom.mysql.jdbc.Util.handleNewInstance(Util.java:406)
atcom.mysql.jdbc.Util.getInstance(Util.java:381)
atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
atcom.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2364)
atcom.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:773)
atcom.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:46)
atsun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
atsun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
atjava.lang.reflect.Constructor.newInstance(Constructor.java:513)
atcom.mysql.jdbc.Util.handleNewInstance(Util.java:406)
atcom.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
atcom.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
atjava.sql.DriverManager.getConnection(DriverManager.java:582)
atjava.sql.DriverManager.getConnection(DriverManager.java:185)
atorg.openmrs.util.DatabaseUpdater.getConnection(DatabaseUpdater.java:427)
atorg.openmrs.util.DatabaseUpdater.getLiquibase(DatabaseUpdater.java:365)
...29 more
Caused by:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database'openmrs'
錯誤原因:不是第一次執行openmrs
解決方法:刪除執行時配置檔案
3. get方式提交中文亂碼
解決方法:在tomcat下指定URL編碼格式為UTF-8
配置tomcatconf/server.xml
<Connectorexecutor="tomcatThreadPool"
port="8080"protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="30000"
maxKeepAliveRequests="1"
maxHttpHeaderSize="8192"
URIEncoding="UTF-8"
enableLookups="false"
acceptCount="100"
redirectPort="8443"
/>
如果使用的是Eclipse,因為Eclipse執行的是虛擬的tomcat伺服器,原始的tomcat修改後需要重新配置到Eclipse,或者直接到虛擬tomcat下也做修改。
4. Tomcat啟動超時異常unable to start within 45 seconds
ServerTomcat v6.0 Server at localhost was unable to start within 45 seconds. If theserver requires more time, try increasing the timeout in the server editor
異常原因:Tomcat預設啟動最大時長是45秒,當啟動時間超過45秒回丟擲此異常
解決方法:修改預設啟動時常
如果你用的是eclipse,雙擊tomcat伺服器,開啟一個檢視,右邊有個times out,點開,把45改成450或者更大即可
5. Tomcat啟動: Errorstarting static Resources
一般來說出現這種錯誤是由於你在MyEclipse或Eclipse中刪除了某個專案後,沒有將Tomcat-6.x\conf\server.xml相關修改完全,才引起了這個問題
解決
第一步 清空Tomcat-6.x目錄下的work目錄;
第二步再把server.xml的沒有用的<Context>標籤都刪除或者註釋掉;
第三步 最後再將conf目錄下的Catalina目錄下的localhost內的所有檔案都刪除。
6. SetPropertiesRule]{Server/Service/Engine/Host/Context}Setting property 'source'
通過Eclipse整合Tomcat6啟動時報以下警告資訊:
SetPropertiesRule]{Server/Service/Engine/Host/Context}Setting property 'source' to 'org.eclipse.jst.jee.server:webtest' did not finda matching property.
這是因為我們在eclipse下,通過tomcat部署web工程時,會在tomcat的配置檔案server.xml中會自動生成一個關於該web工程的配置資訊,類似於下面的東西:
<Context docBase="webtest" path="/webtest"reloadable="true" source="org.eclipse.jst.jee.server:webtest"/>
而預設情況下,server.xml的 Context元素不支援名稱為source的屬性,所以會發出警告。
解決
關閉tomcat,雙擊eclipse下tomcat伺服器,在出來的Tomcat server at localhost頁面中找到server options選項,選中其中的選項”Publish modualcontexts to separat XML files“,ctr+s 儲存,啟動tomcat。
這樣專案的配置資訊會被放到conf\Catalina\localhost目錄下的單獨xml檔案中
7. SyntaxError: unterminatedstring literal
無端接的字串,出現該錯誤的原因是字串的雙引號或單引號中間有違反json規範的特殊字元,如回車,換號,單引號,雙引號等
解決方法:刪除字串中非法字元
8. java.lang.OutOfMemoryError:PermGen space
網上查詢可知該異常產生的原因是JVM預設分配的4M執行空間過小,J2EE專案載入的類過多,造成記憶體溢位。
解決方案為:通過新增引數增加分配給JVM的記憶體空間
-Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m
網上的解決方案多半是針對純Tomcat的情況,並非通過Eclipse啟動的Tomcat。
或者修改eclipse.ini配置檔案,不過這些方法都不適合Eclipse執行Tomcat丟擲該異常的情況。
修改eclipse.ini配置檔案增大的是Ecipse開發平臺本身執行的JVM的空間,並非Eclipse啟動Tomcat的記憶體空間。
正確的方法是,點選“Run” – “Run Configurations…”,選中Tomcat Server,進入Arguments分頁,在VM arguments中加入提升初始分配空間的引數,如下圖所示:
9. InvalidDataAccessResourceUsageException
org.springframework.dao.InvalidDataAccessResourceUsageException:could not insert:
Caused by: org.hibernate.exception.SQLGrammarException: could notinsert:
異常原因:資料庫表使用了mysql的關鍵字,請檢查修改表字段。
解決:檢查修改表字段
10. chrome通過file協議瀏覽html程式碼時,傳送的ajax請求本地檔案,會報跨域錯誤
XMLHttpRequest cannot loadfile:///E:/webs/extJS/ext-3.3.0/examples/csdn/combobox.txt?_dc=1414738973999.Cross origin requests are only supported for protocol schemes: http, data,chrome-extension, https, chrome-extension-resource.
解決
解決辦法是給chrome新增啟動引數:--allow-file-access-from-files ,這樣本地ajax請求就不會報跨域錯誤了。(注意如果給chrome新增多個啟動引數,每個啟動引數“--”之前要有空格隔開,如"C:\ProgramFiles\Google\Chrome\Application\chrome.exe"--enable-file-cookies--allow-file-access-from-files)
具體方法:在瀏覽器快捷方式上右鍵-屬性-快捷方式-目標 如下圖: