CXF BusException否名称空间的DestinationFactory http://cxf.apache.org/transports/http

Cru*_*ing 6 java rest web-services cxf jax-rs

我正在尝试站起[basic cxf rs示例] [1],但是使用我自己的服务impl更加简单,我的所有方法都返回字符串。当我尝试运行此服务器时,出现此异常

我建立了一个干净的项目,所以我要重新开始。

pom大师http://maven.apache.org/xsd/maven-4.0.0.xsd“>

<modelVersion>4.0.0</modelVersion>
<name>Tests</name>
<groupId>com.crush</groupId>
<artifactId>tests</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<properties>
    <cxf.version>2.7.11</cxf.version>
    <httpclient.version>3.1</httpclient.version>
    <rs-api.version>2.0</rs-api.version>

    <disclaimer/>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <slf4j.version>1.6.2</slf4j.version>
    <guava.version>13.0-rc2</guava.version>
    <jgroups.version>3.1.0.Final</jgroups.version>
    <infinispan.version>5.1.4.CR1</infinispan.version>
    <commons.cli.version>1.2</commons.cli.version>
    <jettison.version>1.3.2</jettison.version>
    <spring.version>3.1.0.RELEASE</spring.version>
    <bouncycastle.version>1.46</bouncycastle.version>
    <junit.version>4.8</junit.version>
    <jasypt.version>1.9.0</jasypt.version>

    <!-- Additional Dependencies -->
    <cxf.buildtools.version>2.2.12</cxf.buildtools.version>

    <!-- Maven Plugin Versions -->
    <shade.plugin.version>1.7.1</shade.plugin.version>
    <buildnumber.plugin.version>1.1</buildnumber.plugin.version>
    <jar.plugin.version>2.4</jar.plugin.version>
    <resources.plugin.version>2.5</resources.plugin.version>
    <versions.plugin.version>1.3.1</versions.plugin.version>

    <!-- Plugin Versions -->
    <compiler.plugin.version>2.4</compiler.plugin.version>
    <surefire.plugin.version>2.12.4</surefire.plugin.version>
    <skipTests>true</skipTests>
    <jboss.cache.version>3.2.5.GA</jboss.cache.version>
    <maven.build.timestamp.format>yyyyMMdd-HHmmss</maven.build.timestamp.format>
</properties>

<modules>
    <module>sample-service</module>
</modules>

<dependencyManagement>
    <dependencies>
        <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>
        <!-- This dependency is needed if you're using the Jetty container -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>${httpclient.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>${rs-api.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <!-- This plugin is used update the version numbers of the project
                    during the release process. -->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>${versions.plugin.version}</version>
                <configuration>
                    <generateBackupPoms>false</generateBackupPoms>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <!-- Plugin configuration for the plugin that specifies the base file encoding. -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>${resources.plugin.version}</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <outputDirectory>${project.build.outputDirectory}</outputDirectory>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${compiler.plugin.version}</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)


样本服务pom

<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>
<parent>
    <groupId>com.crush</groupId>
    <artifactId>tests</artifactId>
    <version>1.0</version>
</parent>
<artifactId>sample-service</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Simple CXF project using spring configuration</name>
<dependencies>
  <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxws</artifactId>
  </dependency>
  <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http</artifactId>
  </dependency>
  <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http-jetty</artifactId>
  </dependency>
  <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
  </dependency>
  <dependency>
      <groupId>commons-httpclient</groupId>
      <artifactId>commons-httpclient</artifactId>
  </dependency>
  <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>javax.ws.rs-api</artifactId>
  </dependency>
</dependencies>
<profiles>
        <profile>
              <id>server</id>
            <build>
                <defaultGoal>test</defaultGoal>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.2.1</version>
                        <executions>
                            <execution>
                                <phase>test</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                                <configuration>
                                    <mainClass>com.crush.tests.service.Test</mainClass>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
</profiles>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.crush.tests.service.Test</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)


MANIFEST.MF清单版本:1.0存档版本:Plexus存档创建者:Apache Maven构建者:美眉Build-Jdk:1.7.0_55

主要类别:com.crush.tests.service.Test

SampleServiceImpl

package com.crush.tests.service.ws.impl;

import javax.jws.WebService;

import com.crush.tests.service.ws.SampleService;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
impo rt javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

@WebService(endpointInterface = "com.crush.tests.service.ws.SampleService")
@Path("/sample/")
@Produces("text/xml")
public class SampleServiceImpl implements SampleService
{
public SampleServiceImpl()
{

}

@GET
@Path("/hi/{text}")
public String sayHi(@PathParam("text") String text)
{
    return "Hello " + text;
}


}
Run Code Online (Sandbox Code Playgroud)

当我使用以下命令运行该命令时:mvn -Pserver
2014年6月27日3:10:26 org.apache.cxf.endpoint.ServerImpl initDestination
信息:将服务器的发布地址设置为http://:// localhost:9000 /
SLF4J:失败加载类“ org.slf4j.impl.StaticLoggerBinder”。SLF4J:默认为不操作(NOP)记录器实现SLF4J:有关更多详细信息,请参见http://www.slf4j.org/codes.html#StaticLoggerBinder
服务器就绪...

和以前一样,从捆绑的jar中运行
java -cp sample-service-1.0-jar-with-dependencies.jar com.crush.tests.service.Test线程“ main” org.apache.cxf.service中的异常。 com.crush.tests.service.Test上com.crush.tests.service.Test。(Test.java:25)上的org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:205)上的factory.ServiceConstructionException .main(Test.java:30)原因:org.apache.cxf.BusException:找不到命名空间http://cxf.apache.org/transports/http的 DestinationFactory。。在org.apache.cxf.endpoint.ServerImpl的org.apache.cxf.bus.managers.DestinationFactoryManagerImpl.getDestinationFactory(DestinationFactoryManagerImpl.java:130)在org.apache.cxf.endpoint.ServerImpl.initDestination(ServerImpl.java:78) 。(ServerImpl.java:62)at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:159)...还有2个

如果浏览sample-service-1.0-jar-with-dependencies.jar,则可以导航到/ org / apache / cxf / transport(s)并在依赖的jar中找到任何类。

Cru*_*ing 3

问题是 cxf 类需要在类路径上设置,即使它们被捆绑到我的 jar 中......没有道理为什么,但这就是修复。

  • 您能否添加解决问题所遵循的程序的详细信息?谢谢。 (5认同)