Expand my Community achievements bar.

SOLVED

Config factory not visible on configMgr console

Avatar

Level 2

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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!

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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!

Avatar

Level 2

@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.

Avatar

Community Advisor

You need to import 'OSGiFectoryConfig' in file OSGIFactoryConfigImpl.
It will resolve the compiling error.

I hope it helps!