How to Deploy Java Spring Boot Application on Tomcat or Wildfly Server


What is Spring Boot?

Spring Boot enables the developer's to quickly develop an Application by using the Spring Framework by taking care of default configurations and allowing Java developers to focus on rapid prototyping. Tomcat is by default the embedded server for Spring Boot. So you don't need to setup tomcat when developing Application using Spring Boot.

Also, when you run your normal Spring Application on Eclipse, Intellij or any Other IDE, you setup Tomcat or any web server in the IDE itself. IDE also manages all the things for you like deploying war file on Server and running the Application. But if you want to deploy your application on some hosting server, you would have to make some necessary changes to your Project.

This post shows you how to Deploy Spring Boot Application on Web Server like Apache Tomcat, Oracle WebLogic Server, Jetty and or any other server.

Follow below steps to Deploy Java Spring Boot Application on Server

  1. Update pom.xml file to include packaging as war:

  2. <project ...> <packaging>war</packaging> <dependencies> ... <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> ... </dependencies> </project>
  3. Add following lines to your Application's Main class

  4. @SpringBootApplication public class MainApplication extends SpringBootServletInitializer { public static void main(String[] args) throws Exception {, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(MainApplication.class); } }

    Our main method delegates to Spring Boot's MainApplication class by calling run. MainApplication bootstraps our application, starting Spring, which, in turn, starts the auto-configured Tomcat web server embedded in Spring Boot. We need to pass MainApplication.class as a parameter to the run method to tell that MainApplication is the primary Spring component. The String args[] array is also passed through to expose any command-line arguments.

  5. Export Project as war file:

    • Using Eclipse: Right-click Project, Click Export-->War
    • Using Maven Command-line: Just type "mvn package" inside project's folder to compile the project into a war file.

  6. Deploying war file to Web Server:

  7. Tomcat
    • Copy the war file generated in Step 3 to "/tomcat/webapps/" folder.
    • Restart Tomcat server.
    • Copy the war file generated in Step 3 to "wildfly-10.1.0.Final\standalone\deployments" folder
    • Restart Wildfly server

Hope, this tutorial helped you to deploy your Java Web application on Server. If you liked the post or have any doubt please comment below.

Want to Clear Java Interview? Read Java Interview Notes prepared by Us

Are You Good enough in Java? Prove it!


Get Answers to your Programming Questions

Recommended Deals ends in

Quiz For You:

Search Tags

    Deploy Java Spring Boot Application on Server

    Install Spring Boot Application on Tomcat Server

    Deploy Java Web Application on Web Server