felix scr 注释中元类型属性的用例 [英] usecase of metatype attribute in felix scr annotations

查看:23
本文介绍了felix scr 注释中元类型属性的用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用了 scr 注释.有人可以解释@Component注解中元类型属性的用例吗?

I am using scr annotations in my project. Can anybody explain the usecase of metatype attribute in @Component annotation?

import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.felix.scr.annotations.Service;
    @Component (name = "SampleComponent", label = "TestLabel", description = "This is a test application", ds = true, immediate = false, metatype = true, factory = "com.java.test.sampleComponent")
    @Service

推荐答案

documentation for Felix SCR Annotations: "如果此参数设置为 true,则在该组件的 metatype.xml 文件中生成元类型服务数据.否则没有元类型服务数据是为此组件生成的."

As stated in the documentation for Felix SCR Annotations: "If this parameter is set to true Metatype Service data is generated in the metatype.xml file for this component. Otherwise no Metatype Service data is generated for this component."

元类型数据可由管理系统或 GUI 使用,例如 Felix Web Console 提供了一种更有用的方式来配置您的组件.

Metatype data can be used by administrative systems or GUIs such as Felix Web Console to present a much more helpful way to configure your component.

我认为您应该始终打开此标志,因为它将来可能会很有用,并且即使您从不使用它也基本上为零成本.

I think you should always turn this flag on, since it may be useful in the future, and has basically zero cost even if you never use it.

顺便说一句,您可能应该停止使用 Felix SCR 注释,因为它们正在被 OSGi 中的标准 DS 注释所淘汰.有关详细信息,请参阅 OSGi Compendium 规范(第 5 版或更高版本)的第 112.8 节.

By the way you should probably stop using the Felix SCR annotations since they are being phased out in favour of the standard DS annotations from OSGi. See section 112.8 of the OSGi Compendium specification (release 5 or later) for details.

这篇关于felix scr 注释中元类型属性的用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