Home
- Home
- Blog
Author :
Global TechHub
Introduction
In this article, I am going to explain
how to create a Spring Boot Application in different ways. Spring Boot had been
built for Rapid Application Development. In this article, we will explore the
different options of creating Spring Boot projects with Maven and Eclipse. You
will learn:
Ø Create Spring Boot Project with Spring Initializr.
Ø Create Spring Boot Project with Spring Starter Eclipse
Plugin.
Ø Generate Spring Boot Project with a simple Maven Project in
Eclipse.
Create Spring Boot
Project with Spring Initializr
The best way of creating 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.
Steps:
1.
Select Maven Project,
Java and Spring Boot version as 2.0.1
2.
Change the Group/Package
name. Enter as com.eai.integration
3.
Change the Artifact to SpringBoot-Initializr, Name will
automatically change to the same
4.
Type the Dependencies and
select them. We will add Web and Jersey (JAX-RS)
5. Click on Generate Project button to download the zip file.
Now Extract the zip and 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-Initializr-0.0.1-SNAPSHOT.jar
created inside the target folder.
Create Spring Boot
Project with Spring Starter Eclipse Plugin
We will use STS(Spring Tool Suite)
Toolkit to create Spring Boot application when using eclipse. We will first
install the STS. Open Eclipse Marketplace, Type STS in Find and install the
STS.
Create a New -> Spring Starter
Project.
Enter the following details. Click
Next.
Select Web and Web Services as
Dependencies. Click on Next and Click on Finish.
This should create the Spring Boot
Project in Eclipse.
Generate Spring Boot
Project with a simple Maven Project in Eclipse
In Eclipse, start with File > New
> MavenProject.
In the next screen, provide below
details for your project and click Finish.
This would create a basic Maven
project with zero dependencies. Next, add in the appropriate Spring Boot
starters into the pom.xml:
spring-boot-starter – this
lets spring boot autoconfigure your application
spring-boot-starter-web
– this dependency tells spring boot that your application is a web application.
This add the functionality of @Controller, @RequestMapping, etc.
Create the Main Class
Just like any java application, we
need to define the main method in which will be the starting point. Here we
create a class named Application.java with the annotation @SpringBootApplication.
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
System.out.println(“Hello,
Spring Boot”)
}
}
To run, open the class Application
then right click the main method and select run or debug to debug the app. This
will print Hello, Spring Boot
message in the console.
Conclusion
Hope this Step by Step approach will
helped you. Next we will learn how to create REST Services 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. Lot of Spring boot articles to come
here. Keep eye on this blog for more articles.
Download
S. No
|
File Name
|
Size
|
Download
|
1
|
Different
ways of creating Spring Boot Project.pdf
|
1.0 MB
|
Comments
Post a Comment