01. I tried to build an environment with SpringBoot + IntelliJ + MySQL (MyBatis) (Windows10)

Target

** "I want to make a simple API or Web application using java for studying, but it is troublesome to build an environment on my home PC ..." ** will be described as the main target. We have prepared each link for detailed procedures, so we will hand over to that and describe simple work procedures.

By the way, my environment is Windows, so if you are a Windows user, you should be able to build the environment with the same procedure.

Overview

On this page, ** is described from ** Spring Boot (java) to the point where it connects to DB **. Please note that we have not touched on the actual program. Although it is still the title, we will make it possible to develop with the following configuration.

procedure

1. Install various tools

1-1. Install the JDK

  1. Go to the official Oracle site (https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html).

  2. Since ** JDK 8u191 ** will be used this time, check ** Accept License Agreement ** and select the one that matches the OS to be used. (I chose Windows x64) インストール手順1.png

  3. Execute the downloaded exe file and follow the installer to complete the installation.

  4. Set the environment variables (** JAVA_HOME, Path **).

Please refer to this article for JDK and environment variables. Make sure to set and check environment variables.

1-2. Install IntelliJ IDEA

  1. Go to IntelliJ Official Website and click ** DOWNLOAD ** in the center of the screen.

  2. Select either ** Ultimate (paid) ** or ** Community (free) ** [^ 1]. (I chose Community)

  3. Execute the downloaded exe file and complete the installation according to the procedure.

For details on the procedure for IntelliJ, see this article.

