gpt4 book ai didi

Java OSGi : InstantiationException with Declarative Services

转载 作者:行者123 更新时间:2023-11-29 06:17:48 25 4
gpt4 key购买 nike

我是 OSGi 的新手,正在构建第一个 DS 实现。

一切都是根据“书”编码的,但在运行时出现此错误:

java.lang.InstantiationException: com.mine.logger.internal.udp.UdpListener
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.eclipse.equinox.internal.ds.model.ServiceComponent.createInstance(ServiceComponent.java:457)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.createInstance(ServiceComponentProp.java:264)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:325)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:588)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:196)
at org.eclipse.equinox.internal.ds.Resolver.getEligible(Resolver.java:328)
at org.eclipse.equinox.internal.ds.SCRManager.serviceChanged(SCRManager.java:221)
at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:104)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:933)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:756)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:711)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:130)
at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:206)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.registerService(BundleContextImpl.java:507)
at org.eclipse.equinox.internal.ds.InstanceProcess.registerService(InstanceProcess.java:504)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:212)
at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:441)
at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:213)
at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:800)
at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:767)
at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
at org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor.run(Executor.java:70)

这是我想在其他模块中使用的模块的configuration.xml:

<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="startup" deactivate="shutdown" immediate="true" name="com.mine.logger.storeindb">
<implementation class="com.mine.logger.internal.storeindb.StoreLog"/>
<service>
<provide interface="com.mine.logger.storeindb.IStoreLog"/>
</service>
</scr:component>

这是将使用它的模块的 configuration.xml:

<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.mine.logger.udp">
<implementation class="com.mine.logger.internal.udp.UdpListener"/>
<reference bind="setStoreLog" interface="com.mine.logger.storeindb.IStoreLog" name="storelog" unbind="unsetStoreLog"/>
</scr:component>

绑定(bind)和解除绑定(bind)代码:

private IStoreLog storeLog;

public void setStoreLog(IStoreLog value)
{
System.err.println("UdpListener > setStoreLog");
this.storeLog = value;
}

public void unsetStoreLog(IStoreLog value)
{
System.err.println("UdpListener > unsetStoreLog");
if (this.storeLog == value) {
this.storeLog = null;
}
}

有什么想法吗?谢谢,弗兰克

最佳答案

InstantiationException :

Thrown when an application tries to create an instance of a class using the newInstance method in class Class, but the specified class object cannot be instantiated. The instantiation can fail for a variety of reasons including but not limited to:

  • the class object represents an abstract class, an interface, an array class, a primitive type, or void
  • the class has no nullary constructor

com.mine.logger.internal.udp.UdpListener 是否有一个公共(public)的、无参数的构造函数?

关于Java OSGi : InstantiationException with Declarative Services,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4396777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com