3

私は、Jersey と Tomcat7 を使用して安静な実装をしています。私の campher.rest パッケージには、RegionService、ClientService、NoteService という 3 つのリソースが定義されています。

TestResource という別のリソースを追加しようとすると、Tomcat が起動すると、次のエラーが表示されます。/{notes} が /{test} と競合する理由がわかりません?? 助けてください、私の髪はあなたに感謝します。

Aug 22, 2012 2:23:39 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class campher.rest.NoteService
  class campher.rest.ClientService
  class campher.rest.TestResource
  class campher.rest.RegionService
Aug 22, 2012 2:23:39 AM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
Aug 22, 2012 2:23:40 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.12 02/15/2012 04:51 PM'
Aug 22, 2012 2:23:40 AM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
  SEVERE: Conflicting URI templates. The URI template /{test} for root resource class campher.rest.TestResource and the URI template /{notes} transform to the same regular expression /([^/]+?)(/.*)?
Aug 22, 2012 2:23:40 AM org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable

これら 4 つのサービスのスケルトン実装を次に示します。

package campher.rest;
@Path("regions")
public class RegionService {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response regions() {}

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public Region addRegion(Region region){}

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public Region updateRegion(Region region){}

    @GET @Path("{id}")  
    @Produces(MediaType.APPLICATION_JSON)
    public Response getRegion(@PathParam("id") long id) {}

    @DELETE @Path("{id}")   
    @Produces(MediaType.APPLICATION_JSON)
    public Response deleteRegion(@PathParam("id") long id) {}

    @GET @Path("{id}/clients")  
    @Produces(MediaType.APPLICATION_JSON)
    public Response getClients(@PathParam("id") long id) {}
}



package campher.rest;
@Path("clients")
public class ClientService {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response clients() {}

    @GET @Path("{id}")  
    @Produces(MediaType.APPLICATION_JSON)
    public Response getClient(@PathParam("id") long id) {}

    @GET @Path("{id}/notes")    
    @Produces(MediaType.APPLICATION_JSON)
    public Response getNotes(@PathParam("id") long id) {}

    @GET @Path("{id}/alerts")   
    @Produces(MediaType.APPLICATION_JSON)
    public Response getAlerts(@PathParam("id") long id) {}

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public Client addClient(Client client){}

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public Client updateClient(Client client){}

    @DELETE @Path("{id}")   
    @Consumes(MediaType.APPLICATION_JSON)
    public Response deleteClient(@PathParam("id") long id){}
}

package campher.rest;
@Path("{notes}")
public class NoteService {  
    @GET @Path("{id}")  
    @Produces(MediaType.APPLICATION_JSON)
    public Response getNote(@PathParam("id") long id) {}

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public Note addNote(Note note){}

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public Note updateNote(Note note){}

    @DELETE @Path("{id}")   
    @Produces(MediaType.APPLICATION_JSON)
    public Response deleteNote(@PathParam("id") long id) {}     
}

package campher.rest;
import javax.ws.rs.Path;
@Path("{test}")
public class TestResource {

}
4

1 に答える 1

3
@Path("test") 

一致します<web-root>/test

@Path("{test}")

と が一致<web-root>/foo<web-root>/barます。ここでの単語 test は、関連付けるパス パラメータ マップ キーfoobar値にすぎません。

{}名前の前後の の有無に注意してください。それらは表現の意味を完全に変えます。それらの存在は、それを抽出して、 で注釈が付けられたインスタンス変数に入れたいことを示しています@PathParam("name-between-brackets")

あなた@Path("{test}")@Path("{notes}")両方は基本的に、Jersey にフォームのルート URL を探して、それぞれに変数とパス変数http://<host:port>/<webapp>/{capture-text}をコピーcapture-textするように求めています。これはあいまいです。testnotes

于 2012-08-22T01:02:51.480 に答える