Apache Felix OSGi error: missing requirement osgi.extender

Apache Felix OSGi error: missing requirement osgi.extender

我在尝试启动捆绑包时遇到此错误:

org.osgi.framework.BundleException:
  Unable to resolve com.example.test [7](R 7.0):
    missing requirement [com.example.test [7](R 7.0)] osgi.extender; (&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))
  Unresolved requirements:
    [[com.example.test [7](R 7.0)] osgi.extender; (&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))]

我的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>bundle</packaging>

    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>6.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.service.component.annotations</artifactId>
            <version>1.4.0</version>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <version>4.0.0</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <configuration>
                    <instructions>
                        <Export-Package>com.example</Export-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

代码:

Facade.java:

package com.example;
public interface Facade {}

FacadeLocator.java:

package com.example;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

@Component
public class FacadeLocator {
    public static Facade facade;

    @Reference
    public void setFacade(Facade facade) {
        FacadeLocator.facade = facade;
    }
}

我做错了什么?

谢谢

您的包包含一个声明式服务组件 -- FacadeLocator 来自您的代码。这意味着您依赖于实现声明式服务的 "extender" 包。您需要将该捆绑包与您自己的捆绑包一起部署才能使其正常工作。

来自 Apache Felix 的 DS 实现包的名称为 org.apache.felix.scr,可以下载 from Maven Central

您看到的错误信息可以解码如下。 osgi.extender 命名空间(类似于 DS 的扩展程序的命名空间)中缺少要求。您需要的特定扩展程序是 osgi.component,版本 1.3 或更高版本。 maven-bundle-plugin 在你的 bundle 的 META-INF/MANIFEST.MF 中生成了这个需求,因为它看到你的 bundle 中有一个组件。每当一个 bundle 有一个 要求 时,必须有另一个 bundle 提供匹配的 capability。在这种情况下,该捆绑包是 org.apache.felix.scr.

在 karaf 中使用此命令安装声明式服务支持功能 feature:install scr