Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

AEM 6.3 | adptTo returning null for sling models

vivekas69392643
Level 1
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
smacdonald2008
Level 10
Level 10

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

GaneshM
Level 3
Level 3

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!

vipins5188
Level 3
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

vivekas69392643
Level 1
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.

smacdonald2008
Level 10
Level 10

Save the configuration seems to be the workaround here.

vipins5188
Level 3
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.