I am declaring a sling servlet like so
@Component(metatype = false)
@Service(Servlet.class)
@Properties({
@Property(name = "sling.servlet.paths", value = "/bin/foo/bar"),
@Property(name = "sling.servlet.methods", value = "POST") })
public class FooBarServlet extends SlingAllMethodsServlet {
...
}
I override doPost like so
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
...
}
And I am able to post from a client. Great!
I throw in the following
@Reference
private QueryBuilder queryBuilder;
as per the documentation, a reference to query builder should be injected. But it does not seem to. In the log I see this error
bindQueryBuilder cannot be found (java.lang.VerifyError: ...
And when I try to post to the servlet I get this
javax.jcr.RepositoryException: org.apache.sling.api.resource.PersistenceException: Resource at '/bin/foo/bar' is not modifiable.
And in the OSGi console I see my bundle is installed, and this is what it has to say about my servlet
Service ID 3075 Types: javax.servlet.Servlet
Service PID: com.myproject.FooBarServlet
Component Name: com.myproject.FooBarServlet
Component ID: 5526
Vendor: Adobe
Any suggestions as to what I am doing wrong?
For the dependency injection to work, you should declare the member variable as public.
Try changing it to
I had been using this tutorial as a reference. I came across this about the Felix Service Component Runtime (SCR)
and so I implemented the following
and it worked! So upon closer investigation I learned that these bind/unbind methods are actually supposed to be generated by the maven-scr-plugin, of which I have version 1.6.0
and for the annotations I have 1.4.0
so although I am not sure why the bind/unbind methods are not getting generated, I know that they should be, so I generate them manually.
Update I tried to update the maven-scr-plugin to version 1.20.0, which yielded the following error during mvn build
so... I updated the org.apache.felix.scr.annotations to 1.9.0. And it works! My bind/unbind accessors are generated and all is great. However, I am concerned and do not know if I should use version 1.9.0 of org.apache.felix.scr.annotations because I am marking it as
provided
in the maven dependency and when I look at the OSGi bundles installed on the cq instance I see the following