找不到为 javax.ws.rs.PathParam("id") 采用 String 参数或 valueOf() 或 fromString() 方法的构造函数
Posted
技术标签:
【中文标题】找不到为 javax.ws.rs.PathParam("id") 采用 String 参数或 valueOf() 或 fromString() 方法的构造函数【英文标题】:Unable to find a constructor that takes a String param or a valueOf() or fromString() method for javax.ws.rs.PathParam("id") 【发布时间】:2016-02-04 18:39:45 【问题描述】:我有一个将使用 xml 数据的 Web 服务
@Override
@GET
@Consumes("*/*")
@Produces("application/xml")
@Path("page/id")
public PageData getPage(@QueryParam("session") final String sessionId,
@PathParam("id") final String valueId)
throws SessionNotFoundException
final PageData pageData= getPageData(valueId);
return pageData;
在启动 wildfly 服务器时,我收到以下异常
14:33:33,272 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./project: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./project: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_11]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_11]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_11]
Caused by: java.lang.RuntimeException: org.jboss.seam.InstantiationException: Could not instantiate Seam component: org.jboss.seam.resteasy.bootstrap
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:222)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
... 3 more
Caused by: org.jboss.seam.InstantiationException: Could not instantiate Seam component: org.jboss.seam.resteasy.bootstrap
at org.jboss.seam.Component.newInstance(Component.java:2208)
at org.jboss.seam.contexts.Contexts.startup(Contexts.java:343)
at org.jboss.seam.contexts.Contexts.startup(Contexts.java:317)
at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:143)
at org.jboss.seam.init.Initialization.init(Initialization.java:813)
at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:193)
... 7 more
Caused by: java.lang.RuntimeException: Unable to find a constructor that takes a String param or a valueOf() or fromString() method for javax.ws.rs.PathParam("id") on public com.project..pojo.flex.PageData com.project.ws.PageDataService.getPage(
java.lang.String,java.lang.Object) throws com.project.SessionNotFoundException for basetype: java.lang.Object
at org.jboss.resteasy.core.StringParameterInjector.initialize(StringParameterInjector.java:206)
at org.jboss.resteasy.core.StringParameterInjector.<init>(StringParameterInjector.java:57)
at org.jboss.resteasy.core.PathParamInjector.<init>(PathParamInjector.java:49)
at org.jboss.resteasy.core.InjectorFactoryImpl.createParameterExtractor(InjectorFactoryImpl.java:98)
at org.jboss.resteasy.core.InjectorFactoryImpl.createParameterExtractor(InjectorFactoryImpl.java:61)
at org.jboss.resteasy.core.MethodInjectorImpl.<init>(MethodInjectorImpl.java:75)
at org.jboss.resteasy.core.InjectorFactoryImpl.createMethodInjector(InjectorFactoryImpl.java:55)
at org.jboss.resteasy.core.ResourceMethod.<init>(ResourceMethod.java:71)
at org.jboss.resteasy.core.ResourceMethodRegistry.processMethod(ResourceMethodRegistry.java:178)
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:123)
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:106)
at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:83)
at org.jboss.seam.resteasy.ResteasyBootstrap.registerPlainResource(ResteasyBootstrap.java:504)
at org.jboss.seam.resteasy.ResteasyBootstrap.registerResources(ResteasyBootstrap.java:422)
at org.jboss.seam.resteasy.ResteasyBootstrap.init(ResteasyBootstrap.java:133)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_11]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_11]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_11]
at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_11]
at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:79)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.bpm.BusinessProcessInterceptor.aroundInvoke(BusinessProcessInterceptor.java:51)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:196)
at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:114)
at com.project.report.api.RESTCaptureBootstrap_$$_javassist_seam_0.init(RESTCaptureBootstrap_$$_javassist_seam_0.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_11]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_11]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_11]
at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_11]
at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
at org.jboss.seam.Component.callComponentMethod(Component.java:2313)
at org.jboss.seam.Component.callCreateMethod(Component.java:2236)
at org.jboss.seam.Component.newInstance(Component.java:2196)
... 15 more
另一件事是,如果我将我的 Jars 添加到 eclipse 并从 eclipse 运行,我没有收到任何异常,但是如果我从 WildFly 构建应用程序并编写脚本并部署,那么只有我得到异常。
我怀疑这是由于 JAR 不匹配,但在这两种情况下我都有相同的 jar。
如果有人知道答案,请提出建议。
【问题讨论】:
【参考方案1】:线索在这里
getPage(java.lang.String, java.lang.Object)
正如您所想,这意味着您之前看到的代码不是部署在服务器上的代码。
对我来说,通常的原因是我通过将 WAR 粘贴到 Wildfly 独立/部署文件夹来部署代码,然后尝试使用 Wildfly Maven 插件部署更新版本。在 Maven 中一切似乎都成功了,但我粘贴到部署文件夹中的版本将继续优先于 Maven 版本。
顺便说一句,无法找到构造函数错误的一个常见原因是将集合用作@QueryParam。这看起来很直观,但 Resteasy 不支持,您需要使用 List。
【讨论】:
以上是关于找不到为 javax.ws.rs.PathParam("id") 采用 String 参数或 valueOf() 或 fromString() 方法的构造函数的主要内容,如果未能解决你的问题,请参考以下文章