How To Create Spring Boot Project In Intellij With Gradle
Spring Boot
Spring Boot is an extension of the Spring framework that simplifies the initial configuration of Spring applications. It enables you to quickly create a working standalone Spring application with minimum default configuration.
Spring Initializr is a web application that can generate a Spring Boot project. You can select the necessary configuration, including the build tool, language, version of the Spring Boot framework, and any dependencies for your project. IntelliJ IDEA provides the Spring Initializr project wizard that integrates with the Spring Initializr API to generate and import your project directly from the IDE.
Create a Spring Boot project
-
From the main menu, select .
-
In the left pane of the New Project wizard, select Spring Initializr.
-
Go through the steps of the Spring Initializr wizard.
For an example, see Tutorial: Create your first Spring application.
Spring Initializr generates a valid project structure with the following files:
-
A build configuration file, for example, build.gradle for Gradle or pom.xml for Maven.
-
A class with the
main()
method to bootstrap the application. -
An empty JUnit test class.
-
An empty Spring application configuration file: application.properties
By default, IntelliJ IDEA applies code formatting to the generated files. If you want the files to remain formatted as they are generated by Spring Initializr, open the IDE settings with Ctrl+Alt+S, select and disable the Reformat code option in the New Initializr Projects group.
Custom configuration files
Spring Initializr creates one default configuration file that may not always be sufficient for development. If you do not want to use the default configuration file, or if you want to run your code in different environments, you can use custom configuration files defined in your project.
Let IntelliJ IDEA know which files are configuration files in your project to enable relevant highlighting and coding assistance:
-
From the main menu, select or press Ctrl+Alt+Shift+S to open the Project Structure dialog.
-
From the left-hand list, select Facets.
-
Select the Spring facet from the list in the middle and click in the right-hand section.
-
If you want to use a custom configuration file instead of the default one, type its name in the
spring.config.name
field.If you want to use multiple configuration files, click and select files from the project tree.
Valid configuration files are marked with .
-
Click OK and apply the changes.
Runtime endpoints
Spring Boot includes additional features for monitoring and managing the state of your application in the production environment through HTTP endpoints or with Java Management Extensions (JMX). For more information, see Spring Boot Actuator: Production-ready Features.
Enable the Spring Boot endpoints
-
Add the Spring Boot Actuator dependency for your project.
Open the pom.xml file and add the following dependency under
dependencies
:<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
Open the build.gradle file and add the following dependency under
dependencies
:implementation 'org.springframework.boot:spring-boot-starter-actuator'
When you run your application with this dependency, you will be able to access the exposed actuator endpoints via HTTP. For example, if the application is running on localhost port number 8080, the default URL for the health
endpoint will be http://localhost:8080/actuator/health.
Expose the Spring Boot endpoints through JMX
By default, IntelliJ IDEA enables the JMX agent for the Spring Boot run configuration, so when you run your application, the IDE can access the actuator endpoints.
-
From the main menu, select .
-
In the Run/Debug Configurations dialog, select your Spring Boot run configuration, and then select the Enable JMX agent option.
View the Spring Boot endpoints
-
Run your Spring Boot application and open the Services tool window: select or press Alt+8.
-
Select your running Spring Boot application and open the Endpoints tab.
You can use tabs to view endpoints of the following types: runtime beans, health information, and request mappings.
0 Response to "How To Create Spring Boot Project In Intellij With Gradle"
Post a Comment