Osgi 使用iPOJO API显示;无法创建POJO实例,找不到POJO构造函数";

Osgi 使用iPOJO API显示;无法创建POJO实例,找不到POJO构造函数";,osgi,bundle,apache-felix,osgi-bundle,ipojo,Osgi,Bundle,Apache Felix,Osgi Bundle,Ipojo,IPOJOAPI似乎很难处理,尤其是在嵌入OSGI框架时。在通过将API编码行保存在OSGI包中解决了类加载器问题之后,我在这里遇到了一个新的不同问题: 在我的bundle start方法中,我有以下代码: public void start(BundleContext context) { ComponentType x = new PrimitiveComponentType() .setBundleContext(context)

IPOJOAPI似乎很难处理,尤其是在嵌入OSGI框架时。在通过将API编码行保存在OSGI包中解决了类加载器问题之后,我在这里遇到了一个新的不同问题:

在我的bundle start方法中,我有以下代码:

public void start(BundleContext context)
{

    ComponentType x = new PrimitiveComponentType()
            .setBundleContext(context)
            .setClassName(InstanceFactoryImpl.class.getName())
            .setValidateMethod("start")
            .setInvalidateMethod("stop");


            x.start();

            try {
                x.createInstance();
            } catch (UnacceptableConfiguration e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (MissingHandlerException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ConfigurationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            System.out.println("and we are done!");
}
InstanceFactoryImpl
类与以下内容位于同一个包中:

public class InstanceFactoryImpl implements instancefactory.InstanceFactory{


    @Override
    public void start() {



    }

    @Override
    public void stop() {

    }



}
在java应用程序中将包加载到Felix framework时,出现以下错误:

[ERROR]  : [instancefactoryImpl.InstanceFactoryImpl-0] createInstance -> Cannot invoke the constructor (method not found) : instancefactoryImpl.InstanceFactoryImpl.<init>(org.apache.felix.ipojo.InstanceManager)
java.lang.NoSuchMethodException: instancefactoryImpl.InstanceFactoryImpl.<init>(org.apache.felix.ipojo.InstanceManager)
    at java.lang.Class.getConstructor0(Class.java:2715)
    at java.lang.Class.getDeclaredConstructor(Class.java:1987)
    at org.apache.felix.ipojo.InstanceManager.createObject(InstanceManager.java:726)
    at org.apache.felix.ipojo.InstanceManager.getPojoObject(InstanceManager.java:923)
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:156)
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java)
    at org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:536)
    at org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:418)
    at org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:179)
    at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:319)
    at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:240)
    at org.apache.felix.ipojo.api.ComponentType.createInstance(ComponentType.java:79)
    at instancefactoryImpl.Activator.start(Activator.java:37)
    at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:2146)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
    at embedder.HostApplication.<init>(HostApplication.java:148)
    at embedder.Embedder.main(Embedder.java:12)
[ERROR] instancefactoryImpl.InstanceFactoryImpl : Cannot create a POJO instance, the POJO constructor cannot be found
org.apache.felix.ipojo.ConfigurationException: The configuration is not correct for the type instancefactoryImpl.InstanceFactoryImpl : Cannot create a POJO instance, the POJO constructor cannot be found
    at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:328)
    at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:240)
    at org.apache.felix.ipojo.api.ComponentType.createInstance(ComponentType.java:79)
    at instancefactoryImpl.Activator.start(Activator.java:37)
    at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
    at org.apache.felix.framework.Felix.activateBundle(Felix.java:2146)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
    at embedder.HostApplication.<init>(HostApplication.java:148)
    at embedder.Embedder.main(Embedder.java:12)
Caused by: org.apache.felix.ipojo.ConfigurationException: Cannot create a POJO instance, the POJO constructor cannot be found
    at org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:191)
    at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory.java:319)
    ... 10 more
Caused by: java.lang.RuntimeException: Cannot create a POJO instance, the POJO constructor cannot be found
    at org.apache.felix.ipojo.InstanceManager.createObject(InstanceManager.java:766)
    at org.apache.felix.ipojo.InstanceManager.getPojoObject(InstanceManager.java:923)
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.__M_stateChanged(LifecycleCallbackHandler.java:156)
    at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHandler.stateChanged(LifecycleCallbackHandler.java)
    at org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:536)
    at org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:418)
    at org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory.java:179)
    ... 11 more
Caused by: java.lang.NoSuchMethodException: instancefactoryImpl.InstanceFactoryImpl.<init>(org.apache.felix.ipojo.InstanceManager)
    at java.lang.Class.getConstructor0(Class.java:2715)
    at java.lang.Class.getDeclaredConstructor(Class.java:1987)
    at org.apache.felix.ipojo.InstanceManager.createObject(InstanceManager.java:726)
    ... 17 more

我试图显式定义一个构造函数,并添加一个名为“init”的方法。所有这些都失败了,同样的错误不断出现。我该怎么办?谢谢?

iPOJO核心捆绑包和iPOJO API捆绑包之间存在版本不匹配问题。如果您使用的是iPOJO 1.11.0,则需要使用iPOJO API 1.11.0

在iPOJO 1.11.0中,我们更改了操纵器过程。这使得由旧版本的iPOJO API检测的包不合适


有关

您的
ComponentType
类是否实现了无参数
.createInstance()
工厂方法的更多详细信息?为了其他人的利益,请阅读您的答案并更新它。我认为它有拼写错误。谢谢。如何知道IPOJO的版本!?它要么写在bundle文件名中,要么是bundle版本(在bundle的清单中)。
x.createInstance();