2011-12-16 8 views
12

Tôi đang cố gắng tích hợp Apache CXF với Spring để tạo một webservices RESTful. Nhưng trong khi triển khai ứng dụng, tôi nhận được ngoại lệ sau.Không thể xác định vị trí Spring NamespaceHandler cho không gian tên lược đồ XML [http://cxf.apache.org/jaxrs]

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] 

Đây là beans.xml tôi

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

và pom.xml của tôi là

<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.jackson</groupId> 
      <artifactId>jackson-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> 

Tôi không chắc chắn những gì jar hoặc cấu hình tôi đang thiếu.

Tôi đã thêm CXF-rt-frontend-jaxrs jar nhưng vẫn nhận được cùng một ngoại lệ

+0

Bạn đã bao giờ tìm ra điều này chưa? Tôi đang đối mặt với cùng một vấn đề và tôi đã bao gồm cả phụ thuộc cxf-rt-frontend-jaxws và cxf-rt-frontend-jaxrs maven –

Trả lời

20

Theo guide này, bạn có thể muốn thử thêm phụ thuộc sau đây trong pom của bạn.

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