Create Java Spring Boot project in IntelliJ

Introduction

Organize the steps to create a Spring Boot project in IntelliJ IDEA. This time, Java and Gradle will be used.

procedure

Project creation

Launch IntelliJ and click ** Create New Project **.

スクリーンショット 2020-06-19 0.06.56.png

Select Gradle, Java and click ** Next **.

スクリーンショット 2020-06-19 0.13.14.png

Create a project as SprintBootTest.

スクリーンショット 2020-06-19 1.49.36.png

Edit build.gradle

Build.gradle created in the project

build.gradle


plugins {
    id 'java'
}

group 'com.ykdevs'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Edit as follows. The latest version is specified from Spring Boot. Since IntelliJ is used, idea is specified for plugins. Reference JUnit uses JUnit5.

build.gradle


buildscript {
    ext {
        springBootVersion = '2.3.1.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

plugins {
    id 'idea' // IntelliJ
    id 'java'
}

group 'com.ykdevs'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    // SpringBoot
    implementation "org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}"
    implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
    testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"

    // JUnit
    testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
}

Creating an application execution class

The following directories are created when the project is created.

src
├─ main
│  │
│  ├─ java
│  │
│  └─ resources
└─ test
   │
   ├─ java
   │
   └─ resources

Create a package under main / java.

スクリーンショット 2020-06-21 21.58.00.png

If you specify the package names separated by commas, the directory will be created automatically.

スクリーンショット 2020-06-21 22.22.16.png

Create an application class file in the package directory.

スクリーンショット 2020-06-21 22.05.29.png

Annotate @SpringBootApplication and create main function.

Application.java


package com.ykdevs.springboottest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}

Right-click on the class name and select Generate to create a Test.

スクリーンショット 2020-06-21 22.11.30.png

スクリーンショット 2020-06-21 22.11.40.png

The test looks like the following.

package com.ykdevs.springboottest;

import org.junit.jupiter.api.Test;

class ApplicationTest {

	@Test
	void main() {
		Application.main(new String[0]);
	}
}

Run test with Run

スクリーンショット 2020-06-21 22.29.59.png

スクリーンショット 2020-06-21 22.30.26.png

reference

Gradle User Guide Introduction to Spring Boot-Official Documents JUnit 5 User Guide

Recommended Posts

Create Java Spring Boot project in IntelliJ
How to create a Spring Boot project in IntelliJ
Launch (old) Spring Boot project in IntelliJ
Java tips-Create a Spring Boot project in Gradle
Create a Spring Boot project in intellij and exit immediately after launching
Until you create a Spring Boot project in Intellij and push it to Github
How to create a new Gradle + Java + Jar project in Intellij 2016.03
Create JSON in Java
Run a Spring Boot project in VS Code
Create a Spring Boot application using IntelliJ IDEA
View the Gradle task in the Spring Boot project
A story about a Spring Boot project written in Java that supports Kotlin
Create a portfolio app using Java and Spring Boot
Set context-param in Spring Boot
[Spring Boot] How to create a project (for beginners)
Spring Boot 2 multi-project in Gradle
[Java] Thymeleaf Basic (Spring Boot)
Create Azure Functions in Java
CICS-Run Java application-(4) Spring Boot application
Try gRPC in Spring Boot & Spring Cloud project (Mac OS)
Major changes in Spring Boot 1.5
NoHttpResponseException in Spring Boot + WireMock
[Java] [Spring] Spring Boot 1.4-> 1.2 Downgrade Note
Create microservices with Spring Boot
How to call and use API in Java (Spring Boot)
[Java] Sample project for developing web applications with Spring Boot
Spring Boot + Java + GitHub authentication login
Spring Boot Hello World in Eclipse
Spring Boot application development in Eclipse
Create an app with Spring Boot 2
Java Spring environment in vs Code
Spring Boot: Restful API sample project
Elastic Beanstalk (Java) + Spring Boot + https
Java --Jersey Framework vs Spring Boot
Implement reCAPTCHA v3 in Java / Spring
Create a Java project using Eclipse
(Intellij) Hello World with Spring Boot
Create an app with Spring Boot
Implement REST API in Spring Boot
What is @Autowired in Spring boot?
Implement Spring Boot application in Gradle
[Java] LINE integration with Spring Boot
Java + OpenCV 3.X in IntelliJ IDEA
Setting project environment variables in intelliJ
Thymeleaf usage notes in Spring Boot
I can't create a Java class with a specific name in IntelliJ
[Java] Get data from DB using singleton service in Spring (Boot)
Compare Hello, world! In Spring Boot with Java, Kotlin and Groovy
Spring Java
Create Spring Boot development environment on Vagrant
Create variable length binary data in Java
Try to solve Project Euler in Java
Build Spring Boot + Docker image in Gradle
Static file access priority in Spring boot
Output Spring Boot log in json format
Local file download memorandum in Spring Boot
Optimize Java import declarations in IntelliJ IDEA
Loosen Thymeleaf syntax checking in Spring Boot
Create a TODO app in Java 7 Create Header
[Practice! ] Display Hello World in Spring Boot
Spring Boot + Docker Java development environment construction