无法找到为javax.ws.rs.PathParam(“id”)接受String参数或valueOf()或fromString()方法的构造函数

时间:2015-11-04 10:08:31

标签: rest wildfly seam

我有一个将使用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构建我的应用程序并编写脚本并部署,那么只有我得到了Exception。

我怀疑这是由于JAR不匹配,但我在两种情况下都有相同的罐子。

如果有人知道答案,请建议。

1 个答案:

答案 0 :(得分:1)

线索在这里

  

getPage(java.lang.String, java.lang.Object

这意味着,正如您所想,您之前看到的代码不是在服务器上部署的代码。

对我来说,通常的原因是我通过将WAR粘贴到Wildfly独立/部署文件夹中来部署代码,然后尝试使用Wildfly Maven插件部署更新的版本。一切都会在Maven中成功,但我粘贴到deployments文件夹中的版本将继续优先于Maven版本。

顺便说一下,无法找到构造函数错误的常见原因是将Collection用作@QueryParam。这似乎很直观,但Resteasy不支持,您需要使用List。