felix scr批注中的元类型属性的用例 [英] usecase of metatype attribute in felix scr annotations
问题描述
我在项目中使用了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
推荐答案
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控制台提供了一种更有用的配置组件的方法.
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汇编规范(版本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屋!