隨筆 - 0, 文章 - 264, 評論 - 170, 引用 - 0
          數據加載中……

          Missing dependency for constructor public

          用jersey做rest 應用的時候,在resource類中,聲明了一個如下的參數:
          @Path("/{type}/hits")
          public class HitsResource {
                private CacheType type;
               
                public HitsResource(@PathParam("type") CacheType type) {
                      this.type = type;
                }
          ...
          ,運行的時候報錯:
          Missing dependency for constructor public 。。。

          經查,發現jersey的開發人員,說了如下一句話:
          For 1.3 i turned on error checking for missing dependencies rather  
          than injecting null values.
          明白了,因為我的CacheType是個枚舉類,這樣,如果{type}參數傳遞的值不在這個枚舉中的話,就會導致程序出錯。

          于是改變了一下構造方法,問題解決:
                public HitsResource(@PathParam("type") String type) {
                      this.type = CacheType.valueOf(type);
                }

          posted on 2011-11-28 19:38 小一敗涂地 閱讀(393) 評論(0)  編輯  收藏 所屬分類: jersery、struts等web框架相關

          主站蜘蛛池模板: 绥阳县| 西藏| 泰来县| 安新县| 琼海市| 西平县| 突泉县| 博野县| 嘉禾县| 贞丰县| 巧家县| 扶风县| 民乐县| 中西区| 盖州市| 安新县| 五河县| 亳州市| 灯塔市| 房山区| 罗江县| 保康县| 合肥市| 北京市| 剑川县| 长葛市| 手游| 广东省| 沧州市| 武隆县| 大丰市| 大荔县| 太仆寺旗| 黔江区| 台前县| 梓潼县| 离岛区| 平乡县| 土默特右旗| 台南市| 迭部县|