Tutorial: Create your first Spring application
This tutorial describes how to create and run a Spring application in IntelliJ IDEA. It will be a Spring Boot Maven project generated by Spring Initializr. This is the quickest way to create a Spring application, and IntelliJ IDEA provides a dedicated project wizard for it. You will learn how to expose an HTTP endpoint and map it to a method that returns a greeting to the user when accessed through a web browser.
Create a new Spring Boot project
- In the main menu, go to File | New | Project .
- In the left pane of the New Project wizard, select Spring Initializr .
- Specify a name for the project: spring-boot-tutorial . From the JDK list, select Download JDK and download the latest version of Oracle OpenJDK. Select the latest Java version.
Click Next to continue. - Select the Spring Web dependency under Web . This dependency is required for any web application that uses Spring MVC.
Click Create to generate and set up the project. Besides the New Project wizard, you can manage Spring Starters later, in existing Spring Boot projects: with your pom.xml or build.gradle file open in the editor, click the Edit Starters inlay hint next to the dependencies list or press Alt+Insert and select Edit Starters . This lets you quickly find, add, and remove Spring dependencies in existing projects without having to manually modify the file or thinking about compatible versions. You can disable and enable this inlay hint in the IDE settings ( Control+Alt+S ), in Editor | Inlay Hints | Other , under Groovy , Kotlin , and XML .
Add a method that sends a greeting
Spring Initializr creates a class with the main() method to bootstrap your Spring application. In this tutorial, we’ll add the sayHello() method directly to this class.

- Open the SpringBootTutorialApplication.java file under src/main/java/com/example/springboottutorial . IntelliJ IDEA provides the Go to File action to quickly find and open files. Go to Navigate | File or press Control+Shift+N , start typing the name of the file and select it from the list.
- Add the sayHello() method with all of the necessary annotations and imports so that the file looks like this:
package com.example.springboottutorial; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @RestController public class SpringBootTutorialApplication < public static void main(String[] args) < SpringApplication.run(SpringBootTutorialApplication.class, args); >@GetMapping(«/hello») public String sayHello(@RequestParam(value = «myName», defaultValue = «World») String name) < return String.format("Hello %s!", name); >>
- The @RestController annotation marks the SpringBootTutorialApplication class as a request handler (a REST controller).
- The @GetMapping(«/hello») annotation maps the sayHello() method to GET requests for /hello .
- The @RequestParam annotation maps the name method parameter to the myName web request parameter. If you don’t provide the myName parameter in your web request, it will default to World .
Run your Spring application
IntelliJ IDEA creates a Spring Boot run configuration that you can use to run your new Spring application.
- If the run configuration is selected, press Shift+F10 . You can also use the icon in the gutter of the SpringBootTutorialApplication.java file next to the class declaration or the main() method declaration.
By default, IntelliJ IDEA shows your running Spring Boot application in the Run tool window.

The Console tab shows the output of Spring log messages. By default, the built-in Apache Tomcat server is listening on port 8080. Open your web browser and go to http://localhost:8080/hello. If you did everything right, you should see your application respond with Hello World! .

You can quickly open this URL in your browser using the dedicated intention action: place the caret at the controller URL mapping (such as /hello ), press Alt+Enter , and select Open in web browser .
This is the default generic response. You can provide a parameter in your web request to let the application know how to greet you properly. For example, try http://localhost:8080/hello?myName=Human.
Add a home page
The created Spring Boot application has one endpoint available at /hello. However, if you open the root context of your application at http://localhost:8080/, you will get an error because there is no root resource defined. Let’s add a static HTML home page with links to your endpoint.
- Create the index.html file under /src/main/resources/static/ . In the Project tool window, right-click the /src/main/resources/static/ directory, select New | HTML File , specify the name index.html , and press Enter .
- Modify the default template or replace it with the following HTML code:
Now your application will serve index.html as the root resource at http://localhost:8080/.
What’s next?
This simple application demonstrates how to get started with Spring. To learn how IntelliJ IDEA helps you write your code and manage the application at runtime, refer to the next tutorial, which focuses on more advanced Spring support features.
Spring Initializr project wizard
Use the Spring Initializr project wizard to generate a new Spring Boot project in IntelliJ IDEA.
- In the main menu, go to File | New | Project .
- In the New Project dialog, select Spring Initializr .
Step 1. Basic project configuration

