Try Hello world while looking at Original Documents It was.
I think that the original document will be updated in the future, so As a gyotaku, I will keep a record that the java, marven, spring versions are like this when done in the following state.
$ java -version
java version "11.0.7" 2020-04-14 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.7+8-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.7+8-LTS, mixed mode)
$ mvn -v
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.15.4", arch: "x86_64", family: "mac"
$ spring --version
Spring CLI v2.2.6.RELEASE
The name is "spring-boot-hello" for the time being.
$ mkdir spring-boot-hello
$ cd spring-boot-hello
Create pom.xml directly under the spring-boot-hello folder. Create a file, open it with a text editor, and paste the following content.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
</parent>
<description/>
<developers>
<developer/>
</developers>
<licenses>
<license/>
</licenses>
<scm>
<url/>
</scm>
<url/>
<!-- Additional lines to be added here... -->
</project>
This pom.xml Gemfile for RubyOnRails Package.json for JavaScript I think it's a file.
Add "spring-boot-starter-web" required for web service development to pom.xml.
Added the following after Addtional lines to be add here. (The original document was written under parent, but I thought it would be better, so I wrote it here without permission.)
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Please be careful about nesting when pasting.
To check the dependency, hit the following command.
$ mvn dependency:tree
I think that the various functions required to run the web service are displayed as dependencies.
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.example:myproject >------------------------
[INFO] Building myproject 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) @ myproject ---
[INFO] com.example:myproject:jar:0.0.1-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-starter-web:jar:2.2.6.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.2.6.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:2.2.6.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.6.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.6.RELEASE:compile
[INFO] | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] | | | +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] | | | \- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.12.1:compile
[INFO] | | | \- org.apache.logging.log4j:log4j-api:jar:2.12.1:compile
[INFO] | | \- org.slf4j:jul-to-slf4j:jar:1.7.30:compile
[INFO] | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | +- org.springframework:spring-core:jar:5.2.5.RELEASE:compile
[INFO] | | \- org.springframework:spring-jcl:jar:5.2.5.RELEASE:compile
[INFO] | \- org.yaml:snakeyaml:jar:1.25:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-json:jar:2.2.6.RELEASE:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.10.3:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.3:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.10.3:compile
[INFO] | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.10.3:compile
[INFO] | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.10.3:compile
[INFO] | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.10.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.2.6.RELEASE:compile
[INFO] | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.33:compile
[INFO] | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.33:compile
[INFO] | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.33:compile
[INFO] +- org.springframework.boot:spring-boot-starter-validation:jar:2.2.6.RELEASE:compile
[INFO] | +- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile
[INFO] | \- org.hibernate.validator:hibernate-validator:jar:6.0.18.Final:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.4.1.Final:compile
[INFO] | \- com.fasterxml:classmate:jar:1.5.1:compile
[INFO] +- org.springframework:spring-web:jar:5.2.5.RELEASE:compile
[INFO] | \- org.springframework:spring-beans:jar:5.2.5.RELEASE:compile
[INFO] \- org.springframework:spring-webmvc:jar:5.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:5.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:5.2.5.RELEASE:compile
[INFO] \- org.springframework:spring-expression:jar:5.2.5.RELEASE:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.657 s
[INFO] Finished at: 2020-04-28T14:40:57+09:00
[INFO] ------------------------------------------------------------------------
src/main/java/ Create a folder hierarchy called Example.java and create a file called Example.java under it.
Excample.java
import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration
public class Example {
@RequestMapping("/")
String home() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(Example.class, args);
}
}
$ mvn spring-boot:run
Various things are displayed on the terminal, but I think it will be a success if the following logo appears.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
http://localhost:3000
When I accessed, it was displayed as Hello World.
That is all. The source is on github.
Recommended Posts