@RestControllerでRESTAPI用のコントローラを定義する。
RestController (Spring Framework API) - Javadoc
Fedora41でVSCodeでやる。

まずSpring Boot Extension Packを入れる。
続いて、Spring Boot CLIを入れる。
まず、SDKMANを入れる。
bg1@vbox:~/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController$ curl -s "https://get.sdkman.io" | bash
-+syyyyyyys:
`/yho:` -yd.
`/yh/` +m.
.oho. hy .`
.sh/` :N` `-/o` `+dyyo:.
.yh:` `M- `-/osysoym :hs` `-+sys: hhyssssssssy+
.sh:` `N: ms/-`` yy.yh- -hy. `.N-````````+N.
`od/` `N- -/oM- ddd+` `sd: hNNm -N:
:do` .M. dMMM- `ms. /d+` `NMMs `do
.yy- :N` ```mMMM. - -hy. /MMM: yh
`+d+` `:/oo/` `-/osyh/ossssssdNMM` .sh: yMMN` /m.
-dh- :ymNMMMMy `-/shmNm-`:N/-.`` `.sN /N- `NMMy .m/
`oNs` -hysosmMMMMydmNmds+-.:ohm : sd` :MMM/ yy
.hN+ /d: -MMMmhs/-.` .MMMh .ss+- `yy` sMMN` :N.
:mN/ `N/ `o/-` :MMMo +MMMN- .` `ds mMMh do
/NN/ `N+....--:/+oooosooo+:sMMM: hMMMM: `my .m+ -MMM+ :N.
/NMo -+ooooo+/:-....`...:+hNMN. `NMMMd` .MM/ -m: oMMN. hs
-NMd` :mm -MMMm- .s/ -MMm. /m- mMMd -N.
`mMM/ .- /MMh. -dMo -MMMy od. .MMMs..---yh
+MMM. sNo`.sNMM+ :MMMM/ sh`+MMMNmNm+++-
mMMM- /--ohmMMM+ :MMMMm. `hyymmmdddo
MMMMh. ```` `-+yy/`yMMM/ :MMMMMy -sm:.``..-:-.`
dMMMMmo-.``````..-:/osyhddddho. `+shdh+. hMMM: :MmMMMM/ ./yy/` `:sys+/+sh/
.dMMMMMMmdddddmmNMMMNNNNNMMMMMs sNdo- dMMM- `-/yd/MMMMm-:sy+. :hs- /N`
`/ymNNNNNNNmmdys+/::----/dMMm: +m- mMMM+ohmo/.` sMMMMdo- .om: `sh
`.-----+/.` `.-+hh/` `od. NMMNmds/ `mmy:` +mMy `:yy.
/moyso+//+ossso:. .yy` `dy+:` .. :MMMN+---/oys:
/+m: `.-:::-` /d+ +MMMMMMMNh:`
+MN/ -yh. `+hddhy+.
/MM+ .sh:
:NMo -sh/
-NMs `/yy:
.NMy `:sh+.
`mMm` ./yds-
`dMMMmyo:-.````.-:oymNy:`
+NMMMMMMMMMMMMMMMMms:`
-+shmNMMMNmdy+:`
Now attempting installation...
Looking for a previous installation of SDKMAN...
Looking for unzip...
Looking for zip...
Looking for tar...
Looking for curl...
Looking for sed...
Installing SDKMAN scripts...
Create distribution directories...
Getting available candidates...
Prime platform file...
Prime the config file...
Installing script cli archive...
* Downloading...
######################################################################## 100.0%
* Checking archive integrity...
* Extracting archive...
* Copying archive contents...
* Cleaning up...
Installing script cli archive...
* Downloading...
######################################################################## 100.0%
* Checking archive integrity...
* Extracting archive...
* Copying archive contents...
* Cleaning up...
Set version to 5.20.0 ...
Set native version to 0.7.4 ...
Attempt update of interactive bash profile on regular UNIX...
Added sdkman init snippet to /home/bg1/.bashrc
Attempt update of zsh profile...
Updated existing /home/bg1/.zshrc
All done!
You are subscribed to the STABLE channel.
Please open a new terminal, or run the following in the existing one:
source "/home/bg1/.sdkman/bin/sdkman-init.sh"
Then issue the following command:
sdk help
Enjoy!!!
bg1@vbox:~/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController$ source "$HOME/.sdkman/bin/sdkman-init.sh"
bg1@vbox:~/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController$で、Spring Boot CLIのインストール。
bg1@vbox:~/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController$ sdk install springboot Downloading: springboot 3.5.5 In progress... ###################################################################################################################################################### 100.0% Installing: springboot 3.5.5 Done installing! Setting springboot 3.5.5 as default. bg1@vbox:~/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController$ spring --version Spring CLI v3.5.5 bg1@vbox:~/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController$
Installing: springboot 3.5.5って言ってるけど、Spring CLI v3.5.5らしい。
で、プロジェクト作成。
bg1@vbox:~/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController$ spring init --dependencies=web --build=maven --java-version=21 annotationRestController Using service at https://start.spring.io Project extracted to '/home/bg1/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController/annotationRestController' bg1@vbox:~/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController$
で、できたのが、

