0

I have a Camel application that uses a servlet to expose a REST API. I'm using SpringBoot alongside Camel. After building the WAR, I can run it using java -jar, and it works fine. Now, when I deploy the same WAR into tomcat/webapps I get the following error in the logs:

    java.lang.ClassCastException: class org.apache.camel.component.servlet.CamelHttpTransportServlet cannot be cast to class jakarta.servlet.Servlet (org.apache.camel.component.servlet.CamelHttpTransportServlet is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @4f2613d1; jakarta.servlet.Servlet is in unnamed module of loader java.net.URLClassLoader @520a3426)

This is my web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <servlet>
    <servlet-name>CamelServlet</servlet-name>
    <servlet-class>
        org.apache.camel.component.servlet.CamelHttpTransportServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>SpringApplicationContext</servlet-name>
    <servlet-class>
        org.springframework.web.context.ContextLoaderServlet
    </servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <!-- Camel servlet mapping -->
  <servlet-mapping>
    <servlet-name>CamelServlet</servlet-name>
    <url-pattern>/srv/*</url-pattern>
  </servlet-mapping>
</web-app>

I'm using Tomcat 10.0.10 and Camel 3.8

Any help is appreciated.

El.Psy.Kongroo
  • 117
  • 1
  • 7
  • 2
    Does this answer your question? [jakarta.servlet.ServletException: Class \[com.practice.MyServlet\] is not a Servlet](https://stackoverflow.com/questions/65872072/jakarta-servlet-servletexception-class-com-practice-myservlet-is-not-a-servle) – Piotr P. Karwasz Aug 26 '21 at 19:55
  • 1
    Quick fix (most likely): Use Tomcat 9 and read about the difference and backward incompatibility warning of Tomcat 10 on its website. – Olaf Kock Aug 27 '21 at 06:49
  • Yeah, using Tomcat 9 worked. Thank you both =) – El.Psy.Kongroo Aug 27 '21 at 12:16

1 Answers1

0

Using Tomcat 9 solved the issue

El.Psy.Kongroo
  • 117
  • 1
  • 7