我在我的项目中使用了scr注释。有人能解释一下@Component注解中metatype属性的用法吗?
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发布于 2016-01-20 21:45:23
正如Felix SCR注解的documentation中所述:“如果此参数设置为true,将在metatype.xml文件中为此组件生成元类型服务数据。否则,不会为此组件生成元类型服务数据。”
管理系统或Felix Web Console等GUI可以使用元类型数据来提供一种更有用的方法来配置组件。
我认为你应该始终打开这个标志,因为它在未来可能会有用,即使你从来不使用它,它也基本上是零成本的。
顺便说一下,您可能应该停止使用Felix SCR批注,因为它们正在逐步淘汰,取而代之的是OSGi中的标准DS批注。有关详细信息,请参阅OSGi概要规范(版本5或更高版本)的112.8节。
https://stackoverflow.com/questions/34874370
复制相似问题