以下代码有效
@POST
@Path("/{apiId}")
@Consumes(MediaType.APPLICATION_JSON)
public Response postMetricsData(String metricsData) {
System.out.println(metricsData);
return Response.ok().build();
}
下面的代码抛出错误
@POST
@Path("/{apiId}")
@Consumes(MediaType.APPLICATION_JSON)
public Response postMetricsData(String metricsData, @PathParam("apiId") String apiId) {
System.out.println(metricsData);
return Response.ok().build();
}
摆脱异常
rg.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
[[FATAL]找不到针对公共javax.ws.rs.core.Response com.trimble.paas.apicloud.metricscollector.resource.MetricsResource.postMetricsData(java.lang.String lang.String)位于索引1; source ='ResourceMethod {httpMethod = POST,consumedTypes = [application / json],producedTypes = [],suspended = false,suspendTimeout = 0,suspendedTimeoutUnit = MILLISECONDS,invocable = Invocable {handler = ClassBasedMethodHandler {handlerClass = class com.trimble.paas .apicloud.metricscollector.resource.MetricsResource,handlerConstructors = [org.glassfish.jersey.server.model.HandlerConstructor@59916e0f]},defineMethod = public javax.ws.rs.core.Response com.trimble.paas.apicloud.metricscollector。 resource.MetricsResource.postMetricsData(java.lang.String,java.lang.String),parameters = [参数[type = class java.lang.String,source = null,defaultValue = null],参数[type = class java.lang .String,source = apiId,defaultValue = null]],responseType = class javax.ws.rs.core.Response},nameBindings = []}'] 在org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:394) 在org.glassfish.jersey.server.ApplicationHandler.lambda $ initialize $ 1(ApplicationHandler.java:316) 在org.glassfish.jersey.internal.Errors.process(Errors.java:316) 在org.glassfish.jersey.internal.Errors.process(Errors.java:298) 在org.glassfish.jersey.internal.Errors.processWithException(Errors.java:256) 在org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:315) 在org.glassfish.jersey.server.ApplicationHandler。(ApplicationHandler.java:282) 在org.glassfish.jersey.servlet.WebComponent。(WebComponent.java:335) 在org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178) 在org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370) 在javax.servlet.GenericServlet.init(GenericServlet.java:158) 在org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1144) 在org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:789) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) 在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) 在org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800) 在org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 在org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:806) 在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1498) 在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) 在org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(Thread.java:745)
对我想念的东西有任何想法吗?
答案 0 :(得分:0)
检查@PathParam的导入。尝试使用
tcl-dev