2007年12月25日

          在使用Spring相關產品時,你可能會碰到下面這種異常:
          Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
          這是異常的第一行,按以往的經驗,第一行應該就是問題所在,但是實際上,從這行來看你根本不知道錯在哪里。

          后面接下來的是:
          Error creating bean with name 'basicProcessingFilter'
          Cannot resolve reference to bean 'authenticationManager'
          while setting bean property 'authenticationManager';

          nested exception is Error creating bean with name 'authenticationManager'
          Cannot resolve reference to bean 'casAuthenticationProvider'
          while setting bean property 'providers' with key [0];

          nested exception is : Error creating bean with name 'casAuthenticationProvider'
          Cannot resolve reference to bean 'statelessTicketCache'
          while setting bean property 'statelessTicketCache';

          nested exception is: Error creating bean with name 'statelessTicketCache'
          Error setting property values;

          nested exception is
          nested PropertyAccessExceptions (1) are:
          PropertyAccessException 1:
          TypeMismatchException:

          Failed to convert property value of type [net.sf.ehcache.Cache]
          to required type [net.sf.ehcache.Ehcache] for property 'cache'

          Error creating bean with name 'authenticationManager'
          Cannot resolve reference to bean 'casAuthenticationProvider'
          while setting bean property 'providers' with key [0];

          nested exception is
          Error creating bean with name 'casAuthenticationProvider'
          Cannot resolve reference to bean 'statelessTicketCache' while setting bean property 'statelessTicketCache';

          nested exception is
          Error creating bean with name 'statelessTicketCache'
          Error setting property values;

          nested exception is
          nested PropertyAccessExceptions (1) are:
          PropertyAccessException 1: org.springframework.beans.TypeMismatchException:
          Failed to convert property value of type [net.sf.ehcache.Cache]
          to required type [net.sf.ehcache.Ehcache] for property 'cache'

          Error creating bean with name 'casAuthenticationProvider'
          Cannot resolve reference to bean 'statelessTicketCache'
          while setting bean property 'statelessTicketCache';

          nested exception is
          Error creating bean with name 'statelessTicketCache'
          Error setting property values;

          nested exception is PropertyAccessExceptionsException;
          nested PropertyAccessExceptions (1) are:
          PropertyAccessException 1:TypeMismatchException:
          Failed to convert property value of type [net.sf.ehcache.Cache]
          to required type [net.sf.ehcache.Ehcache] for property 'cache'

          Error creating bean with name 'statelessTicketCache'
          Error setting property values;

          nested exception is PropertyAccessExceptionsException;
          nested PropertyAccessExceptions (1) are:
          PropertyAccessException 1: org.springframework.beans.TypeMismatchException:
          Failed to convert property value of type [net.sf.ehcache.Cache]
          to required type [net.sf.ehcache.Ehcache] for property 'cache'

          PropertyAccessExceptionsException;
          nested PropertyAccessException details (1) are:
          PropertyAccessException 1:
          ypeMismatchException:
          Failed to convert property value of type [net.sf.ehcache.Cache]
          to required type [net.sf.ehcache.Ehcache] for property 'cache'

          上面的內容是我將重復信息去掉,并分塊后的結果。

          從報錯機制可以看出來,spring出現異常不同于普通的java異常,我們查異常的習慣一般是關注第一行,但是sping恰恰相反,要在sping中查錯,你必須分解他,因為spring的嵌套層次比較多,它報錯是從最高層報起,然后逐層往下,每個層次都會要報錯,直到最終出錯的地方,因此查sping的錯必須逐層分解到最底層,那里才是真正出錯的地方。

          OK,現在看出來了,真正錯誤的原因是:
          Failed to convert property value of type [net.sf.ehcache.Cache]
          to required type [net.sf.ehcache.Ehcache] for property 'cache'

          我出現這個錯誤的原因是使用了Acegi 1.0.5,它本身自帶了ehcache 1.2.4.jar
          但是我同時還使用了hibernate3.1,從Eclipse導入hibernate3.1時,將會導入ehcache 1.1.jar,因為hibernate本身也要使用EHCache,但是版本不同。

          posted @ 2007-12-25 10:02 Exiler 閱讀(3201) | 評論 (0)編輯 收藏


          2007年12月24日

          公司做了套由JMS做消息隊列,從JMS取出對象后轉交給RTX服務器發送RTX消息的機制。
          前幾天出現重大BUG:消息不發送。

          經過兩天的測試發現了癥結所在:
          我們通過RTX服務器發送RTX消息的機制是通過向一個URL后面加參數來實現的,而這個請求URL,在RTX服務器上默認超時時間設置為0,即永不超時,同時此服務器設置的同一個連接兩次發送消息的最短間隔時間為15毫秒。
          因為我們網管的失誤,打開了8012端口,此端口為RTX服務器接收消息的端口,致使開發環境中的消息能夠發送到工作環境的服務器,使得RTX服務器接收的并發量出現瞬時過大現象,RTX服務器判斷為DDOS攻擊,因此拒絕服務,此服務器拒絕服務的方式為不返回任何值。
          同時,因為設置的超時時間為0,因此后繼的消息因為前面的并未拋出超時異常也未發送完成,所以積壓在JMS隊列中,造成了消息發送失敗的現象。

          一開始我一直在找JMS的原因,因為曾經在某處看到過JMS服務器并不穩定的文章,但是我在測試過程中發現,JMS還是很強大的,在消息積壓的時候,其隊列中最高曾積壓了4000多條消息,仍然能夠繼續工作,我使用的是ActiveMQ+Tomcat6.10。

          希望能給碰到類似JMS消息積壓現象的朋友一點啟示,從JMS消息不能正常取出入手,或許會有收獲!

          posted @ 2007-12-24 09:33 Exiler 閱讀(3965) | 評論 (5)編輯 收藏


          2007年12月9日

          類似Hibernate異常:
          %%%% Error Creating SessionFactory %%%%
          org.hibernate.MappingException: Could not read mappings from resource:
          這種錯誤出現的情況只有在人為改動了Hibernate生成的文件的時候出現。

          情況有兩種
          1:hibernate.cfg.xml中,屬性<mapping resource="./Permission.hbm.xml" />里面"./Permission.hbm.xml"所指定的路徑不正確,即改動了生成實體的配置文件的位置。
          2:Permission.hbm.xml中,<class name="db_DAO.Permission" table="ACEGI_PERMISSION" schema="POSTTEST">其中屬性class name="db_DAO.Permission"指定的Permission類名錯誤,即:改動了生成實體類的類名或者包名。

          如果上述兩種情況改動后仍然報錯,clean一下項目后OK

          posted @ 2007-12-09 15:08 Exiler 閱讀(8549) | 評論 (4)編輯 收藏


          2007年4月21日

          /**
           * @author Solo
           *
           * 很久以前寫的一道題目,昨天翻出來看了看,都有些忘記了,花了1個小時補上了注釋
           * 對于學習在Java中使用正則表達式有點幫助
           * 將一個保存有ip地址與地區對照關系的文本文件導入到數據庫時,
           * 應該將其中的某些空格替換成逗號(,),即對于如下格式的文本文件內容:
           * 起始IP 結束IP 地區
           * ---------------------------------------------------------------
           * 61.54.231.245 61.54.231.245 河南省安陽市 新世紀網吧
           * 61.54.231.246 61.54.231.246 河南省安陽市 未知地區
           * 61.54.231.9 61.54.231.247 河南省安陽市 紅日網吧
           * 61.54.231.248 61.54.231.248 河南省安陽市 安陽師范學院
           * 61.54.231.249 61.54.231.249 河南省安陽市 黑蜘蛛網吧(師范學院附近)
           * 應轉換成下面的這種格式:
           * 61.54.231.245,61.54.231.245,河南省安陽市 新世紀網吧
           * 61.54.231.246,61.54.231.246,河南省安陽市 未知地區
           * 61.54.231.247,61.54.231.247,河南省安陽市 紅日網吧
           * 61.54.231.248,61.54.231.248,河南省安陽市 安陽師范學院
           * 61.54.231.249,61.54.231.249,河南省安陽市 黑蜘蛛網吧(師范學院附近)
           * 任務:
           * 閱讀String.replaceAll方法的幫助,以及它提供的相關超鏈接,
           * 了解該方法的用法后,編寫一個java程序來自動實現上面的正則表達式替換,
           * 將a.txt替換后的結果保存到b.txt文件中。
           * 另外,我們在實現ip地區查詢系統時,使用的是類似如下的sql語法:
           * select 地區 from ip表 where 用戶ip>起始IP and 用戶ip<結束ip
           * 通過這條sql語句就可以查詢出用戶ip所對應的地區結果。由于用戶ip與起始
           * ip和結束ip的比較屬于字符串比較,如果用戶ip為9.1.1.1,那么它與
           * 61.54.231.245比較的結果就是前者大于后者,因為用戶ip的第一個字符“9”
           * 大于61.54.231.245中的第一個字符“6”。
           * 現在請你想出一種解決辦法,讓上面的sql語句能夠返回正確結果。
           * 請按這種思路在你的程序中增加進行這種改變的正則表達式替換。
           */

          import java.io.*;
          import java.util.regex.*;

          public class Ip
          {
              private static void fileIO(File f)
              {
                  String strLine;
                 
                  // 調用執行本程序的操作系統的標準換行符,意味著跨平臺
                  String line = System.getProperty("line.separator");
                  try
                  {
                      // 輸入流
                      FileInputStream fis = new FileInputStream(f);
                      InputStreamReader isr = new InputStreamReader(fis);
                      BufferedReader br = new BufferedReader(isr);
                     
                      // 輸出流
                      FileOutputStream fos = new FileOutputStream("c://b.txt");
                      OutputStreamWriter osw = new OutputStreamWriter(fos);
                      BufferedWriter bw = new BufferedWriter(osw);
                     
                      /*
                       * 創建一個模式對象, 模式中編輯的正則表達式匹配分別是(200-249|250-255|001-199) 以匹配一個IP地址
                       */
                      Pattern pattern = Pattern
                              .compile("((2[0-4]d|25[0-5]|[01]?dd?).){3}(2[0-4]d|25[0-5]|[01]?dd?)");
                     
                      // 聲明模式適配器
                      Matcher matcher;
                     
                      // 循環讀取文件中的每一行
                      while ((strLine = br.readLine()) != null)
                      {
                          /*
                           * String調用replaceAll方法匹配一個正則表達式找到一個位置,然后替換成逗號
                           */
                          strLine = strLine.replaceAll("(?<=d)s+", ",");
                          
                          // 用適配器加載一行字符串,并匹配模式
                          matcher = pattern.matcher(strLine);
                         
                          // 如果在一行中能找到匹配的字符串則循環
                          while (matcher.find())
                          {
                              // 取一行中第一個能匹配的子字符串
                              String buf = matcher.group();
                             
                              // 以"."分割成數字,然后分別補零,再合并
                              strLine = matcher.replaceAll(change(buf));
                            
                              // 輸入一行到文件,但不包括換行符
                              bw.write(strLine);
                             
                              // 輸入行分割符,即換行符
                              bw.write(line);
                          }
                      }
                     
                      // 關閉輸入流
                      br.close();
                     
                      // 關閉輸出流
                      bw.close();
                  }
                  // 捕獲原始文件未找到異常
                  catch (FileNotFoundException e)
                  {
                      System.out.println("原始文件未找到");
                  }
                  // 捕獲IO異常
                  catch (IOException e)
                  {
                      e.printStackTrace();
                  }

              }
             
              // 此方法用來接收一個分割出來的一個數字,將不足3位的補零后返回
              private static String fill(String str)
              {
                  // 不足3位的補零
                  while (str.length() < 3)
                  {
                      str = '0' + str;
                  }
                 
                  // 返回補零后的字符串
                  return str;
              }
             
              private static String change(String buf)
              {
                  // 緩沖字符串
                  String temp;
                 
                  // 結果返回字符串
                  String ret;
                 
                  // 以"."分割,存入字符串數組
                  String[] str = buf.split(".");
                 
                  // 第一個數字不需要在前面加"."
                  ret = fill(str[0]);
                 
                  // 從第2個數字開始,給每個數字前面分別再加上".",并且不足的補零
                  for (int i = 1; i < str.length; i++)
                  {
                      // 調用fill方法給不足3位的數字補零
                      temp = fill(str[i]);
                     
                      // 每個數字加點后從新組裝成一個
                      ret = ret + "." + temp;
                  }
                  // 返回結果字符串
                  return ret;
              }
             
              // 程序入口
              public static void main(String[] args)
              {
                  // 讀原始文件
                  File f = new File("c://a.txt");
                 
                  // 將原始文件傳入fileIO方法,按要求加工
                  fileIO(f);
              }
          }

          posted @ 2007-04-21 01:21 Exiler 閱讀(1149) | 評論 (0)編輯 收藏


          僅列出標題  

          posts - 3, comments - 32, trackbacks - 0, articles - 3

          Copyright © Exiler

          主站蜘蛛池模板: 金门县| 达孜县| 宁明县| 兴宁市| 集贤县| 成武县| 从江县| 郧西县| 松原市| 南涧| 柞水县| 田东县| 武宁县| 马公市| 云阳县| 额济纳旗| 安西县| 繁昌县| 紫阳县| 靖江市| 西林县| 定襄县| 宜宾县| 德令哈市| 海阳市| 吴川市| 托里县| 赣榆县| 湖口县| 兴山县| 潮州市| 焦作市| 东安县| 鲁山县| 平邑县| 永修县| 正镶白旗| 龙里县| 保康县| 北宁市| 大兴区|