REST CXF and Spring cxf-extension-jaxrs-binding File not found exception?

主宰稳场 提交于 2019-12-08 17:32:33

问题


i'm trynig to develop a REST web service using CXF 2.6.0 and spring 2.5.6 my CXF maven dependancy in the pom.xml are :

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

I'am using Spring 2.5.6 and i have declared my web service in the applicationcontext.xml spring file :

<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"/>

And i have declared my Web service into web.xml file by this code :

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

when i deploy my project on tomcat i got this exception for the second file of import in applicationcontext.xml file :

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

回答1:


According to this, this file is no longer required for cxf > 2.4.x.




回答2:


I am also getting the exact same error. The error that I am getting is -

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.

Even I read that the newer versions of cxf don't need anything other than cxf-rt-frontend-jaxrs. After I got these errors, I have added following dependencies in my pom file but they were of no help -

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

I also do not understand the reason why almost all the tutorials detailing steps for building a REST service using CXF want you to include following 3 lines in spring config (when I can't possibly locate these files anywhere) -

<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"/>



回答3:


Try removing the line that imports cxf-extension-jaxrs-binding.xml. The other 2 xml files are in the cxf-X.Y.Z.jar. For me that is cxf-2.7.7.jar.




回答4:


The file META-INF/cxf/cxf-extension-jaxrs-binding.xml is available in the below artifact.

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



回答5:


In applicationContext.xml, comment out the below imports works for me in cxf 3.1.10. import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml



来源:https://stackoverflow.com/questions/10721243/rest-cxf-and-spring-cxf-extension-jaxrs-binding-file-not-found-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!