2016-05-18 9 views
0

Ich habe 3 Methoden in ProfileResource:Planung REST Ressource mehrere Methoden zu unterstützen, die produziert und verbraucht genau die gleichen Mime-Typen

@GET 
@Produces(MediaType.APPLICATION_JSON) 
public List<Profile> getAllProfiles() { 
    return profileService.getAllProfiles(); 
} 

@GET 
@Path("{profileId}") 
@Produces(MediaType.APPLICATION_JSON) 
public Profile getProfile(@PathParam("profileId") String profileId) { 
    return profileService.getProfile(profileId); 
} 

@GET 
@Produces(MediaType.APPLICATION_JSON) 
public Profile getProfileByName(@QueryParam("profileName") String profileName) { 
    return profileService.getProfileByName(profileName); 
} 

Während Serverstart unter Fehler ausgelöst wird, da beide getAllProfiles und getProfileByName Methoden GET sind Methoden, beide produzieren MediaType.APPLICATION_JSON und es gibt keine Path Differenz b/n sie.

org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization. 
[[FATAL] A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by"@Consumes" and "@Produces" annotations at Java methods public restapi.model.Profile restapi.resources.ProfileResource.getProfileByName(java.lang.String) and public java.util.List restapi.resources.ProfileResource.getAllProfiles() at matching regular expression /profiles. These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail.; source='[email protected]'] 
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:555) ~[jersey-server-2.22.2.jar:na] 

Wie wird das Problem gelöst?

Antwort

1

Sie haben sowohl getAllProfiles() als auch getProfileByName() differenziert, indem Sie unterschiedliche Pfade angeben, um darauf zuzugreifen, es sei denn, der Server kann sie nicht unterscheiden. damit Sie unter Fehler kommen.

Ein Ressourcenmodell hat mehrdeutig (sub-) Ressourcen Methode für HTTP GET-Methode

für verschiedene Pfade zur Verfügung stellen beide, kann man, dass die Verwendung @path tun() Anmerkung.

+0

Können wir dieses Problem nicht lösen, ohne einen neuen Pfad anzugeben? –

+0

das ist, was ich in der Antwort sagte – SivaTeja

+0

@ Tom Howard Irgendwelche Eingaben? –

Verwandte Themen