How can I access Adobe Experience Manager (AEM) properties in an OSGi configuration within a WCMUse class in AEM 6.1?

1 Answers
Answered by suresh

To access Adobe Experience Manager (AEM) properties in an OSGi configuration within a WCMUse class in AEM 6.1, you can follow these steps:

1. Define the OSGi configuration:
```xml

johndoe

```

2. Create a Java class to read the OSGi configuration property:
```java
package com.example.core.models;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import com.adobe.cq.sightly.WCMUse;

public class MyWCMUseClass extends WCMUse {
private String myConfigProperty;

@Override
public void activate() throws Exception {
SlingBindings bindings = (SlingBindings) getRequest().getAttribute(SlingBindings.class.getName());
ResourceResolver resolver = bindings.getResourceResolver();

Resource configResource = resolver.getResource("/apps/my-app/config");
ValueMap configProperties = ResourceUtil.getValueMap(configResource);
myConfigProperty = configProperties.get("myConfigProperty", "defaultValue");
}

public String getMyConfigProperty() {
return myConfigProperty;
}
}
```

3. Use the property in your HTL file:
```html

My Config Property: ${myWCMUse.myConfigProperty}

```

By following these steps, you can access Adobe Experience Manager properties in an OSGi configuration within a WCMUse class in AEM 6.1.

Answer for Question: How can I access Adobe Experience Manager (AEM) properties in an OSGi configuration within a WCMUse class in AEM 6.1?