0

I have an issue with my tomcat web application.

I made a build of frontend at first, then I moved all built files to webApp folder of maven spring boot project and then made a build with mvn clean package.

Then I deployed that war with name ROOT.war on the tomcat. When I try to connect with localhost:8080 it returns 404, but when I tried it with localhost:8080/index.html my webApp works.

I have this in my tomcat web.xml file but it didn't help me with my problem.

    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

https://pastebin.com/zhVX2AvW

Here on this link is my whole web.xml ..

Thanks for all your answers .

  • Is there a reason for deploying your Spring Boot app into Tomcat instead of using an embedded Tomcat? – Thomas May 31 '21 at 11:30
  • It is not for my local testing, but I need to deploy it for customer on his own server. – TatkoSmollko May 31 '21 at 11:42
  • Well, the customer probably won't want to use `ROOT.war` as the name then if they are deploying multiple applications to the same Tomcat. If they aren't even they could deploy your application as a single jar, which would make handling easier, e.g. no need to handle library conflicts ("jar hell"), potential downtimes when a single application needs to be taken down or crashes, etc. – Thomas May 31 '21 at 11:54
  • It is not problem, because I can to rename that war. But it still doesn't help me with my problem. I need to resolve why tomcat doesn't know that, it have to open index.html automatically. – TatkoSmollko May 31 '21 at 12:14
  • Well, I didn't use Tomcat directly in a while but there might be some special rules applying to deployments without a context. Does it work when the application is deployed with a proper name? – Thomas May 31 '21 at 12:25
  • 1
    Please, can you include your whole `web.xml` file in the question? Maybe you are mapping your Spring Servlet to serve all the requests in your application, including those related to static assets, and you are not providing a request mapping for your `/` context - which should redirect to your actual `index.html`. – jccampanero May 31 '21 at 12:42
  • @jccampanero I have updated my web.xml on pastebin .. If you want you can check it on this link .. thank you very much with all your help! https://pastebin.com/zhVX2AvW – TatkoSmollko May 31 '21 at 17:34
  • Hi @TatkoSmollko. Thank you very much for sharing your `web.xml` file. It seems you are trying to provide configuration based solely on tomcat resources, you do not provide any Spring related information. Probably that will be the problem. Please, can you see [this SO question and related answer](https://stackoverflow.com/questions/65479023/change-codestar-spring-mvc-project-to-spring-boot/65952131#65952131)? it is related to AWS CodeStar but at the end it has to do on how to run a Spring Boot application in Tomcat. Please, can you try the suggested approach? – jccampanero May 31 '21 at 17:48
  • I have small update. When I made a build with mvn clean package, maven generated the war file ... there are the all libraries in the war file in directory WEB-INF/lib .. When I replaced all these libraries from my another project into this folder, It works... Do you know which library is responsible for this redicert ? Maybe only think thatI need is adding of dependency. @jccampanero – TatkoSmollko May 31 '21 at 18:14
  • Sorry @TatkoSmollko, but I do not understand what you mean. Unless configured to not to, Maven should generate a war with the same dependencies as in the case of the standalone Spring Boot application. Please, can you shed any light on the problem? – jccampanero May 31 '21 at 21:20
  • @TatkoSmollko: since you published the global `web.xml`, my guess is that your application does **not** have a `web.xml` descriptor and that your main servlet has a `/*` mapping, hence disabling the welcome files mechanism. Can you add your main servlet or are you using Spring Boot? – Piotr P. Karwasz Jun 01 '21 at 05:33
  • @PiotrP.Karwasz yes it is a spring boot application. – TatkoSmollko Jun 01 '21 at 09:58
  • Does this answer your question? [how to specify welcome-file-list in WebApplicationInitializer.onStartup()](https://stackoverflow.com/questions/30972676/how-to-specify-welcome-file-list-in-webapplicationinitializer-onstartup) – Piotr P. Karwasz Jun 01 '21 at 13:01
  • Sorry I was on my work holydays ... Thanks, that link resolved my problem. – TatkoSmollko Jun 08 '21 at 08:49

1 Answers1

0

Read the first paragraph under ====Introduction==== in the so called web.xml , it is the "tomcat manager" application configuration web xml you are using and edited of i presume you were trying to convert it for your own use under "" context otherwise known as the / root host domain site. The web.xml of ROOT.war is what should be carrying both the context.xml for the site and its' own web.xml to place the welcome and default file list.

Samuel Marchant
  • 331
  • 2
  • 6
  • What the OP published is the [conf/web.xml](https://github.com/apache/tomcat/blob/main/conf/web.xml) file (i.e. the snippet that is added to all `web.xml` files). – Piotr P. Karwasz Jun 01 '21 at 05:02
  • What is really not clear now is why a ROOT.war (as a folder can be uploaded as an application), but more importantly, the web.xml in such a .war should be created for that specific application not pinched from some other part of the system as appears in the link, only Tomcat has a purpose for including the DefaultServlet in the webapp declaration not an application being constructed to put into the server as a site at any level of virtual host. – Samuel Marchant Jun 01 '21 at 12:15