CXF致力于jboss EAP 6

时间:2014-10-27 16:31:13

标签: cxf jboss-eap-6

目前正致力于在JBOSS EAP 6上启动并运行CXF Web服务。我目前正在运行并且大部分工作但每次出现验证问题时都会出现以下错误。

08:58:49,180 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/data-api].[CXFServlet]] (http-/0.0.0.0:8080-2) JBWEB000236: Servlet.service() for servlet CXFServlet threw exception: java.lang.NoSuchMethodError: javax.ws.rs.InternalServerErrorException.validate(Ljavax/ws/rs/core/Response;Ljavax/ws/rs/core/Response$Status;)Ljavax/ws/rs/core/Response;

我假设它是版本冲突,但我已经排除了JBoss jaxrs子系统。还有其他人有这个问题吗?

的JBoss部署-structure.xml:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
  <deployment>
    <exclude-subsystems>
      <subsystem name="resteasy" />
      <subsystem name="jaxrs" />
      <subsystem name="webservices" />
    </exclude-subsystems>
    <exclusions>
    <module name="javax.ws.rs.api"/>
    <module name="org.apache.cxf"/>
    <module name="org.apache.cxf.impl"/>
    </exclusions>
  </deployment>
</jboss-deployment-structure>

的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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>data-api</display-name>
  <welcome-file-list>
    <!-- Should implement a welcome page at some point -->
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
    <init-param>
      <param-name>javax.ws.rs.Application</param-name>
      <param-value>com.data.api.rest.ConfigApplication</param-value>
    </init-param>
    <init-param>
        <param-name>jaxrs.application.address.ignore</param-name>
        <param-value>true</param-value>
    </init-param>


    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app>

的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>




  <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>

        <!-- Hibernate -->
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
        <version>4.3.6.Final</version>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.6.Final</version>
        </dependency>

        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-validator</artifactId>
        <version>5.1.2.Final</version>
        </dependency>





         <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-bundle</artifactId>
        <version>2.7.13</version>
        </dependency>



        <dependency>
          <groupId>org.codehaus.jackson</groupId>
          <artifactId>jackson-xc</artifactId>
          <version>1.9.13</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-jaxrs</artifactId>
            <version>1.9.13</version>
        </dependency>


        <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <version>5.1.31</version>
        </dependency>


  </dependencies>

  <build>
    <finalName>${project.artifactId}</finalName>

    <plugins>
      <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
      </plugin>
      <plugin>
    <groupId>com.googlecode.maven-java-formatter-plugin</groupId>
    <artifactId>maven-java-formatter-plugin</artifactId>
      </plugin>
      <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
      <overlays>

      </overlays>
      <archive>
        <manifestEntries>
          <Dependencies>org.apache.httpcomponents</Dependencies>
        </manifestEntries>
      </archive>
    </configuration>
      </plugin>
      <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
      </plugin>
      <plugin>
    <groupId>org.jboss.as.plugins</groupId>
    <artifactId>jboss-as-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>

1 个答案:

答案 0 :(得分:2)

这是使用jboss-deployment-structure.xml排除WAR中JAX-RS API的最简单解决方案(无需修改Jboss standalone.xml):

  1. 完全排除模块javaee.api

  2. 重新导入模块javaee.api并排除JAX-RS类

  3. 就是这样!

    在Jboss EAP 6.2上验证

    的JBoss部署-structure.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
      <deployment>
         <dependencies>
            <!-- Exclude JAX-RS: 2. re-import the javaee.api and exclude the JAX-RS classes -->
            <module name="javaee.api" >
                <imports>
                    <exclude path="javax/ws/**" />
                </imports>
            </module>
        </dependencies>
        <exclusions>
            <!-- Exclude JAX-RS: 1. exclude the javaee.api completely -->
               <module name="javaee.api" />
        </exclusions>
      </deployment>
    </jboss-deployment-structure>
    

    这会给调用者带来没有任何stacktrace / NoSuchMethodExceptions的HTTP 500,并在Jboss日志文件中清除Jackson Exceptions:

    引起:com.fasterxml.jackson.databind.JsonMappingException:无法反序列化VALUE_STRING标记中的字节实例

    另请参阅this了解解决方案的方法。

    如果您仍然遇到Jboss提供的JAX-RS子系统的问题(例如,当尝试生成CXF Swagger-API时,我得到了一个 java.lang.LinkageError:ClassCastException:尝试castjar:file:/ c:/jboss//modules/system/layers/base/javax/ws/rs/api/main/jboss-jaxrs-api_1.1_spec-1.0.1 .Final-redhat-2.jar!/javax/ws/rs/ext/RuntimeDelegate.class to vfs:/ c:/jboss/bin/content/myapp.war/WEB-INF/lib/javax.ws.rs- api-2.0.1.jar / javax / ws / rs / ext / RuntimeDelegate.class),那么你也可以排除整个jaxrs-subsystem:

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-deployment-structure>
      <deployment>
      ...
        <exclude-subsystems>
            <subsystem name="jaxrs" />
        </exclude-subsystems>  
      </deployment>
    </jboss-deployment-structure>