最近工作很忙,開發任務很大,遇到的問題也千奇百怪,現總結如下,希望能夠幫到各位.
(1)設定struts 的預設action.目的是通路http://localhost:8080/shop_goods ,自動跳轉到http://localhost:8080/shop_goods/logininput.action
于是我在struts 配置檔案中增加了

<default-action-ref name="logininput" />
但是始終達不到目的,檢查了好多遍,文法都沒有問題,在網上看了好多資料,配置完全一樣,但是還是跳轉不到預設action.
最後才發現有存在某種問題或陰謀.
我在web.xml中配置struts過濾器如下:
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter
</filter-class>
</filter>
<filter-mapping>
<url-pattern>*.action</url-pattern>
</filter-mapping>
後來我把紅色部分改為/*就好了.
(2)ssh項目,啟動tomcat時報錯
詳細錯誤資訊:

org.springframework.beans.factory.beancreationexception: error creating bean with name 'sessionfactory' defined in class path resource [com/tdr/mbs/endpoint/config/core/dbenv.xml]: invocation of init method failed; nested exception is org.hibernate.duplicatemappingexception: duplicate class/entity mapping com.wh.service.loginservice
意思就是tomcat啟動時發現有兩份com.wh.service.loginservice ,然後它就不知道到底要加載哪個class了.
為什麼會這樣呢?
我進到tomcat部署的項目的lib下一看,發現有兩個不同版本的jar包:wh_service-0.0.1.jar,wh_service-0.0.2.jar
因為我的項目是使用maven建構,依賴的另一個子產品也是我們開發的,而且在不斷更新.從0.0.1更新到0.0.2時,原來的jar包沒有删除.
此時如何解決呢?
(1)直接進入tomcat 部署的項目目錄lib下,把舊版本的jar包删除;
(2)先把項目從eclipse中remove,
然後clean,然後在add到eclipse的tomcat下
最後再啟動tomcat.
(3)maven 打包釋出時,發現最新的代碼沒有打在包裡面
明明已經是最新的代碼了,為什麼沒有打進去呢?
原因是項目的src\main\webapp\web-inf目錄下有一個classes檔案夾,裡面的class等檔案還是舊的,maven打包時沒有自動替換它
解決方法:直接删除上述classes目錄.
(4)終于體會了logger日志(使用日志架構如log4j)的好處
之前和同僚聯調項目時出現了問題,他通路我的web服務,總是傳回空白,突然想到是ip限制,于是我把它的ip加到了白名單.但是還是傳回空,為什麼呢?
看tomcat 日志檔案(使用log4j),并沒有發現exception啊,真是奇怪了.
當時已經絕望了,又看了一眼日志,發現有warning級别的日志,一細看終于發現了原因,原來是他請求時content-type不對,應該是application/json,而他傳的是text/xml;charset=utf-8,
使用hibernate 映射檔案.hbm.xml自動建立表,但是無法建立,不知道為什麼,
後來才發現hbm.xml中多了一個屬性,即hbm.xml中配置一個column 實體類中沒有.
之前的總結:
http://hw1287789687.iteye.com/blog/2034439
http://hw1287789687.iteye.com/blog/2019501
http://hw1287789687.iteye.com/blog/2005427
http://hw1287789687.iteye.com/blog/2002293
http://hw1287789687.iteye.com/blog/1997640