Unable to access the value from OSGI configuration
Hi, I wanted to have an OSGi configuration with one field (type=String) to provide the folder path. So, I have written 2 classes for that - Interface and Implementation class file. Below is the code for your references.
Interface file:-
package devry.edu.core.services;
public interface OSGIConfigMisspelling {
public String getFolderPath();
}
Implementation file:-
package devry.edu.core.services.impl;
import devry.edu.core.services.OSGIConfigMisspelling;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.metatype.annotations.*;
@Component(service = OSGIConfigMisspellingImpl.class,immediate = true)
@Designate(ocd = OSGIConfigMisspellingImpl.ServiceConfig.class )
public class OSGIConfigMisspellingImpl implements OSGIConfigMisspelling {
@ObjectClassDefinition(name="DidYouMean Servlet Content Fragment Folder - OSGi Configuration",
description = "OSGi Configuration for CF Folder")
public @interface ServiceConfig {
@AttributeDefinition(
name = "Folder Path",
description = "Enter folder path",
type = AttributeType.STRING)
public String folderPath() default "/content/dam/devry/misspelled-words";
}
private String folderPath;
@Activate
protected void activate(ServiceConfig serviceConfig){
folderPath=serviceConfig.folderPath();
}
@Override
public String getFolderPath() {
return folderPath;
}
}
I am getting this configurations tab in the Felix console with the provided name after building the project. But, from here on - "I want to use this attribute value coming from the config field in a path based servlet so how can I use that", can anyone please help?