我想从官方文档中复制helloworld应用程序。我的应用程序称为Testapp,我是从org.opendaylight.controller groupId版本1.5.0创建的。添加示例代码(来自官方文档)并启动karaf后,我收到与databroker相关的错误。
状态:失败 蓝图 18/08/11 18:42 例外: 无法从配方ReferenceRecipe [name ='dataBroker']加载org.opendaylight.controller.md.sal.binding.api.DataBroker类 org.osgi.service.blueprint.container.ComponentDefinitionException:无法从配方ReferenceRecipe [name ='dataBroker']加载类org.opendaylight.controller.md.sal.binding.api.DataBroker 在org.apache.aries.blueprint.container.AbstractServiceReferenceRecipe.loadType(AbstractServiceReferenceRecipe.java:309) 在org.apache.aries.blueprint.di.AbstractRecipe.loadClass(AbstractRecipe.java:149) 在org.apache.aries.blueprint.container.AbstractServiceReferenceRecipe.getInterfaceClass(AbstractServiceReferenceRecipe.java:392) 在org.apache.aries.blueprint.container.ReferenceRecipe.internalCreate(ReferenceRecipe.java:100) 在org.apache.aries.blueprint.di.AbstractRecipe $ 1.call(AbstractRecipe.java:79) 在java.util.concurrent.FutureTask.run(FutureTask.java:266) 在org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88) 在org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:255) 在org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:186) 在org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:704) 在org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:410) 在org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:275) 在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511) 在java.util.concurrent.FutureTask.run(FutureTask.java:266) 在org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106) 在org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48) 在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511) 在java.util.concurrent.FutureTask.run(FutureTask.java:266) 在java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.access $ 201(ScheduledThreadPoolExecutor.java:180) 在java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624) 在java.lang.Thread.run(Thread.java:748) 引起原因:java.lang.ClassNotFoundException:org.opendaylight.testapp.impl_0.1.0找不到org.opendaylight.controller.md.sal.binding.api.DataBroker 在org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461) 在org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372) 在org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364) 在org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161) 在java.lang.ClassLoader.loadClass(ClassLoader.java:357) 在org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:564) 在org.apache.aries.blueprint.container.BlueprintContainerImpl.loadClass(BlueprintContainerImpl.java:447) 在org.apache.aries.blueprint.container.GenericType.parse(GenericType.java:137) 在org.apache.aries.blueprint.container.AbstractServiceReferenceRecipe.loadType(AbstractServiceReferenceRecipe.java:307) ...另外22个
声明性服务
我的TestappProvider.java
package org.opendaylight.testapp.impl;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext ;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.testapp.rev170830.TestappService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestappProvider implements BindingAwareProvider, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(TestappProvider.class);
private RpcRegistration<TestappService> helloService;
@Override
public void onSessionInitiated(ProviderContext session) {
LOG.info("TestappProvider Session Initiated");
helloService = session.addRpcImplementation(TestappService.class, new TestappImpl());
}
@Override
public void close() throws Exception {
LOG.info("TestappProvider Closed");
if (helloService != null) {
helloService.close();
}
}
}
我的TestappImpl
package org.opendaylight.testapp.impl;
import java.util.concurrent.Future;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.testapp.rev170830.TestappService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.testapp.rev170830.HelloWorldInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.testapp.rev170830.HelloWorldOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.testapp.rev170830.HelloWorldOutputBuilder;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
public class TestappImpl implements TestappService {
@Override
public Future<RpcResult<HelloWorldOutput>> helloWorld(HelloWorldInput input) {
HelloWorldOutputBuilder helloBuilder = new HelloWorldOutputBuilder();
helloBuilder.setGreating("Hello " + input.getName());
return RpcResultBuilder.success(helloBuilder.build()).buildFuture();
}
}