Expand my Community achievements bar.

SOLVED

private org.apache.sling.api.resource.Resource were not able to be injected

Avatar

Level 2

Hi Team

        I am using sling models with sightly. I am trying to inject resource to my model as below. All the models are throwing same error saying Resource was not able to be injected. This was working sometimes before. Now for some reason I am getting this error. Could you please help

 

@Model(adaptables = Resource.class)
public class PdfDownloadModel {
    private final Logger LOG = LoggerFactory.getLogger(getClass());

    @Inject
    private Resource resource;

 

 

ERROR

org.apache.sling.models.impl.ModelAdapterFactory Required properties [private org.apache.sling.api.resource.Resource com.core.pdfdownload.models.PdfDownloadModel.resource] on model class class com.core.pdfdownload.models.PdfDownloadModel were not able to be injected.

Thanks in Advance

Veena

1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi All

    It seems like my AEM instance got corrupted due to some compaction I have done. I have got a new Jar and setup the code and its working perfectly fine with my existing code base. 

    Thanks for all your help and time 

 

Thanks

Veena

View solution in original post

4 Replies

Avatar

Employee

You can better use @self to point to the resource

Avatar

Correct answer by
Level 2

Hi All

    It seems like my AEM instance got corrupted due to some compaction I have done. I have got a new Jar and setup the code and its working perfectly fine with my existing code base. 

    Thanks for all your help and time 

 

Thanks

Veena

Avatar

Employee

Still I would use @Self in your case

Avatar

Level 2

Sure Feike. I will refactor the code to use @self :) Thanks for pointing out to me :)

 

Thanks

Veena