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

(1634 Views)


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 the default embedded server for Spring Boot. So you 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 Install Spring Boot Application on Web Server like Apache Tomcat, Oracle WebLogic Server, Jetty and or any other server.

Follow these steps to Deploy Java Spring Boot Application on Server.

  1. Update pom.xml file:

  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 { SpringApplication.run(MainApplication.class, 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 an argument to the run method to tell MainApplication which is the primary Spring component. The 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.
    Wildfly
    • 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 application on Server. If you liked the post or have any doubt please comment below.

Solution Worked 6 UpvotesUpvote

        

Solution Didn't Worked 1 DownvotesDownvote



Comments



Search
Play 2048 Game Online

Search Tags

    Deploy Java Spring Application on Server

    Install Spring Boot Application on Tomcat Server

    Deploy Java Web Application on Web Server