OSGi DS Annotations - showing multiple configurations in Felix Console | Community
Skip to main content
prohira
Level 3
November 1, 2017
Solved

OSGi DS Annotations - showing multiple configurations in Felix Console

  • November 1, 2017
  • 1 reply
  • 2708 views

While migrating the code to 6.3, we are moving to OSGi DS Annotations. I created two files:

1. Interface (where I am keeping all the properties) - com.abc.web.config.TestConfiguration.java

2. Component/Service which will be actually used in other components in order to pull the properties configured. - com.abc.web.config.ConfigurationService.java

3. we have config.xml (sling:osgiConfig) files for this configurations because each environment needs to pull different values. - /apps/project/configuration/config/com.abc.web.config.TestConfiguration.xml

Interface:

@ObjectClassDefinition(name = "Test Config Name",

  description = "Config Description")

public @interface TestConfiguration {

   @AttributeDefinition(name = "Attribute One", description = "Attribute 1")

  String attributeOne() default StringUtils.EMPTY;

   @AttributeDefinition(name = "Attribute Two", description = "Attribute 2")

  String attributeTwo() default StringUtils.EMPTY;

}

Component/Service:

@Component(immediate = true, service = ConfigurationService.class)

@Designate(ocd = TestConfiguration.class)

....... and so on.

config file:

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
   jcr:primaryType="sling:OsgiConfig"
   attributeOne="Value 1"
   attributeTwo="Value 2"/>

The problem I am having is: it shows two configuration in Felix Console:

1. com.abc.web.config.TestConfiguration -- this shows all the values from config file: Value 1 and Value2

2. Test Config Name - this just shows two blank text fields: Attribute One and Attribute Two

The Configuration Binding field in Felix Console Configurations shows no binding information. It says "Unbound or no configuration". I tried clicking on "Save" to bind it but it didn't do anything. I have tried re-deploying the code, deleting the bundle etc.

Am I missing anything or doing anything wrong?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by manoj_devapath

Can you try adding AttributeType to @AttributeDefinition

sudo code :

@AttributeDefinition(

        name = "String Property",

        description = "Sample String property",

        type = AttributeType.STRING

    )

    String servicename_propertyname_string() default "foo";

import org.osgi.service.metatype.annotations.AttributeDefinition;

ref: Official OSGi Declarative Services Annotations in AEM - Adobe Experience Manager | AEM/CQ | Apache Sling

1 reply

manoj_devapath
manoj_devapathAccepted solution
Level 5
November 1, 2017

Can you try adding AttributeType to @AttributeDefinition

sudo code :

@AttributeDefinition(

        name = "String Property",

        description = "Sample String property",

        type = AttributeType.STRING

    )

    String servicename_propertyname_string() default "foo";

import org.osgi.service.metatype.annotations.AttributeDefinition;

ref: Official OSGi Declarative Services Annotations in AEM - Adobe Experience Manager | AEM/CQ | Apache Sling