Spring Boot had been built for Rapid Application Development. In this tutorial we will learn How to Create Spring Boot Application using some easy examples. We will also focus on How to deploy spring boot application in different application servers.
Here are the following topics that we will cover in this series:
- Create Spring Boot Application using
- start.spring.io
- Eclipse STS
- IntelliJ IDEA STS
- Run Spring Boot Application using
- Java CLI
- Eclipse/IntelliJ IDEA
- Create a Basic Spring Boot application using REST
- How to use Spring Actuator
-
Deploy Spring Boot application in
- IBM Liberty Profile
- IBM Application Server 8.5
If you need an introduction of Spring Boot please find my previous post below.
Create Spring Boot Application using start.spring.io
The best way of bootstrapping Spring Boot application is by using Spring Initializr. Let’s first start by opening http//start.spring.io
.As you already know, you can use either Maven or Gradle to build, however we will use Maven in this tutorial. Click on Switch to the full Version
and you will be able to see the below screen.
Software Needed
- JDK 1.8 (You can use 1.7 or 1.6)
- Maven 3.x
Steps :
- Select
Maven Project
- If you want, change the Group/Package name. We will use
com.adeveloperdiary
- Change the Artifact to
SpringBoot
, Name will automatically change to the same - Leave the packaging to Jar, Java Version to 1.8 (Make sure you have JDK 1.8 in your local or use 1.7 )
- Either type the Dependencies or select them below. We will add
Web
andActuator
here - Click on Generate Project button to download the zip file
Now Extract the zip and you will have the following files.
Open Terminal and navigate to the above folder. Type mvn clean package
and press enter. The Build will start now.
Once the build has been completed, you will have the SpringBoot-0.0.1-SNAPSHOT.jar
created inside the target
folder.
The Size of the jar would be around 13MB
since it will have the embedded Tomcat server in it.
Create Spring Boot Application using Eclipse
We will use STS Toolkit to bootstrap when using eclipse. I am using eclipse MARS .1 version. We will first install the STS (SpringSource Tools Suite). Open Eclipse Marketplace, Type STS in Find and install the STS.
Then open Spring
perspective.
Create a New
-> Spring Starter Project
.
Enter the following details. Click Next.
Select Web
and Actuator
. Click on Next.
Click on Finish.
This should create the Spring Boot Project in Eclipse.
Create Spring Boot Application using IntelliJ IDEA
We will now use IntelliJ IDEA to create our Spring Boot Application.I recommend to use the latest version of IntelliJ. Create a New Project. Select Spring Initializr
. Click on Next.
Enter the following details. Click Next.
Select Web
and Actuator
. Click Next.
Enter the project Name and click Finish.
Your Spring Boot Project has been created now.
Run Spring Boot Application using CLI
We had created the jar file, now we will run it from Command Line by executing this line
1 |
java -jar target/SpringBoot-0.0.1-SNAPSHOT.jar |
You should be able to see Spring Boot in the Command Line.
The server should have started and the default port number will also be displayed as below.
Run Spring Boot Application in Eclipse
Its much easier to run the Spring Boot app in eclipse. Select the project, Right Click and, move to Run As
and click on Spring Boot App
. Again, remember you need to select the project to get this option, not the pom file.
Here is the output.
Run Spring Boot Application in IntelliJ IDEA
Its probably most easy, click on the run icon.
You should be able to see the logs that the application has started.
Conclusion
Hope this Step by Step approach will help you. Next we will learn how to create RESTServices and use Actuator in Spring Boot. Later we will also learn how to deploy Spring Boot Application in IBM Liberty Profile and IBM WAS 8.5 Server.
This is the 2nd part of Getting Started with Spring Boot Series. Find all the parts here.
- An Introduction to Spring Boot
- How to Create Spring Boot Application Step by Step
- How to create RESTFul Webservices using Spring Boot
- How to deploy Spring Boot application in IBM Liberty and WAS 8.5
Naseem Ahamed says
If I run a project more than once on the same port with STS, it gives me an error that the port is already in use. If I change the port again, it is working for the first time only. Can you please help me on this? Should I stop and start the server again and again for every code change?
Error:
java.net.BindException: Address already in use: bind
application.properties entry:
server.port=8080
adeveloperdiary says
The application is still running at the background. You can restart the server, that should resolve the problem. If you are running it as standalone jar make sure that its stopped while you try to run it again.
In case this does not help, pleas let me know what type of server you are using and how you are running it (IDE, Server Name, Steps etc).
Vivek Agarwal says
The application is still running in the background. you ca restart the server, which might solve the problem .
Raj B says
stop server by clicking the red the square button which you can find on console tab..
restart the server is also another solution but i think its is not good solution.
muff says
hi … i have installed STS from eclipse market place..i am using Eclipse Luna.
When i create a new project-> spring starter project
It is giving me error that M2e connector is not installed. before Installing STS , maven was there, but after installing it just vanished frm my system..
I hv even downloaded m2e connectors from market place.. stl no success.
please help
Kate says
I am attempting to mvn clean package.
However, it keeps displaying BUILD FAILURE
Total time: 0.059 s
[INFO] Finished at: 2016-12-07T11:26:14-05:00
[INFO] Final Memory: 6M/310M
[INFO] ————————————————————————
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (C:\Downloads\SpringBoot\src\main\java\com\adeveloperdiary). Please verify you invoked Maven from the correct directory.
this is my mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T11:41:47-05:00)
Maven home: C:\Users\kbultman\Downloads\apache-maven-3.3.9\apache-maven-3.3.9
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_79\jre
Default locale: en_US, platform encoding: Cp1252
OS name: “windows 8.1”, version: “6.3”, arch: “amd64”, family: “windows”
JReis says
had the same issue. Run the command from “C:\Downloads\SpringBoot\”. Its not super clear from the tutorial but you are not supposed to go to the adeveloperdiary folder.
Basically run it from the pom.xml folder 🙂
Richard says
I have created a Spring boot with Web and Actuator and it works fine. Now, I want to add Config Server. How do I do that?
Mach Speed says
This is very nice. Earlier I was creating the spring boot project from the starter/spring.io website. Now I know how to directly create it in eclipse