Missing dependency for constructor public
用jersey做rest 應用的時候,在resource類中,聲明了一個如下的參數(shù):
@Path("/{type}/hits")
public class HitsResource {
private CacheType type;
public HitsResource(@PathParam("type") CacheType type) {
this.type = type;
}
...
,運行的時候報錯:
于是改變了一下構造方法,問題解決:
public class HitsResource {
private CacheType type;
public HitsResource(@PathParam("type") CacheType type) {
this.type = type;
}
...
,運行的時候報錯:
Missing dependency for constructor public 。。。
經(jīng)查,發(fā)現(xiàn)jersey的開發(fā)人員,說了如下一句話:
明白了,因為我的CacheType是個枚舉類,這樣,如果{type}參數(shù)傳遞的值不在這個枚舉中的話,就會導致程序出錯。經(jīng)查,發(fā)現(xiàn)jersey的開發(fā)人員,說了如下一句話:
For 1.3 i turned on error checking for missing dependencies rather
than injecting null values.
than injecting null values.
于是改變了一下構造方法,問題解決:
public HitsResource(@PathParam("type") String type) {
this.type = CacheType.valueOf(type);
}
this.type = CacheType.valueOf(type);
}
posted on 2011-11-28 19:38 小一敗涂地 閱讀(387) 評論(0) 編輯 收藏 所屬分類: jersery、struts等web框架相關