Restful site broke after upgrading resteasy-jaxrs to the lastest version

社会主义新天地 提交于 2019-12-25 02:32:12

问题


I'm going through this tutorial example on RestEasy:

http://www.mkyong.com/webservices/jax-rs/resteasy-hello-world-example/

I downloaded their code and made modification so that I can deploy it to tomcat 7 and java 1.7.

If I leave the pom.xml as specified by the site,

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>2.2.1.GA</version>
    </dependency>

then everything appears to be fine and can be accessed through:

    http://localhost:8080/RESTfulExample/rest/message/hello

However, if I were to increase the version level to 3.0.8.Final or "RELEASE",

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>3.0.8.Final</version>
    </dependency>

then I can't access it via the above URL. Instead, I get this message in my localhost_access_log.txt

127.0.0.1 - - [19/Aug/2014:16:02:55 -0700] "GET /RESTfulExample/rest/message/hello HTTP/1.1" 404 -

Question: Does anyone know how I can get the pom.xml to work if I really want to use RESTeasy 3.0.8.Final? I'm new to Rest.

Thanks in advance.


回答1:


As the documentation describes you can initialize RESTeasy in a standalone Servlet 3.0 compliant container by adding this dependency:

<dependency>
  <groupId>org.jboss.resteasy</groupId>
  <artifactId>resteasy-servlet-initializer</artifactId>
  <version>3.0.8.Final</version>
</dependency>

You should also update the web.xml with the correct Servlet version. Most of the old configuration stuff can be removed so you end up with:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"> 
    <display-name>Restful Web Application</display-name>
</web-app>

Last thing to do is tell RESTeasy on which path you want to map your application by adding javax.ws.rs.ApplicationPath to the MessageApplication class:

@ApplicationPath("/rest")
public class MessageApplication extends Application { 
    ...
}


来源:https://stackoverflow.com/questions/25394497/restful-site-broke-after-upgrading-resteasy-jaxrs-to-the-lastest-version

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