title: Ways of registering a Sling Servlet - Adobe AEM/CQ
body: <p>There are two ways of registering Sling Servlet as per the <a href="https://sling.apache.org/documentation/the-sling-engine/servlets.html" rel="nofollow">documentation</a></p>
  
  <p>First is <code>@SlingServlet</code></p>
  
  <pre><code>@SlingServlet(
      resourceTypes = "sling/servlet/default",
      selectors = "hello",
      extensions = "html",
      methods = "GET")
      public class MyServlet extends SlingSafeMethodsServlet {
  
      @Override
      protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
          ...
      }
  }
  </code></pre>
  
  <p>Second using <code>@Properties</code></p>
  
  <pre><code>@Component(metatype = true)
  @Service(Servlet.class)
  @Properties({
      @Property(name = "sling.servlet.resourceTypes", value = "sling/servlet/default"),
      @Property(name = "sling.servlet.selectors", value = "hello"),
      @Property(name = "sling.servlet.extensions", value = "html"),
      @Property(name = "sling.servlet.methods", value = "GET")
  })
  public class MyServlet extends SlingSafeMethodsServlet {
  
      @Override
      protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
          ...
      }
  }
  </code></pre>
  
  <p>Documentation doesn't lists any advantages of specific approach over other. One of my team member asked about this. One thing I could think of is <code>@Properties</code> allow us to give configurable properties, which can be changed from OSGi console (<a href="http://localhost:4502/system/console/components" rel="nofollow">http://localhost:4502/system/console/components</a>, assuming CQ is running locally on port 4502). Is there a difference or advantage of using specific approach?</p>