Jersey Web Service无法在Gatein 3.6中使用JBOSS AS7

时间:2013-11-30 05:27:05

标签: java rest jboss

我在我的gatein 3.6(使用Jboss AS7)中创建了一个样本球衣服务器。以下是创建泽西服务器的步骤。

我在web.xml文件中添加了以下代码行。



    <servlet>
          <servlet-name>Jersey REST Service</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>de.vogella.jersey.first</param-value>
           </init-param>
           <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
           <servlet-name>Jersey REST Service</servlet-name>
           <url-pattern>/rest/*</url-pattern>
      </servlet-mapping>

类文件是


    package de.vogella.jersey.first;

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

    // Plain old Java Object it does not extend as class or implements
    // an interface

    // The class registers its methods for the HTTP GET request using the @GET annotation.
    // Using the @Produces annotation, it defines that it can deliver several MIME types,
    // text, XML and HTML.

    // The browser requests per default the HTML MIME type.

    //Sets the path to base URL + /hello
    @Path("/hello")
    public class Hello {

      // This method is called if TEXT_PLAIN is request
      @GET
      @Produces(MediaType.TEXT_PLAIN)
      public String sayPlainTextHello() {
       return "Hello Jersey";
      }

      // This method is called if XML is request
      @GET
      @Produces(MediaType.TEXT_XML)
      public String sayXMLHello() {
       return "" + " Hello Jersey" + "";
      }

      // This method is called if HTML is request
      @GET
      @Produces(MediaType.TEXT_HTML)
      public String sayHtmlHello() {
       return " " + "" + "Hello Jersey" + ""
      + "" + "Hello Jersey" + "" + " ";
      }

    }

但不幸的是,我在启动服务器时遇到异常

17:17:22,649 ERROR [org.apache.catalina.core.ContainerBase。[jboss.web]。[default-host]。[/ cisms]](MSC service thread 1-6)StandardWrapper.Throwable:com .sun.jersey.core.spi.scanning.ScannerException:URI vfs的URI方案vfs:/ E:/BMITDevelopment/GateIn-3.6.0.Final-jbossas7/standalone/deployments/cisms.war/WEB-INF/ classes / com / radiant / cisms / workFlow / core /不受支持。此类URI不支持程序包扫描部署。 尝试使用不同的部署机制,例如使用javax.ws.rs.core.Application的扩展显式声明根资源和提供程序类   在com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:225)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:139)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:78)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:116)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.api.core.PackagesResourceConfig。(PackagesResourceConfig.java:81)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.api.core.PackagesResourceConfig。(PackagesResourceConfig.java:92)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:677)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:655)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:206)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:342)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:516)[jersey-bundle-1.4.jar:1.4]   在javax.servlet.GenericServlet.init(GenericServlet.java:242)[jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]   在org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202)[jbossweb-7.0.13.Final.jar:]   在org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102)[jbossweb-7.0.13.Final.jar:]   在org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655)[jbossweb-7.0.13.Final.jar:]   在org.apache.catalina.core.StandardContext.start(StandardContext.java:3873)[jbossweb-7.0.13.Final.jar:]   在org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90)[jboss-as-web-7.1.1.Final.jar:7.1.1.Final]   at org.jboss.msc.service.ServiceControllerImpl $ StartTask.startService(ServiceControllerImpl.java:1811)   at org.jboss.msc.service.ServiceControllerImpl $ StartTask.run(ServiceControllerImpl.java:1746)   at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:886)[rt.jar:1.6.0_30]   at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:908)[rt.jar:1.6.0_30]   在java.lang.Thread.run(Thread.java:662)[rt.jar:1.6.0_30]

17:17:22,665 ERROR [org.apache.catalina.core.ContainerBase。[jboss.web]。[default-host]。[/ cisms]](MSC服务主题1-6)Servlet / cisms投入负载()exception:com.sun.jersey.core.spi.scanning.ScannerException:URI vfs的URI方案vfs:/ E:/BMITDevelopment/GateIn-3.6.0.Final-jbossas7/standalone/deployments/cisms.war / WEB-INF / classes / com / radiant / cisms / workFlow / core /不受支持。此类URI不支持程序包扫描部署。 尝试使用不同的部署机制,例如使用javax.ws.rs.core.Application的扩展显式声明根资源和提供程序类   在com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:225)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:139)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:78)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:116)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.api.core.PackagesResourceConfig。(PackagesResourceConfig.java:81)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.api.core.PackagesResourceConfig。(PackagesResourceConfig.java:92)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:677)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:655)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:206)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:342)[jersey-bundle-1.4.jar:1.4]   在com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:516)[jersey-bundle-1.4.jar:1.4]   在javax.servlet.GenericServlet.init(GenericServlet.java:242)[jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]   在org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202)[jbossweb-7.0.13.Final.jar:]   在org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102)[jbossweb-7.0.13.Final.jar:]   在org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655)[jbossweb-7.0.13.Final.jar:]   在org.apache.catalina.core.StandardContext.start(StandardContext.java:3873)[jbossweb-7.0.13.Final.jar:]   在org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90)[jboss-as-web-7.1.1.Final.jar:7.1.1.Final]   at org.jboss.msc.service.ServiceControllerImpl $ StartTask.startService(ServiceControllerImpl.java:1811)   at org.jboss.msc.service.ServiceControllerImpl $ StartTask.run(ServiceControllerImpl.java:1746)   at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:886)[rt.jar:1.6.0_30]   at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:908)[rt.jar:1.6.0_30]   在java.lang.Thread.run(Thread.java:662)[rt.jar:1.6.0_30]

先谢谢 Josny

2 个答案:

答案 0 :(得分:0)

在使用Jersey版本1.9将Jersey应用程序从Tomcat迁移到Wildfly 8(JBossAS)时,我遇到了这个问题。将Jersey库版本升级到1.10时,它已得到解决。

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.10</version>
</dependency>

答案 1 :(得分:0)

我写了一篇博客。它在另一个论坛得到了回答,但摘要是您需要在web.xml中禁用resteasy扫描并将一个jboss-deployment-structure.xml文件添加到META-INF

这2个文件看起来应该是这样的(根据博客中的例子)

的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"  
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  
      id="WebApp_ID" version="3.0">  
      <display-name>hellows</display-name>  
      <servlet>  
           <servlet-name>hellows servlet</servlet-name>  
           <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>  
           <init-param>  
                <param-name>javax.ws.rs.Application</param-name>  
                <param-value>com.vbranden.HelloApplication</param-value>  
           </init-param>  
           <init-param>  
                <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>  
                <param-value>true</param-value>  
           </init-param>  
           <load-on-startup>1</load-on-startup>  
      </servlet>  
      <servlet-mapping>  
           <servlet-name>hellows servlet</servlet-name>  
           <url-pattern>/*</url-pattern>  
      </servlet-mapping>  
      <context-param>  
           <param-name>resteasy.scan</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>  
      <context-param>  
           <param-name>resteasy.scan.providers</param-name>  
           <param-value>false</param-value>  
      </context-param>  
 </web-app>  

jboss-deployment-structure.xml(进入META-INF)

<?xml version="1.0" encoding="UTF-8"?>  
 <jboss-deployment-structure>  
 <deployment>  
 <exclude-subsystems>  
  <subsystem name="resteasy" />  
 </exclude-subsystems>  
 <exclusions>  
  <module name="javaee.api" />  
  <module name="javax.ws.rs.api"/>  
  <module name="org.jboss.resteasy.resteasy-jaxrs" />  
 </exclusions>  
 <local-last value="true" />  
 </deployment>  
 </jboss-deployment-structure> 

这里的完整示例

http://blog.vbranden.com/2015/03/creating-jersey-webservice-in-gatein.html