Running Spring Boot apps. Suppose we have a simple Spring Boot application that we got from importing the “Rest Service” guide. It implements a simple @RestController and serves some JSON back to the user. In order to run this app, you could select “Run As → Spring Boot App” or create your own launch configuration in the Eclipse IDE.
By using Spring Boot application, we can create a war file to deploy into the web server. In this chapter, you are going to learn how to create a WAR file and deploy the Spring Boot application in Tomcat web server.
Spring Boot Servlet Initializer
The traditional way of deployment is making the Spring Boot Application @SpringBootApplication class extend the SpringBootServletInitializer class. Spring Boot Servlet Initializer class file allows you to configure the application when it is launched by using Servlet Container.
The code for Spring Boot Application class file for JAR file deployment is given below −
We need to extend the class SpringBootServletInitializer to support WAR file deployment. The code of Spring Boot Application class file is given below −
![]()
If you are a beginner with Spring Boot, I highly recommend starting with our Spring Boot. IntelliJ IDEA is the most popular Java IDE. https://eternalyellow383.weebly.com/itunes-mac-iphone-apps.html. IntelliJ IDEA provides first-class support to create and run Spring Boot based applications. We can create and configure Spring Boot application in the following ways. Spring boot CLI is a spring command line tool which can help you develop spring application quickly and easily. It utilize spring’s start dependence and automation configuration features, then developer can focus on the business logic code, do not need to care about the project jars dependency and configuration. Finally, we can now run our simple spring boot web application. To run, open the class Application then right-click the main method and select run or debug to debug the app. This will display the spring boot banner and logs in the console. If you are a beginner with Spring Boot, I highly recommend starting with our Spring Boot. IntelliJ IDEA is the most popular Java IDE. IntelliJ IDEA provides first-class support to create and run Spring Boot based applications. We can create and configure Spring Boot application.
Setting Main ClassRun Spring Boot App Mac Download
In Spring Boot, we need to mention the main class that should start in the build file. For this purpose, you can use the following pieces of code −
https://realtorever149.weebly.com/warlock-pet-randomly-takes-dmg.html. For Maven, add the start class in pom.xml properties as shown below −
https://fracfancoe.hatenablog.com/entry/2020/11/25/233422. Dvc 150b drivers for mac. For Gradle, add the main class name in build.gradle as shown below −
Update packaging JAR into WAR
We have to update the packaging JAR into WAR using the following pieces of code − What apps to get on macbook.
For Maven, add the packaging as WAR in pom.xml as shown below −
For Gradle, add the application plugin and war plugin in the build.gradle as shown below −
Now, let us write a simple Rest Endpoint to return the string “Hello World from Tomcat”. To write a Rest Endpoint, we need to add the Spring Boot web starter dependency into our build file.
For Maven, add the Spring Boot starter dependency in pom.xml using the code as shown below −
For Gradle, add the Spring Boot starter dependency in build.gradle using the code as shown below −
Now, write a simple Rest Endpoint in Spring Boot Application class file using the code as shown below −
Boot App For PcPackaging your Application
https://eternalyellow383.weebly.com/dotloop-app-for-mac.html. Now, create a WAR file to deploy into the Tomcat server by using Maven and Gradle commands for packaging your application as given below −
For Maven, use the command mvn package for packaging your application. Then, the WAR file will be created and you can find it in the target directory as shown in the screenshots given below −
For Gradle, use the command gradle clean build for packaging your application. Then, your WAR file will be created and you can find it under build/libs directory. Observe the screenshots given here for a better understanding −
Deploy into Tomcat
Now, run the Tomcat Server, and deploy the WAR file under the webapps directory. Observe the screenshots shown here for a better understanding −
After successful deployment, hit the URL in your web browser http://localhost:8080/demo-0.0.1-SNAPSHOT/ and observe that the output will look as shown in the screenshot given below −
The full code for this purpose is given below.
pom.xml
build.gradle
The code for main Spring Boot application class file is given below −
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |