Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

AEM 6.3 | adptTo returning null for sling models

Avatar

Level 1

Hi Team,

I am reading the resource path from the OSGI configuration and then adapting the resource to a sling model, it's returning null.

It's working fine when we explicitly save the configuration. But returning null after every build until unless the configuration is been saved.

Regards,

Viveka

6 Replies

Avatar

Level 10

Are you talking about OSGi configurations that are read in an AEM Service?

Avatar

Level 4

Hi Viveka,

Please create the OSGI configuration in code and place to desired run modes. So it will not get vanished after every build.

Some thing like /apps/project/config.dev/com.day.cq.commons.impl.ExternalizerImpl.xml

FYI, http://aempodcast.com/2016/infrastucture/best-practice-treat-osgi-configurations-code

Thanks!

Avatar

Level 3

Hi Viveka,

If you are not maintaining OSGI configuration xml files explicitly, i would recommend you to have default value in OSGI service itself like as below.

@Properties({ @Property(name = "resource.path", value = "/content/we-retails")})

Note: Providing default values like this will resolve your issue where after every build your configuration is lost.

Or else you can created xml config files and have your configuration value added there.

Hope this helps

Avatar

Level 1

I have already created xml configuration with default Value and we can able to read the configuration value from the Service class, But the issue is coming only on adapting the resource to a sling model (with out saving the configuration). It works perfectly fine once I save the OSGI configuration in web console.

Avatar

Level 10

Save the configuration seems to be the workaround here.

Avatar

Level 3

Hi Viveka,

Could you please post snippet of your sling model here.

Make sure you are injecting service to sling model in proper way.