Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

How to Register Servlets Dynamically in AEM? | AEM Community Blog Seeding




How to Register Servlets Dynamically in AEM? by Albin Issac


Most of the time while working on the project we will have scenarios to dynamically register the servlets with different resource types, selector and extension, etc — registering the same servlet with different resource types, selector, extensions, etc.

Let's assume we have a servlet that is registered with a specific resource type but later we have a requirement to enable the same servlet for a different resource type, one of the common options is modifying the source code to enable the additional resource types. The code change might not be the optimal solution in most cases.

In this tutorial, let us see the simple approach to register the servlets dynamically with different resource types, selectors, and extensions.

The OSGi Metatype Annotations(OSGi Declarative Services Annotations) can be used to register the dynamic servlets.

ObjectClassDefinition — Generate a Meta Type Resource using the annotated type

AttributeDefinition — AttributeDefinition information for the annotated method.

Designate — Generate a Designate element in the Meta Type Resource for an ObjectClassDefinition using the annotated Declarative Services component.

Read Full Blog

How to Register Servlets Dynamically in AEM?


Please use this thread to ask the related questions.


Topics help categorize Community content and increase your ability to discover relevant content.

5 Replies


Level 5

Hi @kautuk_sahni ,

Is there any specific reason is there that JSON or txt extensions can be accessed only from jcr:content node.


Please provide me some explanation.


In this article for configuration class static is added. Because of that configuration is not registering. After removing static it worked perfectly.

public static @interface Config 








@Sandeep6  This is a Blog post from Albin. I have asked him to assist you.



Community Advisor

Thanks, @Sandeep6 for the feedback, the resource type is tagged to the jcr:content node of the cq:page so the _jcr_content should be included to invoke the servlet. 

Anyhow the HTML extension is invoking the servlet without adding the _jcr_content to the request path. 

Let me know if you need any further information on this. I will review the issue with the static keyword.



Albin I


Community Advisor

One option to add the resource type as cq/Page so the servlet can be accessed directly on page nodes, in this case, the servlet will be invoked for all the pages irrespective of the page resource type specified in jcr:content node.


Albin I