我是Apache Karaf的新手,我正在部署一个简单的捆绑软件,它在启动时打印日期。我已经使用Activator类实现了它,它调用Activator启动方法并打印出日期。我正在阅读的是,如果没有Activator并使用蓝图注册我的服务,我可以实现另一种方法。Apache Karaf捆绑软件注册监听器注册方法永远不会触发
我已经写了包,并在Karaf容器部署它,但它并没有打印出日期,下面所描述的甚至从来都没有调用注册方法:
<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<bean id="timeGreetServiceImpl" class="com.cengage.wiring.TimeGreetServiceImpl">
<argument ref="timeService"/>
<argument ref="sampleService"/>
</bean>
<bean id="serviceLaunch" class="com.cengage.wiring.ServiceLaunch"></bean>
<reference id="sampleService" activation="eager" availability="mandatory" interface="com.cengage.api.SampleService">
</reference>
<reference id="timeService" activation="eager" availability="mandatory" interface="com.cengage.register.api.SimpleTimeService">
</reference>
<service id="timeGreetService" interface="com.cengage.wiring.TimeGreetService" ref="timeGreetServiceImpl">
<registration-listener ref="serviceLaunch" registration-method="register" unregistration-method="unregister"/>
</service>
</blueprint>
这是我的POJO类,它有注册方法
public class ServiceLaunch {
public void register(final TimeGreetService service) {
System.out.println("TimeGreetService registered - output: "
+ service.print());
}
public void unregister() {
}
}
有人可以告诉我我错过了什么吗?卡拉夫没有错误或日志。
谢谢
尝试2: 正如我改变了我的蓝图的意见要求,但它仍然没有命中寄存器方法
<blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<bean id="timeGreetServiceImpl" class="com.cengage.wiring.TimeGreetServiceImpl">
<argument ref="timeService"/>
<argument ref="sampleService"/>
</bean>
<bean id="serviceLaunch" class="com.cengage.wiring.ServiceLaunch"></bean>
<reference id="sampleService" activation="eager" availability="optional" interface="com.cengage.api.SampleService">
</reference>
<reference id="timeService" activation="eager" availability="optional" interface="com.cengage.register.api.SimpleTimeService">
</reference>
<service id="timeGreetService" interface="com.cengage.wiring.TimeGreetService" ref="timeGreetServiceImpl">
<registration-listener ref="serviceLaunch" registration-method="register" unregistration-method="unregister"/>
</service>
</blueprint>
请忽略我的第一个答案。我以为你引用了你发布的同样的服务。情况并非如此,因此可选不是必需的。 –
您可以使用以下服务查看karaf中的服务:列表命令。它显示你依赖的服务,也可能是你发布的服务? –
也许问题在于你试图注册一个类型为'TimeGreetService'的服务,但是你的类没有实现'TimeGreetService'。此外,为什么你关心你自己的服务注册的确切时间?为什么不去一个简单的激活方法? –