Jersey/REST--NoSuchMethodError: com.sun.jersey.core.reflection.ReflectionHelper.getContextClassLoaderPA()Ljava/security/PrivilegedAction;

倾然丶 夕夏残阳落幕 提交于 2019-12-30 11:04:05

问题


I get the NoSuchMethodError when trying build the REST service using jersey. Any help would be much appreciated.

My 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>

My 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>

Not sure what I am doing wrong, but when I checked the API docs, it seems I have the right version in the mvn dependancies.

Here is the stacktrace during run time.

[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)

回答1:


I faced the issue too recently. Check if class with name com.sun.jersey.core.reflection.ReflectionHelper is present in any other jar.

For me I had caliper.jar also, and it was being loaded from there instead. That class did not have getContextClassLoaderPA.

Do a grep -ir com.sun.jersey.core.reflection.ReflectionHelper * to see if any other jar shows up the same class.




回答2:


  • Bea Weblogic 12.1.3.0.0
  • jdk 1.7.0_75
  • jersey dependencies 1.19

I had the following exception: java.lang.IllegalAccessError: tried to access method com.sun.jersey.core.spi.factory.ResponseImpl.<init etc.

  • Tried to use "provided" scope for the jersey dependencies, but it didn't work.
  • The error seems to appear randomly, with similar packages working or not.
  • I created another weblogic managed server and deployed the same war that was not working on the initial managed server. The error doesn't appear.

This may suggest that there is an internal Weblogic issue. I was updating the same deployment with newer wars. After a period, it looks like the update process is not unloading the old war dependencies. I removed manually from the weblogic directories the deployed war files. I wasn't able to remove two wars: the current one and the replaced one, while the managed server was running. Directories of interest: 12.1.3\user_projects\domains\wl_server\servers\managed_1\stage, 12.1.3\user_projects\domains\wl_server\servers\managed_1\tmp_WL_user, 12.1.3\user_projects\domains\wl_server\servers\AdminServer\upload.

After stopping the managed server, I could remove the old war, leaving only the latest war. On managed_1 start, the latest war is working without the weird exception.



来源:https://stackoverflow.com/questions/28652337/jersey-rest-nosuchmethoderror-com-sun-jersey-core-reflection-reflectionhelper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!