I have a couple of Sling servlets in a project (implementing SlingAllMethodsServlet or SlingSafeMethodsServlet), and some of them reference Sling services:
public class MyServlet extends SlingAllMethodsServlet{
@Reference
private SlingSettingsService slingSettingsService;
}
Now, static code analyzers like Sonar tell me to make the variable "slingSettingsService" transient or Serializable, because a Sling Servlet implements Serializable:
public class MyServlet extends SlingAllMethodsServlet{
@Reference
private transient SlingSettingsService slingSettingsService;
}
As an alternative, they tell me to make the referenced service implement Serializable, but that seems to be impossible to me. Is that a good idea to make the reference transient? In which case will a Sling servlet ever be serialized and deserialized, and will the trasient referenced be recovered then?