How to access OSGi configuration properties in AEM 6.1 WCMUse class?

1 Answers
Answered by suresh

To access OSGi configuration properties in AEM 6.1 WCMUse class, you can follow the steps outlined below:

1. In your WCMUse class, inject the SlingHttpServletRequest object using the @SlingObject annotation. This will allow you to access the current request.

```java
@SlingObject
private SlingHttpServletRequest request;
```

2. Use the ResourceResolverFactory to get a ResourceResolver object, which will give you access to the configurations.

```java
ResourceResolver resolver = request.getResourceResolver();
```

3. Get the configuration service (org.apache.sling.commons.osgi.Properties) using the getResource() method of the ResourceResolver.

```java
Resource configResource = resolver.getResource("/apps/myproject/config/configurationName");
ValueMap configProperties = configResource.adaptTo(ValueMap.class);
```

4. Finally, you can access the OSGi configuration properties using the getValue() method of the ValueMap object.

```java
String propertyValue = configProperties.get("propertyName", String.class);
```

By following these steps, you can easily access the OSGi configuration properties in your AEM 6.1 WCMUse class.

Answer for Question: How to access OSGi configuration properties in AEM 6.1 WCMUse class?