Hello Friends!, today we are going to learn a step-by-step process to create Spring Boot Gradle application using Spring Initializr in Intellij.
you can check our other post on the Maven project, on how to create Spring Boot Application using the below ways.
Application with Eclipse and Maven manually
This is a simple process to create a Spring Boot application as Gradle Project. we will use Spring Initializr tool to bootstrap our application using Spring MVC.
Create Project on Spring Initializr as Gradle Project
Set Project metadata as show in image.
- Project :
Gradle Project
- Group :
com.gyanideveloper.springboot
- Artifact :
user-service
- Name :
user-service
Project should be Gradle Project
as we are developing a Gradle based Spring Boot application in this tutorial.
click on ADD DEPENDENCIES
button or press CTRL + B
on keyboard.search and add Spring Web starter
,Spring Boot Actuator
, Spring Boot DevTools as dependency
as shown in the image.
we can add multiple dependencies
as we required in our application. we can click on EXPLORE button or press CTRL + SPACE on the keyboard to check the application structure
click on GENERATE
button or press CTRL+ ENTER
on the keyboard, This would download a ZIP file to your local machine. Unzip the zip file and extract it to a folder.
Open Spring Boot Application in IntelliJ.
choose File -> Open navigate to the path where you extracted the ZIP file and select that folder as shown below and click on OK
button.
Import project from gradle click on OK
button
Your project will get open in IntelliJ and it takes some time to initialize and Gradle to download the dependencies.
Run Spring Boot Application
our project structure look like below.
you can run spring boot application in multiple way.such as using Toolbar run or using main class, we are using here toolbar Run.
choose run -> run..
as shown below.
select Main class Name
as shown as below
It will take some time and application will start.
It start your Spring Boot application on port number 8080
, we can find console log as below.
If the application fails to start because the port is in use. please check our How to Change the Default Port in Spring Boot post for more details.
12:49:16 AM: Executing task 'UserServiceApplication.main()'...
> Task :compileJava UP-TO-DATE
> Task :processResources UP-TO-DATE
> Task :classes UP-TO-DATE
> Task :UserServiceApplication.main()
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.0.RELEASE)
2020-05-29 00:49:19.630 INFO 7840 --- [ restartedMain] c.g.s.u.UserServiceApplication : Starting UserServiceApplication on DESKTOP-R5VMSGQ with PID 7840 (F:\gyani-developer\gradle\user-service\build\classes\java\main started by Gyani in F:\gyani-developer\gradle\user-service)
2020-05-29 00:49:19.635 INFO 7840 --- [ restartedMain] c.g.s.u.UserServiceApplication : No active profile set, falling back to default profiles: default
2020-05-29 00:49:19.708 INFO 7840 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-05-29 00:49:19.709 INFO 7840 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-05-29 00:49:22.511 INFO 7840 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-05-29 00:49:22.526 INFO 7840 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-05-29 00:49:22.526 INFO 7840 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.35]
2020-05-29 00:49:22.712 INFO 7840 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-05-29 00:49:22.712 INFO 7840 --- [ restartedMain] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3002 ms
2020-05-29 00:49:23.149 INFO 7840 --- [ restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-05-29 00:49:23.788 INFO 7840 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2020-05-29 00:49:23.804 INFO 7840 --- [ restartedMain] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-05-29 00:49:23.920 INFO 7840 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-05-29 00:49:23.942 INFO 7840 --- [ restartedMain] c.g.s.u.UserServiceApplication : Started UserServiceApplication in 4.817 seconds (JVM running for 5.64)
Your first application is ready.
Final Note
we have learn how to create Spring Boot Gradle Application by using Spring Initializr in IntelliJ