1

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
Shriram
  • 4,343
  • 8
  • 37
  • 64
  • There are several packages providing an `@Component` annotation. Could you please specify which you are using? Including the Java `import` statement would help. – Neil Bartlett Jan 19 '16 at 14:30
  • The @Service makes it look like the Felix SCR annotations are being used. – BJ Hargrave Jan 19 '16 at 15:20

1 Answers1

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.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • Thanks for the explanation. Still we are in karaf 2.3.10 which uses OSGi rev 4.2. Since you are strongly recommending to not to use SCR is there any limitations? – Shriram Jan 20 '16 at 15:12
  • Ah well if you're using a 7-year-old release of OSGi then the limitations of the SCR annotations are the least of your worries. – Neil Bartlett Jan 20 '16 at 22:48