Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployment as war to tomcat 10 does not work #276

Closed
miq opened this issue Feb 4, 2022 · 5 comments · Fixed by #541
Closed

Deployment as war to tomcat 10 does not work #276

miq opened this issue Feb 4, 2022 · 5 comments · Fixed by #541
Assignees

Comments

@miq
Copy link

miq commented Feb 4, 2022

Expected Behavior

A war archive created as per documentation and deployed to a tomcat servlet container should run and react like the standalone app or when deploying to tomcat 9.

Actual Behaviour

The war gets deployed but the app seems to never be called. All requests result in a 404 error.

Steps To Reproduce

  1. Create a fresh micronaut app, implement a controller and add micronaut-servlet to build a war file.
  2. Deploy the war file to a servlet container like Tomcat.
  3. Call the defined endpoint, e.g. http://localhost:8080/demo-tomcat-0.1/hello/
  4. Instead of the result string you get a 404

Environment Information

  • Windows 10
  • OpenJDK 17
  • Tomcat 10.0.16

Example Application

https://github.com/miq/micronaut-servlet-demo

Version

3.3.0

@miq miq changed the title Deployment as war does not work Deployment as war to tomcat 10 does not work Feb 11, 2022
@timyates
Copy link
Contributor

For Micronaut 3.x.x this is expected as Tomcat 10 moved to jakarta.servlet (in place of javax.servlet)

It is possible to convert javax.servlet applications "on the flyby deploying the WAR to/usr/local/tomcat/webapps-javaeeinstead of/usr/local/tomcat/webapps`

For Micronaut 4.x.x this should just work, however there's a bug which prevents it doing so

#541

This PR will fix that.

@timyates timyates linked a pull request Aug 15, 2023 that will close this issue
@timyates timyates moved this to Ready for Review in 4.0.4 Release Aug 15, 2023
@timyates timyates removed this from 4.1.0 Release Aug 15, 2023
@github-project-automation github-project-automation bot moved this from Ready for Review to Done in 4.0.4 Release Aug 15, 2023
@chrisbitmead
Copy link

@timyates Errm... need a lot more information on this.. are you saying that Micronaut 3 and 4 don't work on Tomcat 9? Or are you saying saying we should use the webapps-javaee on tomcat 9 (or 10?)? We need a compatibility matrix and instructions for each combination, whether possible, impossible, needs this hack.. etc.

@sdelamo
Copy link
Contributor

sdelamo commented Sep 20, 2023

A Micronaut Framework 4.1.1 using Micronaut Servlet should work. does not work for you @chrisbitmead ?

@chrisbitmead
Copy link

@sdelamo It doesn't seem to work for me. A micronaut 4.1.1 app that works as a standalone application, when deployed to tomcat 9, just does nothing. It deploys successfully but has no functionality at all.

I do have this if it matters:

    developmentOnly("io.micronaut.servlet:micronaut-http-server-tomcat")

@timyates
Copy link
Contributor

So with Tomcat 10, they migrated from the javax.servlet package namespace to the jakarta.servlet package namespace.

This means that our jakarta.servlet.ServletContainerInitializer Java Service (SPI) definition will not be seen by Tomcat 9 as it's expecting javax.servlet.ServletContainerInitializer, and if we create a javax definition, it won't work as the MicronautServletInitializer is based on jakarta classes so results in

 Caused by: java.lang.ClassCastException: Cannot cast io.micronaut.servlet.engine.initializer.MicronautServletInitializer to javax.servlet.ServletContainerInitializer
                at java.base/java.lang.Class.cast(Class.java:3889)
                at org.apache.catalina.startup.WebappServiceLoader.loadServices(WebappServiceLoader.java:236)

@chrisbitmead I will add something to the docs to show that for Micronaut 4, you need to use Tomcat 10 as a minimum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants