Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

multiple servlets with same resource type

Avatar

Level 3

hi all , 

suppose i have two servlets registered with the same ResourceType .so how will Resource type will select which servlet will serve the request . this is my interview question actully. please answer  

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hello @Shivanandh 

 

In Adobe Experience Manager (AEM), when you have multiple servlets registered with the same resource type, the selection of which servlet will serve the request depends on the OSGi service ranking 

OSGi service ranking is a property that can be set when registering a service in AEM. The servlet with the highest service ranking value will be selected to serve the request. 

For example, let's say you have two servlets registered with the same resource type:

Servlet A:
- Resource Type: "myapp/components/mycomponent"
- Service Ranking: 100

 

Servlet B:
- Resource Type: "myapp/components/mycomponent"
- Service Ranking: 200

 

In this case, Servlet B will be selected to serve the request because it has a higher service ranking value. 


Aanchal Sikka

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

Hello @Shivanandh 

 

In Adobe Experience Manager (AEM), when you have multiple servlets registered with the same resource type, the selection of which servlet will serve the request depends on the OSGi service ranking 

OSGi service ranking is a property that can be set when registering a service in AEM. The servlet with the highest service ranking value will be selected to serve the request. 

For example, let's say you have two servlets registered with the same resource type:

Servlet A:
- Resource Type: "myapp/components/mycomponent"
- Service Ranking: 100

 

Servlet B:
- Resource Type: "myapp/components/mycomponent"
- Service Ranking: 200

 

In this case, Servlet B will be selected to serve the request because it has a higher service ranking value. 


Aanchal Sikka

Avatar

Community Advisor

@aanchal-sikka is correct, I am just adding the source in case you want to learn more about it. Here https://sling.apache.org/documentation/the-sling-engine/servlets.html#servlet-resolution-order-1 



Esteban Bustamante