1-3. Install MySQL

  1. Go to the official MySQL site (https://dev.mysql.com/downloads/windows/installer/8.0.html).

  2. Select an OS and click ** DOWNLOAD **. * There may be a description of 32bit, but please download without worrying about it. ダウンロード手順1.png

  3. Click ** No thanks, just start my download. **. ダウンロード手順2.png

  4. Run the downloaded msi file and follow the steps to complete the installation.

Please see this article for the details of the procedure. Just like the JDK, let's set and check the environment variables. * If you need to reinstall, please refer to this article. It seems that the reinstallation fails just by uninstalling from the control panel. </ font>

Installation is complete when this is complete. Next, let's create a project.

2. Create a Spring Boot Project

  1. Launch IntelliJ. You may be asked for a plug-in, but I will proceed without doing anything.

  2. Click ** Create New Project **. プロジェクト作成1.png

  3. Select ** Gradle **, check ** Java **, and click ** Next **. * For the SDK, select the JDK you installed earlier. プロジェクト作成2.png

  4. Enter ** GroupId ** and ** ArtifactId ** and click ** Next **. (Please make each ID as you like) プロジェクト作成3.png

  1. After that, click ** Next ** without changing any settings and proceed to ** Finish **.

If you proceed to this point, you should have created a project. (Even if an error occurs, you can ignore it) Next, I want to put in the necessary dependencies, so let's use Spring Initializer.

3. Use Spring Initializer to inject the required dependencies

  1. Use ** Sprinig Initializer ** to change the build.gradle settings for Spring Boot. Please access here.

  2. Change the select box at the top of the screen to ** Generate a Gradle Project with java and Spring Boot 2.1.0 **.

  3. Change the GroupId and ArtifactId so that they are the same as when the project was created.

  4. In ** Dependencies **, select the required dependencies. This time, search for ** MySQL ** and ** MyBatis ** and select them.

  5. The final screen will look like the one below. Click ** Generate Project ** when you are done. プロジェクト作成4.png

  6. Open the downloaded zip file and copy and paste ** build.gradle ** in it to build.gradle that exists on your project. Then run ** Refresh ** at the top right of the screen to recapture the dependencies. Even if you get an error when creating your first project, you should be able to complete it successfully at this time. プロジェクト作成5.png

If you come to this point, you will have a rest. In the current state, the DB connection settings have not been made, so the app will not start. Let's modify application.yml (or properties).

4. Modify application.yml (properties) to connect to DB

4-1. Create a table in DB

  1. Open ** MySQL Command Line Client ** and log in. (password is set at the time of installation) テーブル作成1.png

  2. Anything is fine, so create an appropriate DB. テーブル作成2.png

  3. Next, create the table. In addition, put the data appropriately. テーブル作成3.png

  4. Set the time zone as well. Please refer to here, add the settings to my.ini, and restart MySQL Server.

4-2. Describe the connection information in application.yml

  1. Enter the DB information in application.yml. The item must have at least ** url, username and password . - url ** is * jdbc: mysql: // localhost / sample_db (table name) . -* username ** should be * root . (If you have created another user, that is fine) -* password ** is the password * of the user entered in * username. DB接続1.png

  2. Now, let's execute ** ○○ Application.java ** under src / main of the project once. If the log ** Started 〇〇 Application ** appears, the settings have been read normally and it is successful. DB接続2.png

Please also refer to here for the settings.

5. Actually get the value from the DB (although it deviates a little from the environment settings)

  1. Let's write Java appropriately and get the value from DB. (I will write more about this area separately)
  2. As a result of hitting with postman, I got it! DB接続3.png

Impressions I tried myself

**… Isn't there an easier way? ** ** Spring Boot is convenient! I thought it would go more smoothly, so I felt a little uncomfortable. But now you can connect to the DB!

Finally

"There is a better way!" "You should set this here!" We look forward to your comments!

Next, I would like to introduce how to write a program that actually connects to the DB. ⇒ ** Article has been uploaded! ** I made an API to connect to MySQL from Spring Boot Thank you for reading to the end!

[^ 1]: Please see here for the difference between paid and free. By the way, the author uses the Community for business because of the license, but there is no problem at all. ** Community (free) is recommended for trial **.

Recommended Posts

01. I tried to build an environment with SpringBoot + IntelliJ + MySQL (MyBatis) (Windows10)
When I tried to build an environment of PHP7.4 + Apache + MySQL with Docker, I got stuck [Windows & Mac]
I tried to build an http2 development environment with Eclipse + Tomcat
I tried to build an environment using Docker (beginner)
I tried to make an introduction to PHP + MySQL with Docker
I tried to build the environment of PlantUML Server with Docker
I tried to build an API server with Go (Echo) x MySQL x Docker x Clean Architecture
I tried to build a Firebase application development environment with Docker in 2020
[Rails] How to build an environment with Docker
[First environment construction] I tried to create a Rails 6 + MySQL 8.0 + Docker environment on Windows 10.
How to build an environment of [TypeScript + Vue + Express + MySQL] with Docker ~ Vue edition ~
How to build docker environment with Gradle for intelliJ
I started MySQL 5.7 with docker-compose and tried to connect
I tried to create a java8 development environment with Chocolatey
How to build [TypeScript + Vue + Express + MySQL] environment with Docker ~ Express ~
I tried to build the environment little by little using docker
I tried to build the environment of WSL2 + Docker + VSCode
I tried to create a padrino development environment with Docker
I tried to interact with Java
I was addicted to WSl when trying to build an android application development environment with Vue.js
02. I made an API to connect to MySQL (MyBatis) from Spring Boot
I tried connecting to MySQL using JDBC Template with Spring MVC
How to build [TypeScript + Vue + Express + MySQL] environment with Docker ~ MySQL edition ~
I tried to make an Android application with MVC now (Java)
How to build Rails + Vue + MySQL environment with Docker [2020/09 latest version]
How to build [TypeScript + Vue + Express + MySQL] environment with Docker ~ Sequelize ~
I tried to build a laravel operating environment while remembering Docker
I tried to get started with WebAssembly
I tried using OnlineConverter with SpringBoot + JODConverter
I tried to build AdoptOpenjdk 11 on CentOS 7
I tried to build Ruby 3.0.0 from source
Build an environment with Docker on AWS
I tried to implement ModanShogi with Kinx
How to build Rails 6 environment with Docker
I installed WSL2 without using Microsoft Store and tried to build an environment where Docker can be used
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
I tried to make Basic authentication with Java
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
I tried to manage struts configuration with Coggle
I tried to manage login information with JMX
[Java] I tried to connect using a connection pool with Servlet (tomcat) & MySQL & Java
Build an E2E test environment with Selenium (Java)
[Error resolution] Occurs when trying to build an environment for spring with docker
I tried to build AdoptOpenJDK 8 (Addition: Amazon Corretto 8)
I tried to build Micra mackerel in 1 hour!
I tried to develop an application in 2 languages
[First team development ②] Build an environment with Docker
I tried to break a block with java (1)
I built a CentOS 8 environment with Vagrant and tried to sync_folder, but I got an error, so I solved it.
When I tried to unit test with IntelliJ, I was told "java.lang.OutOfMemoryError: Java heap space"
I got an error when trying to install sbt to build a Scala development environment
[Road _node.js_1-1] Road to build Node.js Express MySQL environment using Docker
I tried to read and output CSV with Outsystems
I tried to implement TCP / IP + BIO with JAVA
I built an Ubuntu environment on Windows 10 using WSL2.
[Java 11] I tried to execute Java without compiling with javac
Build ruby debug environment with VS Code of Windows 10
I tried to get started with Spring Data JPA
[Note] I suddenly can't build with Docker for windows.
I tried to draw animation with Blazor + canvas API
I tried to implement Stalin sort with Java Collector