简体   繁体   English

JBoss 7 RestEasy…服务未注册?

[英]JBoss 7 RestEasy…services not being registered?

I am upgrading my app to JBoss 7.1.1 and will now be using RestEasy. 我正在将我的应用程序升级到JBoss 7.1.1,现在将使用RestEasy。 I am having issues getting RestEasy to work. 我在让RestEasy上班时遇到问题。 I get the error HTTP Status 404 - Could not find resource for relative. 我收到错误HTTP状态404-找不到相对的资源。 I believe this means that it can't find the correct endpoint. 我相信这意味着它找不到正确的端点。 My suspicion is that there is some issue scanning and registering the services. 我怀疑扫描和注册服务时会出现一些问题。 I could be wrong though. 我可能是错的。 Note: I am not using Maven 注意:我没有使用Maven

Here is the portion of my web.xml that is concerned with RestEasy: 这是我的web.xml中与RestEasy有关的部分:

<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/rest</param-value>
</context-param>

<listener>
    <listener-class>
        org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
    </listener-class>
</listener>


<servlet>
    <servlet-name>Resteasy</servlet-name> 
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
    </servlet-class>
</servlet>

<servlet-mapping> 
    <servlet-name>Resteasy</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>  

Here is a sample resource I am using: 这是我正在使用的示例资源:

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

@Path("/hello")
public class HelloResource {

@POST
@Produces("text/plain")
public String helloResource() {
    return "Hello!";
}
}

The url I have tried is: http://localhost:8080/[project-name]/rest/hello 我尝试过的网址是: http:// localhost:8080 / [项目名称] / rest / hello

I think that is all I am using for the call. 我想这就是我正在使用的电话。 If additional info is required to answer my question, don't hesitate to ask. 如果需要其他信息来回答我的问题,请随时提出。 Thanks in advance for your help! 在此先感谢您的帮助!

PS - How do the files need to be structured in the WAR? PS-如何在WAR中构建文件?

[Updated web.xml] [更新的web.xml]

<context-param>
    <param-name>resteasy.servlet.mapping.prefix</param-name>
    <param-value>/rest</param-value>
</context-param>

  <context-param>
    <param-name>resteasy.resources</param-name>
    <param-value>com.elderscan.test.RestEasyExample</param-value>
</context-param> 

<servlet>
    <servlet-name>resteasy-servlet</servlet-name>
    <servlet-class>
        org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
     </servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.elderscan.test.MyApplication</param-value>
    </init-param>
</servlet>


<servlet-mapping> 
    <servlet-name>resteasy-servlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>  

So this allows me to successfully make a call to RestEasyExample, but I cannot make calls to another other rest services, which I obviously need to do. 因此,这使我能够成功调用RestEasyExample,但无法调用其他显然需要做的其他REST服务。 Furthermore, this solution of adding all of my services to xml is not ideal, so another way would be preferred. 此外,这种将我所有服务添加到xml的解决方案也不理想,因此将首选另一种方法。

Ended up solving this. 最终解决了这个问题。 The key was to include this to what I already had, where each singleton is a rest service: 关键是将其包括到我已经拥有的服务中,其中每个单身人士都是休息服务:

public class MyApplication  extends Application {
private Set<Object> singletons = new HashSet<Object>();

public MyApplication() {
    singletons.add(new RestEasyExample());
    singletons.add(new RestEasyExample2());
}

@Override
public Set<Class<?>> getClasses() {
    // TODO Auto-generated method stub
    return null;
}
@Override
public Set<Object> getSingletons() {
    return singletons;
}
}

I think you are right about your suspicion.. Try adding this to your web.xml 我认为您的怀疑是对的。尝试将其添加到web.xml中

<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>true</param-value>
</context-param>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM