无法为 XML 架构命名空间找到 Spring NamespaceHandler [http://cxf.apache.org/jaxrs]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8530819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 04:48:57  来源:igfitidea点击:

Unable to locate Spring NamespaceHandler for XML schema namespace [http://cxf.apache.org/jaxrs]

springresttomcatmavencxf

提问by Ananth Duari

I am trying to integrate Apache CXF with Spring to create a RESTful webservices. But while deploying the application I am getting the following exception.

我正在尝试将 Apache CXF 与 Spring 集成以创建 RESTful Web 服务。但是在部署应用程序时,我收到以下异常。

SEVERE: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://cxf.apache.org/jaxrs]
Offending resource: ServletContext resource [/WEB-INF/beans.xml]

This is my beans.xml

这是我的 beans.xml

<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:jaxrs="http://cxf.apache.org/jaxrs"
      xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
         http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
    <jaxrs:server id="empservice" address="/">
        <jaxrs:serviceBeans>
            <ref bean="empservice"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>

</beans>

and my pom.xml is

我的 pom.xml 是

<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>
  <groupId>com.maventest</groupId>
  <artifactId>Lab</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Lab Maven Webapp</name>
  <url>http://maven.apache.org</url>
     <properties>
       <javac.version>1.6</javac.version>
        <spring.version>3.0.3.RELEASE</spring.version>
        <junit.version>4.5</junit.version>
        <servlet-api.version>2.5.0</servlet-api.version>
        <cxf.version>2.4.0</cxf.version>
   </properties>

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

         <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>

         <dependency>
         <groupId>org.apache.cxf</groupId>
         <artifactId>cxf-rt-transports-http</artifactId>
         <version>${cxf.version}</version>
     </dependency>

    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>jsr311-api</artifactId>
        <version>1.1</version>
    </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>org.springframework.web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>org.springframework.web.servlet</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.4.0</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.Hymanson</groupId>
            <artifactId>Hymanson-mapper-asl</artifactId>
            <version>1.9.2</version>
        </dependency>

        <dependency>
            <groupId>net.sf.kxml</groupId>
            <artifactId>kxml2</artifactId>
            <version>2.2.2</version>
        </dependency>

  </dependencies>
  <build>
    <finalName>Lab</finalName>
      <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                   <source>1.6</source>
                   <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.21</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <scanTargets>
                        <scanTarget>src/main/webapp/WEB-INF</scanTarget>
                        <scanTarget>src/main/webapp/WEB-INF/web.xml</scanTarget>
                    </scanTargets>
                </configuration>
            </plugin>
        </plugins>
  </build>
</project>

I am not sure what jar or configuration I am missing.

我不确定我缺少什么 jar 或配置。

I have added cxf-rt-frontend-jaxrs jar but still getting same exception

我已经添加了 cxf-rt-frontend-jaxrs jar 但仍然遇到相同的异常

回答by Raghuram

As per this guide, you may want to try adding the following dependency in your pom.

根据本指南,您可能想尝试在 pom.xml 中添加以下依赖项。

<dependency>
  <groupId>org.apache.cxf</groupId>
  <artifactId>cxf-rt-frontend-jaxrs</artifactId>
  <version>${cxf.version}</version>
</dependency>