JAX-RS:服务资源订单

时间:2012-08-22 13:25:19

标签: java rest jax-rs

当前状态: 1.在我的web.xml中:

  <servlet-mapping>
   <servlet-name>javax.ws.rs.core.Application</servlet-name>
   <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>

2。我有两个服务资源,具有相同的@Path

@Path("path")
public class Resource1 {
  //methods annotated with @Path
}

@Path("path")
public class SubResource extends Resource1 {
  //same methods annotated with @Path (are inherited, and not overridden)
}

问题。有没有办法将所有请求重定向到“路径”到SubResource和Resource1?在目前的情况下,似乎应用服务器(在我的情况下是JBoss)自己决定采用哪种资源,并且它并不总是相同。

谢谢。

1 个答案:

答案 0 :(得分:0)

我选择的解决方案是使用不同的@Path。 SubResource现在具有更强的路径,具有更多的文字字符:

@Path("path")
public class Resource1 {
  //methods annotated with @Path
}

@Path("/path")//NOTE that the leading slash makes the difference
public class SubResource extends Resource1 {
  //same methods annotated with @Path (are inherited, not overridden)
}

更多关于JAX-RS中的“选择算法”here