I have a very basic Spring MVC REST application which when deployed on Tomcat and called in browser or Postman with http://localhost:8080
, should display hello but instead it shows Tomcat Welcome page. Anyone is able to tell me what did I miss or whether there is someting wrong with deployment (I have done this through InteliJ as well as by dropping war into tomcat directly)? I have tried making multiple changes but none seems to work so any tip would be helpful.
NOTE: My sample app is very similar to this one
Result:
EDIT:
I have checked it in the manager on different Tomcat and the application is there but still it doesn't work whether I call it http://localhost:8080/electronic-apps/
or http://localhost:8080/
CodePudding user response:
You must include the context path in the URL when you call it.
In your case it would be:
http://localhost:8125/electronic-apps/
When you do this, you will see Hello
in the browser, assuming the .war
file was deployed correctly.
BTW: You can check the deployment in Tomcat. Prerequisite is that in the file tomcat-users.xml
the admin user is configured/uncommented.
Just call:
http://localhost:8125/manager/html
A list of configured applications appears. It should also include /electronic-apps
. The UI also offers a possibility to deploy a WAR file if you scroll down. However, it would also work if you simply copy the electronic-apps.war
file into Tomcat's webapps
folder.
Problem 2
The second problem of the updated question has a different cause. Here the OP uses a Tomcat 10 instance (as you can see in the screenshot).
Applications that run on Tomcat 9 and earlier will not run on Tomcat 10 without changes. Java EE based applications designed for Tomcat 9 and earlier may be placed in the $CATALINA_BASE/webapps-javaee directory and Tomcat will automatically convert them to Jakarta EE and copy them to the webapps directory. This conversion is performed using the Apache Tomcat migration tool for Jakarta EE tool which is also available as a separate download for off-line use.
The mentioned migration tool can be downloaded from here: https://tomcat.apache.org/download-migration.cgi
And indeed, a quick test shows that applying this tool works as expected. Without applying this tool, the error appears as shown in your Tomcat 10 screenshot.
So in your case:
- create the
electronic-apps.war
- use this in your Tomcat 9 installation
- apply the migration tool and create a new
electronic-apps.war
- this migrated .war file can then be used with your Tomcat 10 installation
For Tomcat 10, you also need to add the context path to the URL (i.e. http://localhost:8080/electronic-apps/) for the app to run.