小编vpi*_*tts的帖子

使用Jersey在Restful Resource中使用多个@PathParams时没有发现注入源错误

我正在使用Rest/Jersey和Tomcat 7进行一个简单的Restful Web服务.如果我的所有Path都包含一个参数,那么工作正常.如果我包含一个使用多个参数的参数,当我尝试点击我的资源类支持的任何资源路径时,我会遇到"找不到注入源"错误 - 即使是之前正在工作的那些资源路径.如果我注释掉那段特定代码,那么我的所有其他路径都会按预期工作.但如果我取消注释掉那段代码,我就无法使用任何一条路径.

这是我的代码片段:

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

// get all the information about a specific item
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public String getItem(@PathParam("id") String itemId)
{
    String answer = "{";
    answer += "\"itemid\":\"" + itemId + "\",";
    answer += "\"type\":0,";
    answer += "\"sector\":322948,";
    answer += "\"created\":53249098220";
    answer += "}";

    return answer;
}

// if I comment out this method, all is fine; 
// if I leave it in, error is thrown when …
Run Code Online (Sandbox Code Playgroud)

java rest jax-rs jersey jersey-2.0

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×1

jax-rs ×1

jersey ×1

jersey-2.0 ×1

rest ×1