在 JBoss 6.1 Final 中部署 Jersey 1.11 RESTful Web 服务(RestEasy 已取消部署) [英] Deploying a Jersey 1.11 RESTful Web service in JBoss 6.1 Final (RestEasy already undeployed)

查看:26
本文介绍了在 JBoss 6.1 Final 中部署 Jersey 1.11 RESTful Web 服务(RestEasy 已取消部署)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提前对文字墙表示抱歉,但我想说得彻底,以免浪费您的时间,好心的 StackOverflow 用户.:-)

Sorry in advance for the wall of text, but I wanted to be thorough so as not to waste your time, kind StackOverflow-ers. :-)

我已经在 Tomcat 7 中成功部署并测试了一个作为 war 文件的 RESTful Web 服务,因为 JBoss 使用 Tomcat 作为一个组件,我(错误地)认为部署就像将 war 文件放入我的 JBoss 6.1 一样简单server/default/deploy 目录,不!起初我收到一个错误,说只允许一个 JAX-RS 应用程序类,这很容易通过从 Jboss 中的 deployers/目录中删除 resteasy.deployer 来解决(所有、默认和标准服务器只是为了彻底).

I've successfully deployed and tested a RESTful web service in Tomcat 7 as a war file, since JBoss uses Tomcat as a component, I (mistakenly) thought the deployment would be as simple as dropping the war file into my JBoss 6.1 server/default/deploy directory, nope! At first I got an error saying only one JAX-RS Application Class allowed, this was easily fixed by removing the resteasy.deployer from deployers/ dir in Jboss (all, default, and standard servers just to be thorough).

现在的症结是我在 Jboss 启动期间收到以下消息:

Now the crux is that I'm getting the following messages during Jboss startup:



    10:38:07,431 INFO  [PackagesResourceConfig] Scanning for root resource and provider classes in the packages:
    net.ussouth.incomm.SPIL.resource
    10:38:07,486 INFO  [WebApplicationImpl] Initiating Jersey application, version 'Jersey: 1.11 12/09/2011 10:27 AM'
    10:38:07,718 SEVERE [RootResourceUriRules] The ResourceConfig instance does not contain any root resource classes.
    10:38:07,719 ERROR [[/SPIL]] StandardWrapper.Throwable: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
        at com.sun.jersey.server.impl.application.RootResourceUriRules.(RootResourceUriRules.java:99) [:1.11]
        at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298) [:1.11]
        at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169) [:1.11]
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775) [:1.11]
        at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771) [:1.11]

这是WEB-INF/classes目录下的Resource类:

Here is the Resource class which is under the WEB-INF/classes directory:



    package net.ussouth.incomm.SPIL.resource;

    import javax.ws.rs.Path;
    import javax.ws.rs.POST;
    import javax.ws.rs.Consumes;
    import javax.ws.rs.core.MediaType;
    import javax.ws.rs.Produces;
    import javax.ws.rs.FormParam;

    import org.apache.log4j.Logger;

    @Path("/message")
    public class MessageResource {
      private static Logger log = Logger.getLogger(MessageResource.class);


      @POST
      @Path("/Search")
      @Produces(MediaType.APPLICATION_XML)
      @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
      public String search(@FormParam("message") String _msgToProvider, @FormParam("provider") String _provData) {
        log.info("MesageResource.search method called");
        String outVal = null;

        try{
          ProviderHandler hnd = new ProviderHandler();
          outVal = hnd.getOffers(_msgToProvider);

        } catch(JAXBException ex) {
          ...
        } catch (SearchException ex) {
          ...
        }

        return outVal;
      }     
    }

这是 web.xml:

Here's the web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  id="WebApp_ID" 
  version="2.5">

  <display-name>Spil</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>SpilMessageService</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>

    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>net.ussouth.incomm.SPIL.resource</param-value>
    </init-param>

    <init-param>
      <param-name>log4j-properties-location</param-name>
      <param-value>classes/log4j.xml</param-value>
    </init-param>

    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>SpilMessageService</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

</web-app>

最后,这里是 jboss-web.xml:

Finally, for good measure here's the jboss-web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
<jboss-web>
    <context-root>SPIL</context-root>
</jboss-web>

感谢您的帮助.我花了 1.5 天的时间研究并用头撞墙.

Thank you for any help. I've spent 1.5 days researching and banging my head against the wall.

推荐答案

您所需要的只是使用一种可移植的 JAX-RS 部署方法,正如 此处.不要使用包扫描,而是使用 javax.ws.rs.core.Application

All you need is to use a portable JAX-RS deployment approach as explained here. Instead of using package scanning, force manual scanning using an implementation of javax.ws.rs.core.Application

import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;

public class MyApplication extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        final Set<Class<?>> classes = new HashSet<Class<?>>();
        // register resources
        classes.add(MessageResource.class);
        return classes;
    }
}

然后,更新您的 web.xml 以使用它.请记住禁用resteasy扫描,如下所示.

Then, update your web.xml to use this instead. Remember to disable resteasy scanning as shown below.

<?xml version="1.0" encoding="UTF-8"?>
    <web-app
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        id="WebApp_ID"
        version="2.5">

    <display-name>Spil</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>SpilMessageService</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>net.ussouth.incomm.SPIL.resource.MyApplication</param-value>
        </init-param>

        <init-param>
            <param-name>log4j-properties-location</param-name>
            <param-value>classes/log4j.xml</param-value>
        </init-param>

        <load-on-startup>1</load-on-startup>
    </servlet>
    <context-param>
        <param-name>resteasy.scan</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.scan.providers</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>resteasy.scan.resources</param-name>
        <param-value>false</param-value>
    </context-param>

    <servlet-mapping>
        <servlet-name>SpilMessageService</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>

这篇关于在 JBoss 6.1 Final 中部署 Jersey 1.11 RESTful Web 服务(RestEasy 已取消部署)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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