Hi I am trying to create a config factory. Below are the three classes I have created
public interface OSGiConfig {
String getServiceUrl();
}
=====================================
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.osgi.service.metatype.annotations.AttributeType;
@ObjectClassDefinition(name = "My Site - OSGi Factory Configs",
description = "OSGi Factory Config for service url")
public @interface OSGiFectoryConfig {
@AttributeDefinition(name = "Service Url Text",
description = "Enter Service Url ",
type = AttributeType.STRING)
public String serviceUrlStr();
}
=======================================
import org.osgi.service.component.annotations.*;
import org.osgi.service.metatype.annotations.Designate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.mysite.core.configs.OSGiConfig;
import com.mysite.core.configs.OSGiFectoryConfig;
@component(service = OSGiConfig.class, configurationPolicy = ConfigurationPolicy.REQUIRE)
@Designate(ocd = OSGiFectoryConfig.class, factory = true)
public class OSGiFactoryConfigImpl implements OSGiConfig {
private static final Logger LOG = LoggerFactory.getLogger(OSGiFactoryConfigImpl.class);
private String serviceUrlStr;
@activate
@MODIFIED
protected void activate(final OSGiFectoryConfig config){
serviceUrlStr = config.serviceUrlStr();
}
@Override
public String getServiceUrl() {
return serviceUrlStr;
}
}
When I deploy the code, I could not see my factory config in configMgr console. I am using AEM 6.5.5
Solved! Go to Solution.
Views
Replies
Total Likes
Please try with below code.
public interface OSGiConfig {
String getServiceUrl();
}
----------------------------------------
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.AttributeType;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@ObjectClassDefinition(
name = "My Site - OSGi Factory Configs",
description = "OSGi Factory Config for service url")
public OSGiFectoryConfig {
@AttributeDefinition(
name = "Service Url Text",
description = "Enter Service Url ",
type = AttributeType.STRING)
public String serviceUrlStr();
}
-----------------------------------------------
import org.osgi.service.component.annotations.*;
import org.osgi.service.metatype.annotations.Designate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(service = OSGiConfig.class,immediate=true, configurationPolicy = ConfigurationPolicy.REQUIRE)
@Designate(ocd = OSGiFectoryConfig.class, factory = true)
public class OSGIFactoryConfigImpl implements OSGiConfig {
private static final Logger LOG = LoggerFactory.getLogger(OSGIFactoryConfigImpl.class);
private String serviceUrlStr;
protected void activate(final OSGiFectoryConfig config) {
serviceUrlStr = config.serviceUrlStr();
}
public String getServiceUrl() {
return serviceUrlStr;
}
}
I hope it helps!
Please try with below code.
public interface OSGiConfig {
String getServiceUrl();
}
----------------------------------------
import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.AttributeType;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@ObjectClassDefinition(
name = "My Site - OSGi Factory Configs",
description = "OSGi Factory Config for service url")
public OSGiFectoryConfig {
@AttributeDefinition(
name = "Service Url Text",
description = "Enter Service Url ",
type = AttributeType.STRING)
public String serviceUrlStr();
}
-----------------------------------------------
import org.osgi.service.component.annotations.*;
import org.osgi.service.metatype.annotations.Designate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(service = OSGiConfig.class,immediate=true, configurationPolicy = ConfigurationPolicy.REQUIRE)
@Designate(ocd = OSGiFectoryConfig.class, factory = true)
public class OSGIFactoryConfigImpl implements OSGiConfig {
private static final Logger LOG = LoggerFactory.getLogger(OSGIFactoryConfigImpl.class);
private String serviceUrlStr;
protected void activate(final OSGiFectoryConfig config) {
serviceUrlStr = config.serviceUrlStr();
}
public String getServiceUrl() {
return serviceUrlStr;
}
}
I hope it helps!
@Rohit_Utreja I tried but it did not worked, even it was not compiling because of there is class type missing for OSGiFectoryConfig.
Can you please highlight what was wrong in the code I posted. So I will make those changes and try again.
You need to import 'OSGiFectoryConfig' in file OSGIFactoryConfigImpl.
It will resolve the compiling error.
I hope it helps!