For studying because I'm likely to make friends with WEB API using Spring Boot in business Create Spring tool suite 4 development environment in windows10 environment. Let's make a sample site for the time being.
type | name | version |
---|---|---|
IDE | Visual Studio Code | 1.14.1 |
Plugin | Spring Boot Extension Pack | 0.0.8 |
Plugin | Java Extension Pack | 0.8.1 |
Java | JDK | 8.0.232.09-hotspot |
project management | apache-maven | 3.6.3 |
So, we will build the current latest (2019/12/24) "Spring Tools Suite 4" environment. The officially supported IDEs are "Eclipse", "VSCode", and "Atom", and this time we will build with VSCode.
Install JDK / MAVEN / VS Code. SpringToolsSuite (STS) seems to have to be JDK 1.8 or higher, so Java 8 is installed. For MAVEN and JDK, you will need the installation path later, so I personally recommend dropping the compressed file and extracting it in an easy-to-understand place.
JDK
This time it is arranged like this
D:/
├── JDK
| └── jdk-8.0.232.09-hotspot
└── maven
└── apache-maven-3.6.3
Pass the path to the folder where you extracted JDK and MAVEN. In Control Panel ⇒ System ⇒ Advanced System Settings ⇒ Environment Variable Settings
JAVA_HOME="D:/openjdk/jdk-8.0.232.09-hotspot"
MAVEN_HOME="D:/apache-maven-3.6.3"
Path=%JAVA_HOME%\bin;%MAVEN_HOME%\bin;%Path%
Install the following on the VS Code add-on search screen. Spring Boot Extension Pack Java Extension Pack
The VS Code plugins start to get angry, "Where is Java?", So I'll tell you the path you installed there as well. File ⇒ Basic settings ⇒ Settings ⇒ Add the following description to the setting file opened with the icon (Open Settings (JSON)) on the upper right.
{
"java.home": "D:\\openjdk\\jdk-8.0.232.09-hotspot",
"maven.executable.path": "D:\\apache-maven-3.6.3\\bin\\mvn", //I want to know where the maven executable is also
"maven.terminal.useJavaHome": true //Instruct maven to look at the Java path
}
The installation has been completed so far, but if you are using a proxy in-house, you may get the necessary libraries when creating a project and an error may occur. In that case, perform the following procedure. ** Addition to setting.json **
{
"http.proxy": "{Proxy server URL}:{port number}",
//If it's a proxy environment, I'll specify where VS Code will download the library.
}
** Creating settings.xml ** Create a "settings.xml" file in "C: /Users/{username}/.m2" to allow maven to use the proxy.
settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<usePluginRegistry/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors/>
<proxies>
<proxy>
<id>{A string that can be a unique ID}</id>
<active>true</active>
<protocol>http</protocol>
<host>{Proxy server URL}</host>
<port>{port}</port>
</proxy>
</proxies>
<profiles/>
<activeProfiles/>
</settings>
Select the following three dependencies
When you open VS Code again in the created project folder, You can see that it recognizes the projects created by Java, Maven, and Spring Boot.
Add the file to the path below.
\src\main\resources\templates\hogehoge.html(HTML to display)
\src\main\java\com\hogehoge\test_project\controller\HogehogeController.java(Routing controller)
HogehogeController.java
package com.hogehoge.test_project.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HogehogeController {
@RequestMapping("/hogehoge") //Specify the URL here.
public String hogehoge() {
return "hogehoge"; //HTML with the same name as the character returned here is called.
}
}
hogehoge.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hogehoge</title>
</head>
<body>
<h1>HelloWorld</h1>
</body>
</html>
Can be executed with "SPRING-BOOT DASH BOARD" at the bottom left
Recommended Posts