Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

@Reference for configuration factory service

Avatar

Level 3

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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

Avatar

Level 3

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