How to deploy a spring boot MVC application in traditional tomcat webapps folder?

3k Views Asked by At

I created a simple spring mvc application following a springboot springmvc with gradle example.enter image description here

Below is the structure. src/main/java - This is where all the code base is there. src/main/resources - This is where all the resources/templates are there.


    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;

    @SpringBootApplication
    public class Application {

        public static void main(String[] args) {         
            SpringApplication.run(Application.class, args);
        }

    }

And just writing the above class and with zero configurations, I was able to launch my spring-mvc web application (which is very cool). (through commands gradlew build and gradlew bootrun) But coming from a traditional web application development and deployment background, I am wondering how to create a war file out of this and deploy that into a tomcat webapps folder.

Also, where to keep all the new resources (like js files, css, etc.). We would generally have a WEB-INF folder where we keep them, but what to do here.

3

There are 3 best solutions below

1
On BEST ANSWER

meskobalazs answered your question about the resources when building a war deployment (but notice that src/main/webapp is not read as a resource folder in a jar deployment, you have to add it as a resource in this case).

When you want to change your Spring-Boot app to a web deployment you basically have to do two things:

  • convert the packaging of your project from jar to war
  • change the dependency of the embedded tomcat to provided

Further details can be found on the Spring-Boot documentation site

0
On

Spring Boot include Tomcat container.

You have to remove external Tomcat to deploy your project

0
On

If you are using Maven project you need to modify pom.xml to change the packaging to war, as follows

<packaging>war</packaging>

And If you are using Gradle project you need to modify build.gradle as follows

apply plugin: 'war'

Once you build project it will create war file, so you can easily deploy in any tomcat server webapps folder