Please check the imports for the new class which you created. I was
getting the same error when I was creating a sling model
(@Model(adaptables =Resource.class))and after analysing the code I found
that there was an import import javax.annotation.Resource which was not
correct. I replaced it with the correct one import
org.apache.sling.api.resource.Resource and the issue got fixed.