Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 缺少方法public void的依赖项_Java_Html_Http_Jersey_Jackson - Fatal编程技术网

Java 缺少方法public void的依赖项

Java 缺少方法public void的依赖项,java,html,http,jersey,jackson,Java,Html,Http,Jersey,Jackson,我有以下代码: @Path("/automation/devices") @Singleton public class DevicesWebService { private AppiumServerManager appiumServerManager; private AdbService adbService; private DevicesService deviceService; public DevicesWebService() {

我有以下代码:

@Path("/automation/devices")
@Singleton
public class DevicesWebService {
    private AppiumServerManager appiumServerManager;
    private AdbService adbService;
    private DevicesService deviceService;

    public DevicesWebService() {
        this(new AdbServiceLocal(), new AppiumServerManagerLocal());
    }

    @VisibleForTesting
    public DevicesWebService(AdbService adbService, AppiumServerManagerLocal AppiumServerManager) {
        this.adbService = adbService;
        this.appiumServerManager = AppiumServerManager;
    }


    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getMessage() {
        return "welocme to devices web-service";
    }

    @POST
    @Consumes({MediaType.APPLICATION_JSON})
    @Produces({MediaType.TEXT_PLAIN})
    @Path("/acquireDevice/{device}/{port}")
    public Response acquireDevice(@PathParam("device") Device device, @PathParam("port") Integer port) throws
            Exception {
        try {
            deviceService.acquireDevice(device, port);
        } catch (RuntimeException e) {
            return Response.status(Response.Status.NOT_FOUND).build();
        }
        return Response.status(Response.Status.OK).build();

    }
//
    public static void main(String[] args) throws IOException {
        HttpServer server = HttpServerFactory.create("http://localhost:9998/");
        server.start();
        System.out.println("Server running");
        System.out.println("Visit: http://localhost:9998/automation/devices");
    }
}
我的代码在运行时失败,出现以下异常:

Mar 20, 2016 12:37:51 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class com.m.mobileautomation.devices.webServices.DevicesWebService
  class com.m.mobileautomation.MobileAutomationWebService
Mar 20, 2016 12:37:51 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Provider classes found:
  class org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
  class org.codehaus.jackson.jaxrs.JacksonJsonProvider
  class org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper
  class org.codehaus.jackson.jaxrs.JsonParseExceptionMapper
Mar 20, 2016 12:37:51 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.19 02/11/2015 05:39 AM'
Mar 20, 2016 12:37:52 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
  SEVERE: Missing dependency for method public javax.ws.rs.core.Response com.m.mobileautomation.devices.webServices.DevicesWebService.acquireDevice(com.m.mobileautomation.devices.dataModel.Device,java.lang.Integer) throws java.lang.Exception at parameter at index 0
  SEVERE: Method, public javax.ws.rs.core.Response com.m.mobileautomation.devices.webServices.DevicesWebService.acquireDevice(com.m.mobileautomation.devices.dataModel.Device,java.lang.Integer) throws java.lang.Exception, annotated with POST of resource, class com.m.mobileautomation.devices.webServices.DevicesWebService, is not recognized as valid resource method.
Exception in thread "main" com.sun.jersey.spi.inject.Errors$ErrorMessagesException
    at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
    at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
    at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:172)
    at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:264)
    at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:246)
    at com.sun.jersey.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:117)
    at com.sun.jersey.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:92)
    at com.m.mobileautomation.devices.webServices.DevicesWebService.main(DevicesWebService.java:86)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
如果我注释掉
公共响应设备
一切正常

我也尝试删除``但仍有一个错误:

SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
  SEVERE: Missing dependency for method public void com.m.mobileautomation.devices.webServices.DevicesWebService.acquireDevice(com.m.mobileautomation.devices.dataModel.Device,java.lang.Integer) throws java.lang.Exception at parameter at index 0
  SEVERE: Method, public void com.m.mobileautomation.devices.webServices.DevicesWebService.acquireDevice(com.m.mobileautomation.devices.dataModel.Device,java.lang.Integer) throws java.lang.Exception, annotated with POST of resource, class com.m.mobileautomation.devices.webServices.DevicesWebService, is not recognized as valid resource method.
Exception in thread "main" com.sun.jersey.spi.inject.Errors$ErrorMessagesException
    at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
    at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
    at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:172)
    at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:264)
    at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:246)
    at com.sun.jersey.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:117)
    at com.sun.jersey.api.container.httpserver.HttpServerFactory.create(HttpServerFactory.java:92)
    at com.waze.mobileautomation.devices.webServices.DevicesWebService.main(DevicesWebService.java:87)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

如何解决此问题?

正如@peeskillet所说,
@PathParam
不应用于传递对象,因为它更常用于指定一个变量,用于标识您操作的资源/对象(例如,在您的情况下,我可能会使用
acquireDevice/{deviceId}/{port}
如果说,id事先有任何意义)

使用它,就像你现在所做的一样,当你在测试或者需要查看日志中发生的事情时,也可以真正地为你模糊的东西——想想JSON卡在中间的条目将如何在你的应用程序访问日志中查看。


如果你想传递对象,你一定要使用请求的主体——还要注意Jackson(我看到你给它加了标签,所以我假设这就是你在Jersey中使用的)也必须知道如何反序列化该对象,否则你也会失败。

正如@peeskillet所说,
@PathParam
不应用于传递对象,因为它更常用于指定一个变量,用于标识您操作的资源/对象(例如,在您的情况下,如果说id事先有任何意义,我可能会使用
acquireDevice/{deviceId}/{port}

使用它,就像你现在所做的一样,当你在测试或者需要查看日志中发生的事情时,也可以真正地为你模糊的东西——想想JSON卡在中间的条目将如何在你的应用程序访问日志中查看。


如果你想传递对象,你一定要使用请求的主体——还要注意Jackson(我看到你给它加了标签,所以我假设这就是你在Jersey中使用的)必须知道如何反序列化该对象,否则你也会失败。

阅读Javadoc了解
@PathParam
,它将告诉您使用自定义类型参数的要求。Jersey不知道如何从字符串创建设备。但有一些方法可以让泽西知道如何创造它。请参阅javadoche@PathParam java doc,它只处理参数命名,而不处理从字符串到java对象的转换。我遵循了这个教程,我错过了什么?您没有读过关于静态
fromString(String)
valueOf(String)
方法或接受字符串的构造函数的内容吗?这些是您的
设备
类的选项,如果您想将其用作
@PathParam
的参数类型。您需要从传递给这三个选项中任意一个的字符串构造
设备
,我将用谷歌搜索它。基本上,如果我想使用POST发送“设备”,我只能在消息正文中发送。对吗?如果您想将其作为
@PathParam
,这意味着您想将JSON放在URL中。这并不常见,而且是个坏主意。因此,将它放在正文中阅读
@PathParam
的Javadoc,它将告诉您使用自定义类型参数的要求。Jersey不知道如何从字符串创建设备。但有一些方法可以让泽西知道如何创造它。请参阅javadoche@PathParam java doc,它只处理参数命名,而不处理从字符串到java对象的转换。我遵循了这个教程,我错过了什么?您没有读过关于静态
fromString(String)
valueOf(String)
方法或接受字符串的构造函数的内容吗?这些是您的
设备
类的选项,如果您想将其用作
@PathParam
的参数类型。您需要从传递给这三个选项中任意一个的字符串构造
设备
,我将用谷歌搜索它。基本上,如果我想使用POST发送“设备”,我只能在消息正文中发送。对吗?如果您想将其作为
@PathParam
,这意味着您想将JSON放在URL中。这并不常见,而且是个坏主意。所以把它放在身体里