Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Apache Felix SCR更新为OSGi声明性服务R6-@属性_Osgi_Apache Karaf_Declarative Services - Fatal编程技术网

将Apache Felix SCR更新为OSGi声明性服务R6-@属性

将Apache Felix SCR更新为OSGi声明性服务R6-@属性,osgi,apache-karaf,declarative-services,Osgi,Apache Karaf,Declarative Services,我正在从ApacheFelixSCR注释更新到OSGiDSR6注释,而引起我更多问题的是类中的@Property 在我之前: @Component (immediate = true) @Service (A.class) public class AImpl implements A { @Property (intValue = 604800) public static final String A = "a"; ... } 现在我有: @Component (s

我正在从ApacheFelixSCR注释更新到OSGiDSR6注释,而引起我更多问题的是类中的@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
{
    ...
}

这一切中最奇怪的事情是:

以前,我可以将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>

注:这些类都有奇怪的名字等等,因为它们来自一家私人公司

堆栈跟踪:

2017-12-11T16:40:27.689+0100[Framework Event Dispatcher]错误o.o.p.l.l.internal.FrameworkHandler:144 frameworkEvent frameworkEvent错误-org.apache.felix.scr org.osgi.framework.BundleException:bundle org.apache.felix.scr.impl.activator for bundle org.apache.felix.scr无效 位于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) 运行(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 my Bundle上的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>
maven依赖插件
复制kar依赖项
包裹
复制依赖项
假的
运行时
真的
真的
org.osgi
org.osgi.framework
${org.osgi.framework.version}
org.osgi
org.osgi.core
${org.osgi.core.version}
org.apache.felix
org.apache.felix.scr
${org.apache.felix.scr.version}

此部分看起来像错误:
service=AImpl.class
。您的组件应该使用其接口
a
作为服务发布,而不是实现类

这通常是隐式的,因为组件直接实现接口A,但您已经覆盖了接口A


解决方案应该是简单地从
@Component
注释中删除
service=AImpl.class
属性。

您的
AImpl
类仍然是一个组件。但是,现在它是一个“配置”组件,因此它有一个链接到属性类的
@ObjectClassDefinition
注释


转到“配置”选项卡,您将看到您的组件及其属性。

尝试使用scr:list和scr:info命令获取有关组件未出现的原因的更多详细信息。请将scr:info或scr:details(取决于karaf版本)的输出添加到问题中。如果我是你,我会检查XML文件是否在构建过程中生成到JAR文件中。之后,我将检查XML文件是否具有正确的内容。如果有XML文件,请将它们附加到这个问题上好吗?除了使用
scr:list
scr:info
命令外,您还应该使用
log error
命令查看OSGi日志。例如,如果组件从其激活方法引发异常,则详细信息将显示在此日志中。更新了主帖子…@raullalves,您不能。Karaf 3.0.x仅支持OSGi版本5(请参阅),而SCR 2.x需要OSGi版本6。您需要将Karaf升级到版本4.1.x或将SCR降级到版本1.8.2。是的,这是真的,我犯了一些错误,但我改为使用接口而不是实现类,即使这样,我仍然无法将其视为组件。
<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>