Use the default https://start.spring.io/ service or specify a custom instance. For more information, refer to Creating your own instance.
Specify a name for your project.
Specify the path to the directory in which you want to create the project. By default, the IDE creates a directory with the same name as the project.
Select the language that you want to use in your application.
Select the build tool to use for managing dependencies, testing, packaging, automating the build process, and so on: Gradle — Groovy , Gradle — Kotlin , or Maven .
Specify the unique group identifier for your project. It should preferably start with the reversed domain name you control (for example, com.example ).
Specify a name for the artifact within the group, usually the project’s name.
Specify the root package of the project. This is usually a combination of the group and artifact names, for example: com.example.springdemo .
From the JDK list, select the JDK that you want to use in your project.
If the JDK is installed on your computer, but not defined in the IDE, select Add JDK and specify the path to the JDK home directory.
If you don’t have the necessary JDK on your computer, select Download JDK .
Select the Java version that the initializing service should use.
Select whether you want to package the app as a JAR or WAR.
Step 2. Spring Boot dependencies

Select the Spring Boot version.
Download pre-built shared indexes for JDK and Maven libraries
Silently download the pre-built shared indexes for JDK and Maven libraries instead of building the indexes. For more information, refer to Shared indexes.
Select starters and dependencies for your project. If you select technologies that require additional plugins, the IDE will notify you about it once the project is created, and will suggest installing or enabling them.
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 new Spring Boot project via the Spring Initializr wizard
- In the main menu, go to File | New | Project .
- In the left pane of the New Project wizard, select Spring Initializr .
- Go through the steps of the Spring Initializr project wizard.
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 Control+Alt+S , select Languages & Frameworks | Spring | Spring Initializr and disable the Reformat code when creating a new project option.
Run a Spring Boot application

- Open the class with the main() method (it is usually also designated with the @SpringBootApplication annotation), click in the gutter, and select to run the class. Alternatively, you can press Control+Shift+F10 with the class file open in the editor.
IntelliJ IDEA creates and executes the Spring Boot run configuration. For more information, refer to Spring Boot run configuration.
Use Gradle to run Spring Boot
By default, for Spring Boot Gradle-based applications, IntelliJ IDEA uses Gradle to build the project and IntelliJ IDEA to run it. You can configure the IDE to use Gradle instead of IntelliJ IDEA to run Spring Boot applications.
- Go to the Advanced Settings page of the IDE settings Control+Alt+S .
- Under Frameworks. Spring Boot select Run using Gradle .
The Run using Gradle checkbox has no effect if IntelliJ IDEA is selected in Build, Execution, Deployment | Build Tools | Gradle | Build and run using . In this case, IntelliJ IDEA will be used to both build and run your Spring Boot application.
The value of Advanced Settings | Run using Gradle is an IDE-level setting while settings under Build, Execution, Deployment | Build Tools | Gradle can be configured for each project individually.
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:

- In the main menu, go to File | Project Structure or press Control+Alt+Shift+S to open the Project Structure dialog.
- Add the Spring facet: from the left-hand list, select Facets , click , and select Spring .
- In the right-hand section, select Configuration Files and click ( Customize Spring Boot ) in the toolbar.
- 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.
Some custom configuration files are detected automatically. For example, profile-specific configuration files with names that match the current naming pattern will be added to the context.
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, refer to Spring Boot Actuator: Production-ready Features.
Enable the Spring Boot actuator endpoints

- In your pom.xml or build.gradle file, click the Edit Starters inlay hint next to the dependencies list. Alternatively, press Alt+Insert anywhere in the file and select Edit Starters .
- In the window that opens, select Spring Boot Actuator .
Or you can add the spring-boot-starter-actuator dependency manually:
Open the pom.xml file and add the following dependency under dependencies :
Open the build.gradle file and add the following dependency under dependencies :
implementation ‘org.springframework.boot:spring-boot-starter-actuator’
Open the build.gradle.kts 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.
View the Spring Boot actuator endpoints

