May 27, 2020
Estimated Post Reading Time ~

OSGi R7 annotations Examples in AEM

OSGi component / service Configs
String Config

 @AttributeDefinition(
          name = "String Property",
          description = "String example",
          type = AttributeType.STRING
      )
    String stringExample() default "String value";

String Array Config

@AttributeDefinition(
    name = "String Array Example",
    description = "String Array Example",
    type = AttributeType.STRING
   )
 String[] stringArrayExample() default {"String1", "String2"};

Dropdown Config

 @AttributeDefinition(
         name = "Dropdown example",
         description = "Dropdown example",
         options = {
             @Option(label = "Option1", value = "Option1"),
             @Option(label = "Option2", value = "Option2"),
             @Option(label = "Option3", value = "Option3")
         }
     )
 String dropdownExample() default StringUtils.EMPTY;

Boolean Config
To declare your  OSGi configuration as boolean you must use the attribute type BOOLEAN
@AttributeDefinition(
         name = "Boolean Property",
         description = "Boolean example",
         type = AttributeType.BOOLEAN
 )

Long Config

 @AttributeDefinition(
       name = "Long Property",
       description = "Sample long property",
       type = AttributeType.LONG
 )
  long longExample() default 0L;


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.