こんな感じ。
手作業でいろいろ直す。
ソースのパスやファイル名など、

こんな感じに。
さらに、MainApplication.javaは、
こうする。
@RestControllerをMainApplicationクラスにつけて、コントローラのソースを分けずにhomeメソッドでコントローラを実装。
pom.xmlも、
こうする。
bg1@vbox:~/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController/annotationRestController$ sudo systemctl stop tomcat bg1@vbox:~/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController/annotationRestController$ mvn spring-boot:run [INFO] Scanning for projects... [INFO] [INFO] --< com.bgstation0.spring.sample.annotationrestcontroller:annotationRestController >-- [INFO] Building annotationRestController 0.0.1-SNAPSHOT [INFO] from pom.xml [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] >>> spring-boot:3.5.5:run (default-cli) > test-compile @ annotationRestController >>> [INFO] [INFO] --- resources:3.3.1:resources (default-resources) @ annotationRestController --- [INFO] Copying 1 resource from src/main/resources to target/classes [INFO] Copying 0 resource from src/main/resources to target/classes [INFO] [INFO] --- compiler:3.14.0:compile (default-compile) @ annotationRestController --- [INFO] Nothing to compile - all classes are up to date. [INFO] [INFO] --- resources:3.3.1:testResources (default-testResources) @ annotationRestController --- [INFO] skip non existing resourceDirectory /home/bg1/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController/annotationRestController/src/test/resources [INFO] [INFO] --- compiler:3.14.0:testCompile (default-testCompile) @ annotationRestController --- [INFO] Nothing to compile - all classes are up to date. [INFO] [INFO] <<< spring-boot:3.5.5:run (default-cli) < test-compile @ annotationRestController <<< [INFO] [INFO] [INFO] --- spring-boot:3.5.5:run (default-cli) @ annotationRestController --- [INFO] Attaching agents: [] . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v3.5.5) 2025-08-29T07:14:42.511+09:00 INFO 14839 --- [demo] [ main] c.b.s.s.a.MainApplication : Starting MainApplication using Java 21.0.8 with PID 14839 (/home/bg1/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController/annotationRestController/target/classes started by bg1 in /home/bg1/project/cloud/github.com/Sample/spring/annotationRestController/annotationRestController/src/annotationRestController/annotationRestController) 2025-08-29T07:14:42.514+09:00 INFO 14839 --- [demo] [ main] c.b.s.s.a.MainApplication : No active profile set, falling back to 1 default profile: "default" 2025-08-29T07:14:44.345+09:00 INFO 14839 --- [demo] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http) 2025-08-29T07:14:44.425+09:00 INFO 14839 --- [demo] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2025-08-29T07:14:44.426+09:00 INFO 14839 --- [demo] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.44]
tomcat落としてからmvn spring-boot:runで実行。

うまくいけばこれが出る。