8

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.

Anil
  • 1,735
  • 2
  • 20
  • 28

3 Answers3

1

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

P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
  • 1
    There is one more important step. You should also verify that the war file's base name matches the spring server.context-name in src/main/resource/application.properties. This way, the URLs will be the same when accessing the Sprng Boot loaded app vs the web app in Tomcat. For example, to see http://localhost:post/mycontext from both deployments, put the line "server.context-path=/mycontext" in src/main/resource/application.properties and then deploy mycontext-1.0.0.war to /webapps/mycontext.war – djb Aug 10 '15 at 19:43
0

Spring Boot include Tomcat container.

You have to remove external Tomcat to deploy your project

Flavio Troia
  • 2,451
  • 1
  • 25
  • 27
0

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

anandchaugule
  • 901
  • 12
  • 20