I'm building a REST application with AppEngine Datastore as persistence layer. However I have a problem using the com.google.appengine.api.datastore.Key within my Resource Class when parsing they key to create a new entry.
Error message is following: SEVERE: Missing dependency for method public com.acolsolutions.loyaltycard.persistence.entities.Card com.acolsolutions.loyaltycard.resources.CardResource.findByKey(com.google.appengine.api.datastore.Key) at parameter at index 0 SEVERE: Method, public com.acolsolutions.loyaltycard.persistence.entities.Card com.acolsolutions.loyaltycard.resources.CardResource.findByKey(com.google.appengine.api.dat astore.Key), annotated with GET of resource, class com.acolsolutions.loyaltycard.resources.CardResource, is not recognized as valid resource method.
It seems like the problem happens here. Seems that the value cant get converted in to a Key type:
public Card findByKey(@PathParam("key") Key key) {
...
}
My REST class looks as follows: import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.acolsolutions.loyaltycard.dataobjects.CardDAO;
import com.acolsolutions.loyaltycard.persistence.entities.Card;
import com.google.appengine.api.datastore.Key;
@Path("/cards")
public class CardResource {
CardDAO dao = new CardDAO();
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<Card> findAll() {
System.out.println("findAll");
return dao.findAll("creationDate desc");
}
@GET
@Path("search/{query}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<Card> findByName(@PathParam("query") String query) {
System.out.println("findByName: " + query);
return dao.findByName(query, "creationDate desc");
}
@GET
@Path("{key}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Card findByKey(@PathParam("key") Key key) {
//System.out.println("findByKey " + key.toString());
return dao.findByKey(key);
}
Can somebody tell me what I have to do to get this working?
Thanks, Chris
您可以尝试将参数更改为String而不是Key,然后使用com.google.appengine.api.datastore.KeyFactory.stringToKey(String stringKey)来获取Key。
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.