To access the properties from an OSGi configuration in a WCMUse class in AEM 6.1, you can follow these steps:
1. Define the OSGi configuration that contains the properties you want to access. This can be done by creating a configuration interface and annotating it with the @Designate annotation.
Here is an example of an OSGi configuration interface:
```html
<code>package com.example.configuration;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@ObjectClassDefinition(name = "Sample Configuration", description = "This is a sample OSGi configuration")
public @interface SampleConfiguration {
String sampleProperty() default "defaultValue";
}</code>
```
2. Inject the configuration values into the WCMUse class using the @Reference annotation. This annotation allows you to reference OSGi services such as configurations.
Here is an example of how you can inject the OSGi configuration into a WCMUse class:
```html
<code>package com.example.core.models;
import com.example.configuration.SampleConfiguration;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
import javax.inject.Inject;
import org.osgi.service.component.annotations.Reference;
@Model(adaptables = {SlingHttpServletRequest.class, Resource.class})
public class SampleModel {
@Inject
private SampleConfiguration sampleConfiguration;
@ValueMapValue
private String pageTitle;
public String getTitle() {
return pageTitle + " - " + sampleConfiguration.sampleProperty();
}
}</code>
```
By following these steps, you can access properties from an OSGi configuration in a WCMUse class in AEM 6.1.
Please login or Register to submit your answer