REST CXF和Spring cxf-extension-jaxrs-binding文件未找到异常?

时间:2012-05-23 13:43:51

标签: spring rest cxf java-io

我尝试使用CXF 2.6.0和spring 2.5.6开发REST Web服务我的pom.xml中的CXF maven依赖性是:

<dependency>
  <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-extension-providers</artifactId>
  <version>2.6.0</version>
   </dependency>

<dependency>
  <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-extension-search</artifactId>
  <version>2.6.0</version>
</dependency>

我正在使用Spring 2.5.6并且已在applicationcontext.xml spring文件中声明了我的Web服务:

<jaxrs:server id="restContainer" address="/sav">
    <jaxrs:serviceBeans>
        <ref bean="wssav"/>
    </jaxrs:serviceBeans>
</jaxrs:server>

 <import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

我已通过此代码将我的Web服务声明为web.xml文件:

<servlet>
    <servlet-name>CXFServlet</servlet-name>

    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

当我在tomcat上部署我的项目时,我在applicationcontext.xml文件中导入了第二个导入文件的异常:

    java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-jaxrs-binding.xml] cannot be opened because it does not exist 

5 个答案:

答案 0 :(得分:12)

根据this,cxf&gt;不再需要此文件。 2.4.x的。

答案 1 :(得分:1)

我也得到完全相同的错误。我得到的错误是 -

IOException parsing XML document from class path resource [META-INF/cxf/cxf-extension-jaxrs-binding.xml]; 
nested exception is java.io.FileNotFoundException: 
class path resource [META-INF/cxf/cxf-extension-jaxrs-binding.xml] cannot be opened because it does not exist.

即使我读到cxf的新版本也不需要除 cxf-rt-frontend-jaxrs 之外的其他任何内容。在我收到这些错误后,我在我的pom文件中添加了以下依赖项,但它们没有任何帮助 -

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxrs</artifactId>
    <version>2.6.2</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-rs-extension-providers</artifactId>
    <version>2.6.2</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-rs-extension-search</artifactId>
    <version>2.6.2</version>
</dependency>

我也不明白为什么几乎所有教程都详细说明使用CXF构建REST服务的步骤需要你在spring config中包含以下3行(当我无法在任何地方找到这些文件时) - < / p>

<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

答案 2 :(得分:1)

尝试删除导入cxf-extension-jaxrs-binding.xml的行。 其他2个xml文件位于cxf-X.Y.Z.jar中。 对我来说是cxf-2.7.7.jar。

答案 3 :(得分:0)

文件META-INF / cxf / cxf-extension-jaxrs-binding.xml在以下工件中可用。

<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>2.2.7</version>

答案 4 :(得分:0)

在applicationContext.xml中,在cxf 3.1.10中注释掉下面的导入对我有用。 import resource =&#34; classpath:META-INF / cxf / cxf-extension-jaxrs-binding.xml

相关问题