IPOJO组件未正确公开服务



我有类似的ipojo组件

@Component(immediate = true)
@Provides
public class MyComponent implements MyService
{
@Override
public boolean islock()
{
return true;
}
}

当我部署在卡拉夫与以下命令

bundle:install -s mvn:com.my.osgi/mycomponent/0.0.1

如果我做服务:在karaf控制台上列出,它会显示类似的输出

[org.apache.felix.ipojo.Factory] 
-------------------------------- 
component.class = com.my.osgi.mycomponent 
component.description = factory name="com.my.osgi.mycomponent" 
bundle="77" state="valid" implementation-class="com.my.osgi.mycomponent" 
requiredhandlers list="[org.apache.felix.ipojo:properties, 
org.apache.felix.ipojo:callback, org.apache.felix.ipojo:provides, 
org.apache.felix.ipojo:architect 
ure]" 
missinghandlers list="[]" 
provides specification="com.my.osgi.mycomponent" 
inherited interfaces="[com.my.osgi.mycomponent]" 
superclasses="[]" 
component.providedServiceSpecifications = [com.my.osgi.mycomponent] 
factory.name = com.my.osgi.mycomponent 
factory.state = 1 
service.bundleid = 77 
service.id = 153 
service.pid = com.my.osgi.mycomponent 
service.scope = singleton 

但我期待着如下,

[com.my.osgi.mycomponent] 
----------------------------------------------------- 
instance.name = mycomponent.3c2c91a5-4c28-46c3-a08e-1470192ef353 
service.bundleid = 76 
service.factoryPid = com.my.osgi.mycomponent 
service.id = 397 
service.pid = 
com.my.osgi.mycomponent.3c2c91a5-4c28-46c3-a08e-1470192ef353 
service.scope = bundle 

我做错了什么?我正在和maven一起建设。

编辑:一个观察结果是,这个捆绑包在一个更大的应用程序中工作,当它得到部署日志时,它是

2018-07-17T12:03:50,011 | DEBUG | [iPOJO] pool-1-thread-1 | my-component | 38 - com.my.osgi.my-component  - 1.0.3 | ServiceEvent REGISTERED - [org.apache.felix.ipojo.architecture.Architecture] - com.my.osgi.my-component
2018-07-17T12:03:50,021 | DEBUG | [iPOJO] pool-1-thread-1 | my-component | 38 - com.my.osgi.my-component  - 1.0.3 | ServiceEvent REGISTERED - [com.my.osgi.my-component]                         - com.my.osgi.my-component
2018-07-17T12:03:50,021 | DEBUG | [iPOJO] pool-1-thread-1 | my-component | 38 - com.my.osgi.my-component  - 1.0.3 | ServiceEvent MODIFIED -   [com.my.osgi.my-component]                         - com.my.osgi.my-component
2018-07-17T12:03:50,021 | DEBUG | [iPOJO] pool-1-thread-1 | my-component | 38 - com.my.osgi.my-component  - 1.0.3 | ServiceEvent MODIFIED -   [com.my.osgi.my-component]                         - com.my.osgi.my-component
2018-07-17T12:03:50,021 | DEBUG | [iPOJO] pool-1-thread-1 | my-component | 38 - com.my.osgi.my-component  - 1.0.3 | ServiceEvent MODIFIED -   [com.my.osgi.my-component]                         - com.my.osgi.my-component
2018-07-17T12:03:50,021 | DEBUG | [iPOJO] pool-1-thread-1 | my-component | 38 - com.my.osgi.my-component  - 1.0.3 | ServiceEvent REGISTERED - [org.apache.felix.ipojo.Factory] - com.my.osgi.my-component

但在我的情况下,它只有两行

2018-07-17T11:45:43,624 | DEBUG | [iPOJO] pool-1-thread-1 | my-component  | 11 - com.my.osgi.my-component - 2.0.4.SNAPSHOT | ServiceEvent REGISTERED - [org.apache.felix.ipojo.extender.TypeDeclaration] - com.my.osgi.my-component
2018-07-17T11:45:43,654 | DEBUG | [iPOJO] pool-1-thread-1 | my-component  | 11 - com.my.osgi.my-component - 2.0.4.SNAPSHOT | ServiceEvent REGISTERED - [org.apache.felix.ipojo.Factory] - com.my.osgi.my-component  

那么这个体系结构做了什么,修改了什么?

只需在组件类上添加@Instantiate注释。或者,您可以使用:

  • iPOJO工厂服务(http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/ipojo-factory-service.html)
  • 配置管理员(http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/ipojo-advanced-topics/combining-ipojo-and-configuration-admin.html)
  • 用@Configuration注释的类

相关内容

  • 没有找到相关文章

最新更新