@Reference for configuration factory service | Community
Skip to main content
ajinkayk6258253
Level 3
July 4, 2019
Solved

@Reference for configuration factory service

  • July 4, 2019
  • 3 replies
  • 4811 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

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

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

3 replies

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
July 5, 2019

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

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

Arun Patidar
Level 3
December 9, 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

Source image file 18601 not available

Source image file 18602 not available

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