带有 CDI 注释的蓝图 + Karaf + JaxRX CXF ServiceConstructionException:找不到资源 类

Blueprint with CDI annotations + Karaf + JaxRX CXF ServiceConstructionException: No resource classes found

我正在尝试关注 post

http://blog.nanthrax.net/2011/08/jax-rs-services-using-cxf-and-karaf/

我在安装服务包时遇到以下异常请告诉我哪里出错了

API Class

休息 API

package rest.frontend_jaxrs.api;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;


@Path("/")
public interface PersonService {

    @GET
    @Path("all")
    @Produces(MediaType.APPLICATION_XML)
    public Response getAll();

}

实现

RESTIMPL

package frontend_jaxrs.provider.service;

import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

import org.eclipse.jetty.http.HttpStatus;
import org.ops4j.pax.cdi.api.OsgiService;

import frontend_jaxrs.api.HelloService;
import rest.pbm_frontend_jaxrs.api.PersonService;

@Path("")
@Named
public class PersonServiceImpl implements PersonService {

    @Inject
    @OsgiService
    HelloService helloService;

    @Override
    public Response getAll() {

        Response response = Response.ok(helloService.sayHello("Athish")).status(HttpStatus.OK_200).build();

        return response;
    }

}

蓝图

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"  
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
           xmlns:jaxws="http://cxf.apache.org/blueprint/jaxws"
           xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
           xmlns:cxf="http://cxf.apache.org/blueprint/core"
           xsi:schemaLocation="
  http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
  http://cxf.apache.org/blueprint/jaxws http://cxf.apache.org/schemas/blueprint/jaxws.xsd
  http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
  http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd">
<!-- 1 -->  
    <cxf:bus id="cxfBus1">
        <cxf:features>
            <cxf:logging/>
        </cxf:features>
    </cxf:bus>

<!-- 2 -->  
    <jaxrs:server address="/person" id="personRestService">
        <jaxrs:serviceBeans>
            <ref component-id="personServiceImpl"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>

</blueprint>

autowire.xml 从插件生成

<?xml version="1.0" ?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0">
<bean id="helloServiceImpl" class="ca.esc.pbm.fe.pbm_frontend_jaxrs.provider.service.HelloServiceImpl">
</bean>
<service ref="helloServiceImpl" interface="ca.esc.pbm.fe.pbm_frontend_jaxrs.api.HelloService">    <service-properties>
        <entry key="service.exported.interfaces" value="*"/>
    </service-properties>
</service>
</blueprint>

安装 Rest IMPL 出现异常

ServiceConstructionException

org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to initialize bean personRestService
        at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:738) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:848) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:811) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.di.AbstractRecipe.call(AbstractRecipe.java:79) [12:org.apache.aries.blueprint.core:1.8.0]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
        at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:255) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:186) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:725) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:412) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:277) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:300) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:269) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:265) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:255) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422) [12:org.apache.aries.blueprint.core:1.8.0]
        at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1179) [?:?]
        at org.apache.felix.framework.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:730) [?:?]
        at org.apache.felix.framework.EventDispatcher.fireBundleEvent(EventDispatcher.java:485) [?:?]
        at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4562) [?:?]
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2172) [?:?]
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998) [?:?]
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:984) [?:?]
        at org.apache.karaf.bundle.command.Install.execute(Install.java:115) [21:org.apache.karaf.bundle.core:4.1.1]
        at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:84) [42:org.apache.karaf.shell.core:4.1.1]
        at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:68) [42:org.apache.karaf.shell.core:4.1.1]
        at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:86) [42:org.apache.karaf.shell.core:4.1.1]
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:560) [42:org.apache.karaf.shell.core:4.1.1]
        at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:486) [42:org.apache.karaf.shell.core:4.1.1]
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:375) [42:org.apache.karaf.shell.core:4.1.1]
        at org.apache.felix.gogo.runtime.Pipe.doCall(Pipe.java:417) [42:org.apache.karaf.shell.core:4.1.1]
        at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:229) [42:org.apache.karaf.shell.core:4.1.1]
        at org.apache.felix.gogo.runtime.Pipe.call(Pipe.java:59) [42:org.apache.karaf.shell.core:4.1.1]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:?]
        at java.lang.Thread.run(Thread.java:745) [?:?]
Caused by: org.apache.cxf.service.factory.ServiceConstructionException
        at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:219) ~[?:?]
        at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.init(JAXRSServerFactoryBean.java:142) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:483) ~[?:?]
        at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:299) ~[?:?]
        at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:980) ~[?:?]
        at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:736) ~[?:?]
        ... 40 more
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: No resource classes found
        at org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.checkResources(AbstractJAXRSFactoryBean.java:317) ~[?:?]
        at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:159) ~[?:?]
        at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.init(JAXRSServerFactoryBean.java:142) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:483) ~[?:?]
        at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:299) ~[?:?]
        at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:980) ~[?:?]
        at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:736) ~[?:?]
        ... 40 more

两个蓝图上下文似乎不一致。

<ref component-id="personServiceImpl"/>

但在autowire.xml中有:

<bean id="helloServiceImpl" class="ca.esc.pbm.fe.pbm_frontend_jaxrs.provider.service.HelloServiceImpl">
</bean>

所以这行不通。