在将resteasy-jaxrs升级到最新版本后,Restful网站崩溃了 [英] Restful site broke after upgrading resteasy-jaxrs to the lastest version

查看:313
本文介绍了在将resteasy-jaxrs升级到最新版本后,Restful网站崩溃了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在RestEasy上浏览本教程示例:

I'm going through this tutorial example on RestEasy:

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

我下载了他们的代码并进行了修改,以便可以将其部署到tomcat 7和Java 1.7中.

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

如果我保留网站指定的pom.xml,则

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

但是,如果我将版本级别提高到3.0.8.Final或"RELEASE",则

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>

然后我无法通过上述URL访问它.相反,我在localhost_access_log.txt中得到了此消息

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 -

问题:如果我真的想使用RESTeasy 3.0.8.Final,是否有人知道如何使pom.xml正常工作?我是新来的.

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.

谢谢.

推荐答案

作为

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>

您还应该使用正确的Servlet版本更新web.xml.大多数旧的配置内容都可以删除,因此您最终得到:

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>

最后要做的是通过向MessageApplication类添加javax.ws.rs.ApplicationPath来告诉RESTeasy您要映射应用程序的路径:

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 { 
    ...
}

这篇关于在将resteasy-jaxrs升级到最新版本后,Restful网站崩溃了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