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;
Thanks for the great annotation examples.
ReplyDeleteDo you mind asking whether there exists a possibility to have a persisted default value such that you have, after deletion of a custom value, the default value as a fallback.
Thanks in advance for any help or hint.
Yes, You can configure via OSGI config nodes
ReplyDelete