usecase of metatype attribute in felix scr annotations

点点圈 提交于 2019-12-11 10:08:23

问题


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

回答1:


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."

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.

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.



来源:https://stackoverflow.com/questions/34874370/usecase-of-metatype-attribute-in-felix-scr-annotations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!