Search code examples
javaspring-boottomcatwarweb-deployment

Spring boot deploying a war


I am trying to deploy an spring boot application with spring boot 2.0.6 and Java 8 into a Tomcat 8 on Ubuntu 18 server and into tomcat 7 on Windows xampp. I read that the better way to do that is creating a war file, put it on the webapps folder and then start the server. I'd try it like this and using the manager app of tomcat.

For configuring tomcat server I followed this guide for tomcat 8 in Ubuntu.

In both of them I ever get the same result, I can start my app in the server after upload it but if I try to access it in the browser writting the path or by clicking the path in the tomcat's manager app but the browser show me a 404 error everytime.The error says: The required resource is not available.

Yesterday I tried to download a sample war and upload this, and it works correctly. So I guess that the mistake is in the form that I create the war.

As IDE I am using Spring Tool Suit 3. To create a war I followed the next steps:

  1. extends SpringBootServletInitializer on my main class.
  2. add the SpringApplicationBuilder method on my main class.
  3. Change the content of the my located in my pom.xml from jar to war.
  4. add the next dependecy:

    <dependency>    
        <groupId>org.springframework.boot</groupId>         
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>     
    </dependency>
    
  5. Right click on the project> Run as >Maven build...

  6. In the input that says "Gloas" write "package".

And after a while the war is created. I don't now if it is the correct form but is the only that I know. Could you help me please?

This is the link to a repository with a sample code with the configuration which I am trying to deploy: https://bitbucket.org/josealvarezvivar/samplespring/src/master/

Thank you in advance.


Solution

  • Hi If you are using Spring Boot 2, you need to exclude netty react server from the webflux dependency like below.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
        <exclusions>
          <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-reactor-netty</artifactId>
          </exclusion>
        </exclusions>
    </dependency>
    

    The use maven to create your WAR file and you should be fine.