Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Sling Modles - Specifying an Alternate Adapter Class

Avatar

Level 7

Hi Team,

I tried the below code in sling models but I got error for declaring adapters -

@Model(adaptables = Resource.class, adapters = MyModel.class)
public class MySlingModel {
}

I'm using the below dependencies -

    <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.models.api</artifactId>
            <version>1.1.0</version>
            <scope>provided</scope>
        </dependency>

Earlier I used for the version 1.0.0. But it is not working. I'm unable to use adapters.

Can you pls help me in this?

Thanks,

AryA.

1 Accepted Solution

Avatar

Correct answer by
Level 7

You have used @Model incorrectly.

There is no way to create a Sling Model from more than one adaptable, Your class can adapt to multiple means it can adapt to different classes but at one point of time only one.

Read more about How to use Sling Model with Sightly in AEM

regards,

Ankur Ahlawat

AEM CQ5 Tutorials

View solution in original post

5 Replies

Avatar

Level 10

What version of AEM are you using? 

Avatar

Level 10

We are going to release a new AEM 6.2 SLing Model Article. I will post soon. 

Avatar

Administrator

Hi 

Please refer to :- https://helpx.adobe.com/experience-manager/using/sling_models.html

//

Adding following dependency to the pom.xml help overcoming this problem:

<dependency>

    <groupId>org.apache.geronimo.specs</groupId>

    <artifactId>geronimo-atinject_1.0_spec</artifactId>

    <version>1.0</version> <scope>provided</scope>

</dependency>

Reference :- Go to depfinder:- http://localhost:4502/system/console/depfinder  [to find out dependency]

Please let me know, what exactly is the error coming?

PS:- Please add the dependency mentioned. Even the article Link mentioned by me is missing with this dependency, so add it and run it.

Thanks and Regards

Kautuk Sahni 



Kautuk Sahni

Avatar

Administrator

smacdonald2008 wrote...

We are going to release a new AEM 6.2 SLing Model Article. I will post soon. 

 

Article Released:- https://helpx.adobe.com/experience-manager/using/slingmodel_62.html

~kautuk



Kautuk Sahni

Avatar

Correct answer by
Level 7

You have used @Model incorrectly.

There is no way to create a Sling Model from more than one adaptable, Your class can adapt to multiple means it can adapt to different classes but at one point of time only one.

Read more about How to use Sling Model with Sightly in AEM

regards,

Ankur Ahlawat

AEM CQ5 Tutorials