Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

This conversation has been locked due to inactivity. Please create a new post.

SOLVED

A question about Sling servlets and resource types

Avatar

Level 7

Hi,

When a Sling servlet is defined using paths, similar to:

@SlingServlet(paths = "/bin/example", ...)

It is accessible via localhost:4502/bin/example.

When it is defined using resourceTypes, similar to:  

@SlingServlet(resourceTypes = "foo:example", ...)

Under what URL(s) will be accessible?

Also when does it make sense to define a servlet using resourceTypes rather than paths?

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 8

When a servlet is registered to a resourceType then the servlet is available at any URL matching the resource type. So for example if the node /content/foo/bar has a sling resource type of foo.example then the servlet would render for any request to that node in theory. Normally the resourceTypes property is combined with other restrictions - extension or selector or request method to narrow the scope of the servlet.

Normally you use the resourceTypes property when you are creating a servlet that renders content stored on a node, as opposed to servlets that are more service oriented which is what you normally see in the /bin areal.  

View solution in original post

1 Reply

Avatar

Correct answer by
Level 8

When a servlet is registered to a resourceType then the servlet is available at any URL matching the resource type. So for example if the node /content/foo/bar has a sling resource type of foo.example then the servlet would render for any request to that node in theory. Normally the resourceTypes property is combined with other restrictions - extension or selector or request method to narrow the scope of the servlet.

Normally you use the resourceTypes property when you are creating a servlet that renders content stored on a node, as opposed to servlets that are more service oriented which is what you normally see in the /bin areal.