Using SpringBoot, a Java framework,
I want to output Hello World
for the time being! I will leave it for those who say.
You can easily generate a template application by selecting a build tool or development language on the browser. (I recognize it as something like scaffold in Ruby on Rails.)
OS: macOS Mojave version 10.14.6 Text editor: Visual Studio Code (hereinafter VSCode)
$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
$ mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 13.0.2, vendor: N/A, runtime: /usr/local/Cellar/openjdk/13.0.2+8_2/libexec/openjdk.jdk/Contents/Home
Default locale: ja_JP, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
$ spring --version
Spring CLI v2.3.1.RELEASE
Please visit here.
Make the following with various additions and corrections.
Then press the GENERATE button
.
I think that the Zip file was downloaded by pressing the GENERATE button.
Extract the Zip file.
This time there should be a folder named demo, so open it in your text editor (this time it's VSCode).
This is a digression, but it is recommended that you install the following as an extension (work will be improved).
・ Java Extension Pack ・ Spring Boot Tools ・ Lombok Annotations Support for VS Code
Create HelloController.java in src / main / java / com / example / demo
.
While referring to the code of Spring Boot Official , Let's describe the contents of HelloController.java!
HelloController.java
package com.example.demo;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration
public class HelloController {
@RequestMapping("/")
String home() {
return "Hello World!";
}
}
Then go to the demo folder in the terminal and
Type mvn spring-boot: run
.
Terminal
$ mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.3.1.RELEASE:run (default-cli) > test-compile @ demo >>>
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
~abridgement~
After a while, the following will be displayed.
Terminal
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.3.1.RELEASE)
~abridgement~
Then in your browser http: // localhost: 8080 / When you enter
Hello World! Is displayed!
This time, I have omitted detailed explanations such as Spring Boot. (The goal was to be able to display it on the browser)
We hope that you can use it for learning, such as changing the code yourself and checking it with a browser.
Recommended Posts