I'd like to setup Sling Models in our sling based project (actually it is an AEM project). I followed the instructions at http://sling.apache.org/documentation/bundles/models.html but unfortunately the adapTo method on a resource returns null, so I think I made some mistake in my OSGI configuration setup. Unfortunately I don't get any log file error, so now I need some help :) We work with the maven-bundle-plugin which I configured the following way:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<!-- we have to export for the classes to be visible -->
<Export-Package>
com.company.project.*;version=${project.version}
</Export-Package>
<Import-Package>
org.apache.felix.scr;version="[1.6,2)",
org.apache.sling.api;version="[2.1,3)",
org.apache.sling.api.request;version="[2.1,3)",
org.apache.sling.commons.scheduler;version="[2.1,3)",
*
</Import-Package>
<Private-Package>
org.apache.sling.models.*
</Private-Package>
<Include-Resource>
{maven-resources}
</Include-Resource>
<Sling-Model-Packages>
com.company.project.models.componentgroup
</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>
The Model is implemented as an interface:
package com.company.project.models.componentgroup;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Default;
import org.apache.sling.models.annotations.Model;
import javax.inject.Inject;
@Model(adaptables = Resource.class)
public interface MyModel {
@Inject
@Default(values = "My Property Value")
String getMyProperty();
}
I got a Controller class in which a SlingResource adapts to the Model, but returns null:
MyModel model = resource.adaptTo(MyModel.class);
I'm really thankful for any help.