Spring Bootでwebアプリを作る話
Spring bootでwebアプリの使い方ってどうだったっけ?
と思って作り方を思い出してみました。
GitHub : https://github.com/wataru775/example.springboot.web/tree/0.helloworld
@Controller
public class RootController {
@RequestMapping("/")
@ResponseBody
public String index() {
return "Hello World!";
}
}
これだけですねw
ただ、定義が…
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mmpp</groupId>
<artifactId>example.springboot.web</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<spring-boot.version>2.6.2</spring-boot.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
ライブラリを追加だけです
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
それだけですね。
覚書です
ついでにの覚書
mavenの依存を書いた時にIntelliJ IDEAで反映させるには
pom.xmlを右クリックで[MAVEN] > [Reload Project]
です…
これだけで悩みました
作業対象 : IntelliJ IDEA 2021.3.1