简体   繁体   中英

JAX-RS: Service Resource order

currect state: 1. in my web.xml:

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

2. I have two service resources, with the same @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)
}

Question. Is there a way to redirect all requests to "path" to the SubResource, and to the Resource1 ? In the current situation, it seems that the application server (JBoss in my case) decides by itself which resource to take, and it is not always the same.

Thank you.

The solution I've chosen is to use different @Path's. The SubResource has now a stronger Path, by having more literal characters:

@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)
}

More on the the "Selection Algorithms" in JAX-RS here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM