Exam AD0-E103 All QuestionsBrowse all questions from this exam
Question 12

A developer needs to implement a service component that should be manually configured by operations to react on operational circumstances. The service component should NOT be active by default. The service has the properties myservice.name (one string value) and myservice.stringValues (a list of the string values) to be configured.

The developer needs to use OSGi Metatype annotations to make those properties configurable in the Apache Felix Web Console.

Which set of steps should the developer take to meet these requirements?

    Correct Answer: B

    To meet the requirements, the developer should take the following steps: 1. Create an annotation interface as an inner class of the service component and annotate it with @ObjectClassDefinition to define the configuration parameters. 2. Use @AttributeDefinition for the methods myservice.name and myservice.stringValues to specify the configurable properties. 3. Annotate the service component with @Component and set configurationPolicy = ConfigurationPolicy.REQUIRE to ensure it is configured before becoming active. 4. Use the @Designate annotation to link the service component to the created configuration annotation interface to provide the necessary configuration metadata. 5. Implement the activate method of the service component class to get the configuration annotation interface class injected, enabling the service to use the configured values. These steps ensure the service component is not active by default and can be manually configured by operations.

Discussion
chunpinOption: C

Answer: C http://www.nateyolles.com/blog/2017/05/osgi-declarative-services-annotations-in-aem