gpt4 book ai didi

rest - 没有为带有 jaxrs 的 rest-service 中的参数找到注入(inject)源

转载 作者:行者123 更新时间:2023-12-04 04:53:06 27 4
gpt4 key购买 nike

我有一个问题,我的休息服务的两种方法在部署时带来了错误,即没有注入(inject)源。

我的服务如下所示:

@Path("/chatservice")
public class ChatServiceImpl implements ChatService{

@POST
@Path("/registerToServer")
@Consumes(MediaType.APPLICATION_JSON)
@Override
public Response registerToServer(User user) {

UserList userListObject = getAllChatableUsers(user);

return Response.status(200).entity(userListObject).build();
}

@POST
@Path("/sendMessage")
@Consumes(MediaType.APPLICATION_JSON)
@Override
public Response sendMessage(Message message) {
boolean isSuccess = putMessageIntoDatabase(message);

return Response.status(200).build();
}

@POST
@Path("/getAllMessagesForUser")
@Consumes(MediaType.APPLICATION_JSON)
@Override
public Response getAllMessagesForUser(UserWithRecipient userWithRecipient) {

return Response.status(200).build();
}

@POST
@Path("/getAllMessagesForUser/{numberOfMessages}")
@Consumes(MediaType.APPLICATION_JSON)
@Override
public Response getMessagesForUser(@PathParam("numberOfMessages") int numberOfMessages, UserWithRecipient userWithRecipient) {

return Response.status(200).build();
}

出现问题的类(class)如下:
@XmlSeeAlso(User.class)
@XmlRootElement
public class UserWithRecipient {

private User user;
private User recipient;

public UserWithRecipient() {
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public User getRecipient() {
return recipient;
}

public void setRecipient(User recipient) {
this.recipient = recipient;
}
}

我得到的错误如下:
 [[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response de.hszg.fei.ws.service.ChatServiceImpl.getMessagesForUser(int,de.hszg.fei.ws.model.UserWithRecipient) at index 0.; source='ResourceMethod{httpMethod=POST, consumedTypes=[application/json], producedTypes=[], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class de.hszg.fei.ws.service.ChatServiceImpl, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@6da34189]}, definitionMethod=public javax.ws.rs.core.Response de.hszg.fei.ws.service.ChatServiceImpl.getMessagesForUser(int,de.hszg.fei.ws.model.UserWithRecipient), parameters=[Parameter [type=int, source=numberOfMessages, defaultValue=null], Parameter [type=class de.hszg.fei.ws.model.UserWithRecipient, source=null, defaultValue=null]], responseType=class javax.ws.rs.core.Response}, nameBindings=[]}']]]

你能告诉我这门课有什么问题吗?我也不明白,为什么 sendMessage()方法不会带来同样的问题。

最佳答案

我发现问题是,我输入了错误的 @PathParam注解。

关于rest - 没有为带有 jaxrs 的 rest-service 中的参数找到注入(inject)源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27940243/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com