用jersey做rest 應(yīng)用的時(shí)候,在resource類(lèi)中,聲明了一個(gè)如下的參數(shù):
@Path("/{type}/hits")
public class HitsResource {
private CacheType type;
public HitsResource(@PathParam("type") CacheType type) {
this.type = type;
}
...
,運(yùn)行的時(shí)候報(bào)錯(cuò):
Missing dependency for constructor public 。。。
經(jīng)查,發(fā)現(xiàn)jersey的開(kāi)發(fā)人員,說(shuō)了如下一句話(huà):
For 1.3 i turned on error checking for missing dependencies rather
than injecting null values.
明白了,因?yàn)槲业腃acheType是個(gè)枚舉類(lèi),這樣,如果{type}參數(shù)傳遞的值不在這個(gè)枚舉中的話(huà),就會(huì)導(dǎo)致程序出錯(cuò)。
于是改變了一下構(gòu)造方法,問(wèn)題解決:
public HitsResource(@PathParam("type") String type) {
this.type = CacheType.valueOf(type);
}