** "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.
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.
Go to the official Oracle site (https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html).
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)
Execute the downloaded exe file and follow the installer to complete the installation.
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.
Go to IntelliJ Official Website and click ** DOWNLOAD ** in the center of the screen.
Select either ** Ultimate (paid) ** or ** Community (free) ** [^ 1]. (I chose Community)
Execute the downloaded exe file and complete the installation according to the procedure.
For details on the procedure for IntelliJ, see this article.
Go to the official MySQL site (https://dev.mysql.com/downloads/windows/installer/8.0.html).
Select an OS and click ** DOWNLOAD **. * There may be a description of 32bit, but please download without worrying about it.
Click ** No thanks, just start my download. **.
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.
Launch IntelliJ. You may be asked for a plug-in, but I will proceed without doing anything.
Click ** Create New Project **.
Select ** Gradle **, check ** Java **, and click ** Next **. * For the SDK, select the JDK you installed earlier.
Enter ** GroupId ** and ** ArtifactId ** and click ** Next **. (Please make each ID as you like)
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.
Use ** Sprinig Initializer ** to change the build.gradle settings for Spring Boot. Please access here.
Change the select box at the top of the screen to ** Generate a Gradle Project with java and Spring Boot 2.1.0 **.
Change the GroupId and ArtifactId so that they are the same as when the project was created.
In ** Dependencies **, select the required dependencies. This time, search for ** MySQL ** and ** MyBatis ** and select them.
The final screen will look like the one below. Click ** Generate Project ** when you are done.
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.
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).
Open ** MySQL Command Line Client ** and log in. (password is set at the time of installation)
Anything is fine, so create an appropriate DB.
Next, create the table. In addition, put the data appropriately.
Set the time zone as well. Please refer to here, add the settings to my.ini, and restart MySQL Server.
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.
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.
Please also refer to here for the settings.
**… 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!
"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