使用 Felix File install 创建多个 iPojo bundle 实例

Use Felix File install to create multiple iPojo bundle instances

我正在尝试使用 属性 部署 iPojo 包。捆绑包如下所示:

@Component
public class Greeter {

    @Property(name = "greeting")
    private String greeting;

    @Validate
    public void start() {
        System.out.println(greeting);
    }

}

pom.xml 看起来像这样:

<groupId>com.example.my</groupId>
    <artifactId>osgi-greeter</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.ipojo.annotations</artifactId>
            <version>1.12.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <!-- BND Maven Plugin Configuration -->
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <!--<Private-Package>$YOUR_PRIVATE_PACKAGE</Private-Package> <Export-Package>$YOUR_EXPORTED_PACKAGE</Export-Package> -->
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-ipojo-plugin</artifactId>
                <version>1.12.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>ipojo-bundle</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

我正在使用 Apache Felix 作为 OSGi 运行时。我添加了文件安装包并配置了它的路径。我在路径中添加了 osgi-greeter 包和一个名为 com.example.my.Greeter.cfg 的配置文件,如下所示:

greeting = Hello World

我打开了 Felix 的调试日志,可以看到,fileinstall 包已经加载了它的参数。但是,它没有做任何事情。我可以手动安装和启动捆绑包,但它显然只向控制台输出 null。目标是添加多个配置文件并让 fileinstall 从它们启动实例。有什么想法可以实现吗?或者我可以做些什么来使 fileinstall 以这种方式工作?

我设法修复了它。基本上,我将多个配置文件添加到名为:

的 watched fileinstall 文件夹中
  • com.example.my.Greeter-A.cfg
  • com.example.my.Greeter-B.cfg
  • com.example.my.Greeter-C.cfg

我认为 class 名称后的实例标识符只需要在文件名中使用即可。