Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 921
Anil Avatar asked Jun 10 '15 06:06

Anil


1 Answers

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

like image 84
P.J.Meisch Avatar answered Oct 21 '22 21:10

P.J.Meisch