隨筆 - 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 小一敗涂地 閱讀(392) 評論(0)  編輯  收藏 所屬分類: jersery、struts等web框架相關

          主站蜘蛛池模板: 武宣县| 米林县| 南木林县| 英山县| 泾源县| 沙坪坝区| 闽侯县| 铜鼓县| 鹿邑县| 南江县| 淅川县| 同仁县| 武邑县| 湘潭市| 汝南县| 上杭县| 东乌| 大宁县| 香河县| 如皋市| 黑山县| 平泉县| 吐鲁番市| 都江堰市| 米易县| 方正县| 榆中县| 尉犁县| 鄂尔多斯市| 大宁县| 增城市| 荃湾区| 建德市| 巴南区| 鄂尔多斯市| 高州市| 盐边县| 旬邑县| 金秀| 右玉县| 延吉市|