我正在从Apache Felix SCR Annotations更新到OSGi DS R6,而这个问题导致我更多的问题是类中的@Property。
我之前:
@Component (immediate = true)
@Service (A.class)
public class AImpl implements A
{
@Property (intValue = 604800)
public static final String A = "a";
...
}
现在我有:
@Component (service = A.class, immediate = true)
@Designate (ocd = Configuration.class)
public class AImpl implements A
{
...
}
和
@ObjectClassDefinition (name = "Bla")
public @interface Configuration
{
@AttributeDefinition (name = "A", type = AttributeType.INTEGER)
int A() default 604800;
}
所有这一切最离奇的是:
之前,我可以看到我的AImpl类作为一个组件。
现在,我看不到我的AImpl类作为一个组件,并且每个使用它的人都因为不满意的引用而无法启动。
如何改变这样的配置会导致这种行为?也许我错过了什么?
所有这一切的陌生人部分是我的xml在.jar内部,似乎没问题。 scr:info让我得到nullpointer异常,我看不到我的组件,这意味着scr:list对任何事都没有帮助。
XML BELLOW:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="AImpl" immediate="true" activate="init" deactivate="stop">
<implementation class="AImpl"/>
<service>
<provide interface="A"/>
</service>
<reference name="Bla1" interface="Bla1Service" bind="bindBla1Service" unbind="unbindBla1Service"/>
<property name="PROP.EVENT.INTERVAL" type="Long" value="900000"/>
</scr:component>
Ps。:这些课程名称很奇怪,因为它来自私人公司。
堆栈跟踪:
2017-12-11T16:40:27.689 + 0100 [Framework Event Dispatcher] ERROR o.o.p.l.l.internal.FrameworkHandler:144 frameworkEvent FrameworkEvent ERROR - org.apache.felix.scr org.osgi.framework.BundleException:包org.apache.felix.scr的激活器org.apache.felix.scr.impl.Activator无效 在org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:172) 在org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:679) 在org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381) 在org.eclipse.osgi.framework.internal.core.AbstractBundle.updateWorker(AbstractBundle.java:645) 在org.eclipse.osgi.framework.internal.core.AbstractBundle.update(AbstractBundle.java:592) 在org.apache.felix.webconsole.internal.core.UpdateHelper.doRun(UpdateHelper.java:60) 在org.apache.felix.webconsole.internal.core.BaseUpdateInstallHelper.doRun(BaseUpdateInstallHelper.java:93) 在org.apache.felix.webconsole.internal.core.UpdateHelper.doRun(UpdateHelper.java:70) 在org.apache.felix.webconsole.internal.core.BaseUpdateInstallHelper.run(BaseUpdateInstallHelper.java:123) 在java.lang.Thread.run(Thread.java:748) 引起:java.lang.ClassCastException:org.apache.felix.scr.impl.Activator无法强制转换为org.osgi.framework.BundleActivator 在org.eclipse.osgi.framework.internal.core.AbstractBundle.loadBundleActivator(AbstractBundle.java:167) ...省略了9个常见帧
在karaf我的软件包上安装的POM.XML的一部分:
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-kar-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<inherited>false</inherited>
<configuration>
<includeScope>runtime</includeScope>
<prependGroupId>true</prependGroupId>
<excludeTransitive>true</excludeTransitive>
<artifactItems>
<artifactItem>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.framework</artifactId>
<version>${org.osgi.framework.version}</version>
</artifactItem>
<artifactItem>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>${org.osgi.core.version}</version>
</artifactItem>
<artifactItem>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr</artifactId>
<version>${org.apache.felix.scr.version}</version>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
答案 0 :(得分:1)
此部分看起来像错误:service=AImpl.class
。您的组件应使用其接口A
作为服务发布,而不是实现类。
这通常是隐式发生的,因为组件直接实现了接口A,但是你已经覆盖了它。
解决方案应该是从service=AImpl.class
注释中删除@Component
属性。
答案 1 :(得分:1)
您的AImpl
课程仍然是一个组件。但是,现在它是一个配置&#34;组件,因此它有@Designate
注释链接到@ObjectClassDefinition
属性类。
转到“配置”选项卡,您应该会看到“组件”及其属性。