- Run your Spring Boot application and open the Services tool window: select View | Tool Windows | Services or press Alt+8 .
- Select your running Spring Boot application and open the Actuator tab.
If the Spring Boot run configurations are not available in the Services tool window, either add them or use the Run or Debug tool window.
You can use tabs to view endpoints of the following types: runtime beans, health information, and request mappings.
Beans
The Beans tab under Actuator shows the runtime beans of your Spring Boot application. Double-click any bean to open its declaration in the editor. These beans are indicated using the icon in the gutter. Click this icon to view dependent and injected beans.
The Beans tab includes the following toolbar actions:
Refresh the runtime beans information collected by the JMX agent.
Show the complete graph for all your runtime beans instead of a list.
Required plugin: Diagrams (bundled).
Show Library Beans
Show beans from libraries.
Show Configuration Files
Show available configuration files.
Show Bean Documentation
Show the documentation for the selected bean.
Show Bean Graph
Show the direct dependencies for the selected bean.
Required plugin: Diagrams (bundled).
Health
The Health tab under Actuator shows the status of your application. There are some auto-configured health indicators and you can also write custom health indicators.
For more information, refer to Health.
Mappings
The Mappings tab under Actuator shows the request mappings of your application. It lists all methods with the @RequestMapping annotation or its shortcuts, such as @GetMapping .
If you click the path mapping URI, you can select to run the corresponding HTTP request, open an HTTP requests file with the request, or open the request URL in the web browser (if it’s a GET request). For more information, refer to HTTP Client.

Double-click a method to open its declaration in the editor. Spring registers such methods as handlers and IntelliJ IDEA indicates them with the icon in the gutter. Click this icon to run the corresponding HTTP request, open it in a requests files, or in the web browser (if it’s a GET request).
The Mappings tab includes the following toolbar actions:
Refresh the request mappings collected by the JMX agent.
Open in Browser
Open the root application URL in a web browser.
Select which request methods to show.
Show Library Mappings
Show request mappings from libraries.
Application update policies
With the spring-boot-devtools module, your application will restart every time files on the classpath change. If IntelliJ IDEA is configured to continuously compile changed files, you can set a trigger file. In this case, your application will restart only after you modify the trigger file. For more information, refer to Automatic Restart.
Enable automatic restart
- Add the spring-boot-devtools module dependency for your project.
Open the pom.xml file and add the following dependency under dependencies :
Setting the spring-boot-devtools dependency as optional prevents it from being used in other modules that use your project.
Open the build.gradle file and add the following dependency under dependencies :
developmentOnly(«org.springframework.boot:spring-boot-devtools»)
Setting the spring-boot-devtools dependency as developmentOnly prevents it from being used in other modules that use your project.
To update a running application, go to Run | Debugging Actions | Update Running Application Control+F10 in the main menu, or select your application in the Services tool window and click . Depending on your needs, you can configure what the IDE will do when you execute this action.
If the Spring Boot run configurations are not available in the Services tool window, either add them or use the Run or Debug tool window.
Configure the application update policy

- In the main menu, go to Run | Edit Configurations .
- Select the necessary Spring Boot run configuration to open its settings. Click Modify options .
- In the list that opens, point to On ‘Update’ action . You can choose to update only the resources, update both the classes and the resources (build your application), update the trigger file (which will trigger a restart), or try to perform a class hot swap, and if it fails, update the trigger file. For the Update trigger file and the Hot swap classes and update trigger file if failed policies, the IDE sets a trigger file when you start the application.
- In the Modify options list, point to On frame deactivation and select an action that the IDE will do after you switch to another application: update the resources, or build your application.
You can create several Spring Boot run/debug configurations with different update policies and switch between them.
Как установить/подключить Spring and Spring Initializr Service в IDEA 14.1.6?


Intellij IDEA 14 + spring MVC, как правильно установить готовый проект на сервер?
Приветствую! Не могу нагуглить ответ на вопрос, заданный в теме топика. Т.к. почти закончил.
Spring: а как вы разрешаете зависимости для spring ?
Прикручиваю авторизацию к своему мини-серверу и таки понимаю что я 5 минут ищу решение и 15 минут.
Как подключить css в Spring?
Здравствуйте. У меня есть такая проблема. Сделал тестовый пример на Spring + Hibernate, GlassFish.
Как подключить js из maven к spring mvc?
Не получается подключить js из maven к spring mvc <head> <script type="text/javascript".
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
Помогаю со студенческими работами здесь
easyui+Spring+idea
Добрый день. Начал изучать Java, Spring. Так же работу с плагином JQuery EasyUI. У них на сайте.
Как подключить Spring Security c минимальными настройками
У меня основной код написан только на Java configs. Конфигурационные файлы @Import(value =.
В IntelleJ IDEA нет Spring
Здравствуйте Как докачать, подключить Spring в IDEA? Что-то помнится, когда я устанавливал среду.
Spring vanilla + JPA — service `remember me`
А что если стандартная конфигурация не подходит и нужно уменьшить или увеличить время действия.
Или воспользуйтесь поиском по форуму: