Jboss 7.1中的RestEasy Jax-RS不起作用 [英] RestEasy Jax-RS in Jboss 7.1 doesn't work

查看:250
本文介绍了Jboss 7.1中的RestEasy Jax-RS不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在JBoss AS 7.1下部署一个简单的Web应用程序,它与resteasy捆绑在一起。根据文档,所需要的只是(至少)是一个空的 web.xml ,一个带有注释的类@ApplicationPath(/ mypath你的其他课程的) @Path(/ other_stuff)

I'm trying to deploy a simple web application under JBoss AS 7.1 which comes bundled with resteasy. According to the documentation all that is needed is (at bare minimum) is an empty web.xml, a class with annotated @ApplicationPath("/mypath") and @Path("/other_stuff") for your other classes

我关注的文档在这里:

  • https://docs.jboss.org/author/display/AS7/JAX-RS+Reference+Guide
  • https://docs.jboss.org/author/display/AS7/Java+API+for+RESTful+Web+Services+(JAX-RS)

但是,当我点击时:

host:8080/warname/applicationpath/path

我在网页上收到404错误,但日志中没有。

I receive a 404 error on the webpage but nothing in the logs.

是否需要更改配置文件才能使JAX-RS正常工作?

Is there a configuration file I need to change in order for JAX-RS to work?

提前感谢您的帮助!

推荐答案

web.xml 将会这样做。

只需在你的类路径中添加一些resteasy依赖项。例如,如果您使用maven,则可以将其添加到 pom.xml

Just add some resteasy dependency to your classpath. For instance, if you use maven you can add this to your pom.xml:

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>2.3.1.GA</version>
    <scope>provided</scope> <!-- provided if youre deploying to jboss as 7.1 -->
</dependency>

然后仅使用此类设置应用程序:

Then set up the application using only this class:

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

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

为了确保,添加如下资源:

Just to make sure, add a resource like this:

@Path("/hello")
public class HelloResource {
    @GET
    @Produces("text/plain")
    public String helloResource() {
        return "Hello! It's "+new Date();
    }
}

这就是你所需要的。在JBoss AS 7.1上部署并进入它,比如说:

And that's all you need. Deploy it at a JBoss AS 7.1 and get to it, say:

http://127.0.0.1:8080/mywarname/rest/hello



编辑:



I用最小的结构创建了一个java war maven项目:

I have created a java war maven project with the bare minimum strucutre:

-pom.xml
-src
 |
  --main
    |
     --java
       |
        --rest
          |
           --HelloResource.java
           --JaxRsActivator.java

我叫它 simpleRest ,如下所示。所有档案都如下所示:

I called it simpleRest as seen below. All the archives are exactly as shown:

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                        http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>simpleRest</groupId>
    <artifactId>simpleRest</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>2.3.1.GA</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
<build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <!-- So maven doesn't require web.xml -->
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

HelloResource.java

HelloResource.java

package rest;

import java.util.Date;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/hello")
public class HelloResource {
    @GET
    @Produces("text/plain")
    public String helloResource() {
        return "Hello! It's "+new Date();
    }
}

JaxRsActivator.java:

JaxRsActivator.java:

package rest;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/rest")
public class JaxRsActivator extends Application {

}

这会生成 simpleRest.war (通过 mvn clean package )。然后我将其部署到新安装的 JBoss AS 7.1.1.Final 。如您所见,在部署期间未在日志中引用JAX-RS:

This generates a simpleRest.war (through mvn clean package). I then deploy it to a freshly installed JBoss AS 7.1.1.Final. As you can see, no reference is made to JAX-RS in the log during the deploy:

22:48:08,677 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "simpleRest.war"
22:48:09,318 INFO  [org.jboss.web] (MSC service thread 1-4) JBAS018210: Registering web context: /simpleRest
22:48:09,492 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "simpleRest.war"

之后,网址按预期显示:

After that, the URL is available as expected:

http://127.0.0.1:8080/simpleRest/rest/hello

请注意,其他一切都会出现404错误。但它是另一种404.

Notice that everything else gives a 404 error. But it is a different kind of 404.

http://127.0.0.1:8080/simpleRest/ 给出:

HTTP Status 404 - /simpleRest/

这是页面未找到错误。另一方面, http://127.0.0.1:8080/simpleRest/rest 给出:

That is a page not found error. On the other hand, http://127.0.0.1:8080/simpleRest/rest gives:

HTTP Status 404 - Could not find resource for relative : / of full path: http://127.0.0.1:8080/simpleRest/rest

这是资源(REST服务)未找到错误。这样你知道JAX-RS正在运行,虽然它没有该路径的处理程序。

That is a resource (REST service) not found error. This way you know JAX-RS is acting, though it did not have a handler for that path.

这篇关于Jboss 7.1中的RestEasy Jax-RS不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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