Skip to content

Instantly share code, notes, and snippets.

@ko-sasaki
Created June 14, 2025 05:46
Show Gist options
  • Select an option

  • Save ko-sasaki/f38dfe9fc7146268520cf72f333565e5 to your computer and use it in GitHub Desktop.

Select an option

Save ko-sasaki/f38dfe9fc7146268520cf72f333565e5 to your computer and use it in GitHub Desktop.

Revisions

  1. ko-sasaki created this gist Jun 14, 2025.
    51 changes: 51 additions & 0 deletions SpringBootSample.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    ///usr/bin/env jbang "$0" "$@" ; exit $?

    package api;

    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RestController;

    //DEPS org.springframework.boot:spring-boot-starter-web:3.5.0
    //FILES application.yml
    //REPOS central,jitpack,google


    @SpringBootApplication
    @RestController
    public class SpringBootSample {

    @Value("${sample.message}")
    private String message;

    public static void main(String[] args) {
    SpringApplication.run(SpringBootSample.class, args);
    }

    /**
    * 固定メッセージを返却する.
    */
    @GetMapping("/hello")
    public String hello() {
    return "Hello, World!";
    }

    /**
    * URLパスで指定された文字列でメッセージを置換して返却する.
    */
    @GetMapping("/hello/{name}")
    public String hello(@PathVariable String name) {
    return "Hello, {name}!".replace("{name}", name);
    }

    /**
    * application.ymlのメッセージを表示する
    */
    @GetMapping("/hello/message")
    public String message() {
    return message;
    }
    }
    6 changes: 6 additions & 0 deletions application.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@

    server:
    port: 8081

    sample:
    message: Hello, Application Yaml!