failed Jersey REST Service: java.lang.IncompatibleClassChangeError: Implementing class

五迷三道 提交于 2019-12-06 13:25:01

OK, I found out : apparently (looking at the stack trace I posted in the question) , GAE did not allow Jersey to use its classloader to scan the available rest resources. So, I read in detail the Jersey documentation the Jersey documentation regarding the deployments and I found out that I can manually specify the Rest resources to Jersey.

Here is the web.xml :

<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
  <param-name>javax.ws.rs.Application</param-name>
  <param-value>sample.hello.bean.MyApplication</param-value>
</init-param>
</servlet>

You can notice I now have an Application class :

    package sample.hello.bean;

    import java.util.HashSet;
    import java.util.Set;

    import javax.ws.rs.core.Application;

    import sample.hello.resources.HelloResource;

    public class MyApplication extends Application {
         public Set<Class<?>> getClasses() {
             Set<Class<?>> s = new HashSet<Class<?>>();
             s.add(HelloResource.class);
             return s;
         }
    }

Just specify manually your rest resources adding them to the set. Works with jersey-bundle-1.14.jar

Thanks This helped me too. But the jersey documentation also says we can configure using packages. Don't we have any other option to declare in packages. Because for every new resource we need to modify the MyApplication class

<!-- Add following dependency in pom.xml -->
<dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
</dependency>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!