我有一个PostgreSQL表testtable
,其中包含bigint类型的两部分主键(ID1
,bigint类型的ID2
)和带有时间戳的非键字段。我正在尝试使用“来自数据库的新RESTful Web服务”向导生成RESTful Web服务,并且除了包名称(服务)选择所有值的默认值之外。该向导生成四个文件:
部署到服务器并选择“测试RESTful Web服务”,测试页无法加载:
exception javax.servlet.ServletException: PWC1391: Servlet.init() for servlet org.netbeans.rest.application.config.ApplicationConfig threw exception root cause com.sun.jersey.spi.inject.Errors$ErrorMessagesException
查看glassfish事件日志,有两个严重错误:
The following errors and warnings have been detected with resource and/or provider classes: SEVERE: Missing dependency for method public void service.TesttableFacadeREST.remove(service.TesttablePK) at parameter at index 0 SEVERE: Method, public void service.TesttableFacadeREST.remove(service.TesttablePK), annotated with DELETE of resource, class service.TesttableFacadeREST, is not recognized as valid resource method. SEVERE: Missing dependency for method public service.Testtable service.TesttableFacadeREST.find(service.TesttablePK) at parameter at index 0 SEVERE: Method, public service.Testtable service.TesttableFacadeREST.find(service.TesttablePK), annotated with GET of resource, class service.TesttableFacadeREST, is not recognized as valid resource method.
和
WebModule[/tabletest]StandardWrapper.Throwable 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:771) at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766) at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488) at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318) at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609) at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210) at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373) at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556) at javax.servlet.GenericServlet.init(GenericServlet.java:244) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1453) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1093) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:189) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:722)
在我开始使用NetBeans提交错误报告之前,我只是想知道这是否更可能是开发人员错误,而不是开发人员工具集的错误。想法?
答案 0 :(得分:1)
出现问题是因为remove和find方法都将TesttablePK类型与@PathParam结合使用,但Jersey无法找到将字符串从url转换为此类对象的方法。这可以通过修改TesttablePK类型来解决。你有两个选择:
因此,您需要决定如何将复合键表示为字符串并将此类字符串转换为TesttablePK类型。