【发布时间】:2021-07-22 12:30:46
【问题描述】:
我正在从 Felix SCR 注释迁移到 R6 OSGI 声明式服务,但该服务未在 karaf 中列出。根据以下代码 SampleServiceImpl 应该列出的是 karaf 。但它没有列出。 我必须在 pom.xml 中进行任何其他配置吗?
package com.sample.test;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ConfigurationPolicy;
import org.osgi.service.component.annotations.Deactivate;
@Component (configurationPolicy = ConfigurationPolicy.OPTIONAL, immediate = true, service = SampleService.class)
public class SampleServiceImpl implements SampleService
{
@Reference (policy = ReferencePolicy.DYNAMIC, service = AgentService.class , bind = "bindAgentService",unbind ="unbindAgentService")
private AgentService agentService;
@Activate
protected void activate() {
System.out.println("activate ");
}
@Deactivate
protected void deactivate() {
System.out.println("de-activate ");
}
}
这是我正在使用的 pom.xml。
<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">
<groupId>com.test.sample</groupId>
<artifactId>compile</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>osgi.cmpn</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
【问题讨论】:
标签: maven osgi osgi-bundle apache-felix declarative-services