@Reference for configuration factory service

Avatar

Avatar

ajinkayk6258253

Avatar

ajinkayk6258253

ajinkayk6258253

04-07-2019

Hi All,

i created a configuration factory service to bind multiple config for different type mail accounts ? im using @Reference(target ="service.label="") but it's not working as reference is shown as unsatisfied.. im using ds annotations.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883
Arun_Patidar
MVP

05-07-2019

I created a sample service with factory config, please check for reference

aem63app-repo/java/r6/factory at master · arunpatidar02/aem63app-repo · GitHub

Answers (2)

Answers (2)

Avatar

Avatar

Aryan12345

Avatar

Aryan12345

Aryan12345

09-12-2019

Did not work for me.

I did the following

Service code (in the first bundle)

public interface GodaDataServiceFactory {

    List<GodaDataBean> getData();

}

Service Impl Code (Another bundle - Second bundle, Note its a factory)

@Component(

        service = GodaDataServiceFactory.class,

        factory = "GodaDataServiceFactory",

        configurationPolicy = ConfigurationPolicy.REQUIRE

)

@Designate(ocd = GodaDataServiceFactoryConfig.class, factory = true)

public class GodaDataServiceFactoryJcrImpl implements GodaDataServiceFactory {

    private static final Logger LOGGER = LoggerFactory.getLogger(GodaDataServiceFactoryJcrImpl.class);

    @Override

    public List<GodaDataBean> getData() {

        return null;

    }

}

Snaps of the configs

Reference

Option 1 (Direct reference):

@Reference(target = "(sample=test)")

private GodaDataServiceFactory godaDataServiceFactory;

Option 2 (Indirect using bind and unbind)

@Reference(

name = "godaDataServiceFactory",

cardinality = ReferenceCardinality.MULTIPLE,

policy = ReferencePolicy.DYNAMIC,

bind = "bindGodaDataServiceFactory",

unbind = "unbindGodaDataServiceFactory")

List<GodaDataServiceFactory> godaDataServiceFactoryList = new ArrayList<>();

protected synchronized void bindGodaDataServiceFactory(final GodaDataServiceFactory config) {

LOGGER.info("Goda config factory: {}", config);

godaDataServiceFactoryList.add(config);

}

protected synchronized void unbindGodaDataServiceFactory(final GodaDataServiceFactory config) {

godaDataServiceFactoryList.remove(config);

}

None of this seems to work. In the first case godaDataServiceFactory, it is null. The second case, the list is always empty. Note that the consumer is a servlet.

My GitHub Repos

Consumer -> https://github.com/GodaProjects/aem646

API -> https://github.com/GodaProjects/api

API IMPL -> https://github.com/GodaProjects/apiImplJcr

Update 1:

For option 1, The servlet remains unsatisfied.

Reference godaDataServiceFactory

Unsatisfied
Service Name: com.goda.core.services.GodaDataServiceFactory
Target Filter: (sample=test)
Cardinality: 1..1
Policy: static
Policy Option: reluctant
No Services bound

For the second option,the list remains empty

Update 2

Consumer project is created using Archetype 13 (has the servlet which consumes the factory service) -> https://github.com/GodaProjects/aem646

API project is created using Archetype 18 (has the API interface for the factory) -> https://github.com/GodaProjects/api

API IMPL project is created using Archetype 18 (has the implementation for the API which is in the API project) -> https://github.com/GodaProjects/apiImplJcr