Jersey / REST – NoSuchMethodError:com.sun.jersey.core.reflection.ReflectionHelper.getContextClassL

尝试使用jersey构建REST服务时,我得到了NoSuchMethodError.任何帮助将非常感激.

我的POM.xml:

    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-servlet</artifactId>
        <version>1.19</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.19</version>
    </dependency>

我的web.xml:

<servlet>
    <servlet-name>Rest</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.example.serversideauthservice.resources.AuthResource</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Rest</servlet-name>
    <url-pattern>/auth/*</url-pattern>
</servlet-mapping>

不确定我做错了什么,但当我检查API文档时,似乎我在mvn dependancies中有正确的版本.

这是运行时的堆栈跟踪.

[INFO] INFO: Scanning for root resource and provider classes in the packages:
[INFO]   com.example.serversideauthservice.resources.AuthResource
[INFO] Feb 21, 2015 2:35:26 PM com.google.apphosting.utils.jetty.JettyLogger warn
**[INFO] WARNING: failed Rest: java.lang.NoSuchMethodError: com.sun.jersey.core.reflection.ReflectionHelper.getContextClassLoaderPA()Ljava/security/PrivilegedAction;**
[INFO] Feb 21, 2015 2:35:26 PM com.google.apphosting.utils.jetty.JettyLogger warn
[INFO] WARNING: failed com.google.appengine.tools.development.DevAppEngineWebAppContext@7f74a932{/,D:\taxmarkets_main\taxmarket\target\taxmarket-1.0-SNAPSHOT}: java.lang.NoSuchMethodError: com.sun.jersey.core.reflection.ReflectionHelper.getContextClassLoaderPA()Ljava/security/PrivilegedAction;
[INFO] Feb 21, 2015 2:35:26 PM com.google.apphosting.utils.jetty.JettyLogger warn
[INFO] WARNING: failed JettyContainerService$ApiProxyHandler@660382ce: java.lang.NoSuchMethodError: com.sun.jersey.core.reflection.ReflectionHelper.getContextClassLoaderPA()Ljava/security/PrivilegedAction;
[INFO] Feb 21, 2015 2:35:26 PM com.google.apphosting.utils.jetty.JettyLogger warn
[INFO] WARNING: Error starting handlers
[INFO] java.lang.NoSuchMethodError: com.sun.jersey.core.reflection.ReflectionHelper.getContextClassLoaderPA()Ljava/security/PrivilegedAction;
[INFO]  at com.sun.jersey.spi.scanning.AnnotationScannerListener.<init>(AnnotationScannerListener.java:94)
[INFO]  at com.sun.jersey.spi.scanning.PathProviderScannerListener.<init>(PathProviderScannerListener.java:59)
[INFO]  at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
[INFO]  at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
[INFO]  at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
[INFO]  at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
[INFO]  at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:696)
[INFO]  at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674)
[INFO]  at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:205)

解决方法:

我最近也遇到了这个问题.检查名称为com.sun.jersey.core.reflection.ReflectionHelper的类是否存在于任何其他jar中.

对我来说,我也有caliper.jar,它正在从那里装载.那个类没有getContextClassLoaderPA.

执行grep -ir com.sun.jersey.core.reflection.ReflectionHelper *以查看是否有任何其他jar显示相同的类.

上一篇:java-apache http client org.apache.http.NoHttpResponseException:目标服务器无法响应


下一篇:java – JAX-RS / Jersey路径参数regex用于简单字符串