CXF BusException No DestinationFactory for namespa

2019-06-26 09:56发布

问题:

I'm trying to stand up the [basic cxf rs example][1], but with my own service impl which is even simpler and all my methods return strings. When I try to run this server I get this exception

I built a clean project so I'm starting fresh..

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


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


MANIFEST.MF Manifest-Version: 1.0 Archiver-Version: Plexus Archiver Created-By: Apache Maven Built-By: crush Build-Jdk: 1.7.0_55

Main-Class: 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;
}


}

When I run this with: mvn -Pserver
Jun 27, 2014 3:10:26 PM org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be http ://localhost:9000/
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Server ready...

Like I was before, and running from the bundled jar
java -cp sample-service-1.0-jar-with-dependencies.jar com.crush.tests.service.Test Exception in thread "main" org.apache.cxf.service.factory.ServiceConstructionException at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:205) at com.crush.tests.service.Test.(Test.java:25) at com.crush.tests.service.Test.main(Test.java:30) Caused by: org.apache.cxf.BusException: No DestinationFactory was found for the namespace http://cxf.apache.org/transports/http. at org.apache.cxf.bus.managers.DestinationFactoryManagerImpl.getDestinationFactory(DestinationFactoryManagerImpl.java:130) at org.apache.cxf.endpoint.ServerImpl.initDestination(ServerImpl.java:78) at org.apache.cxf.endpoint.ServerImpl.(ServerImpl.java:62) at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:159) ... 2 more

If I browse the sample-service-1.0-jar-with-dependencies.jar I can navigate to /org/apache/cxf/transport(s) as well as find any of the classes in the dependent jars.

回答1:

Problem was that the cxf classes needed to be set on the classpath even though they were bundled into my jar... Didn't make sense why but that was the fix.



回答2:

Seems classloader changes from using manifest than from using java -cp

Here is the different:

http://grepcode.com/file/repo1.maven.org/maven2/org.apache.cxf/cxf-rt-core/2.7.17/org/apache/cxf/bus/extension/ExtensionManagerImpl.java#164

with classpath, Classloader finds several jars with META-INF/cxf/bus-extensions.txt but with manifest only cxf-core (which don't have that http transport defined)