April 27, 2020
Estimated Post Reading Time ~

org.osgi.framework.ServiceException: Service cannot be cast: javax.servlet.Servlet

I was getting the below exception while invoking the servlet from Adobe Experience Manager(AEM) bundle.

15.02.2015 20:58:11.615 *ERROR* [FelixDispatchQueue] FrameworkEvent ERROR (org.osgi.framework.ServiceException: Service cannot be cast: javax.servlet.Servlet) org.osgi.framework.ServiceException: Service cannot be cast: javax.servlet.Servlet
at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:332)
at org.apache.felix.framework.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:219)
at org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:320)
at org.apache.felix.framework.Felix.getService(Felix.java:3556)
at org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:468)

The root cause of the problem is different versions of servlet API classes are loaded by two different class-loaders.

To fix the issue make sure <scope>provided</scope> is added for the Servlet API dependency in POM.xml

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.