Spring BootをGradleで作成する方法
STSのSpringスタータープロジェクトが昔と違ってかなり進化しているので、Gradleで簡単なRest API(REpresentational State Transfer)を作ってみます。
「次へ」をクリックします。
「完了」を選択すると、jp.co.confrageパッケージにSts2Application.javaが作成されています。中身は以下の通りです。
package jp.co.confrage;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Sts2Application {
public static void main(String[] args) {
SpringApplication.run(Sts2Application.class, args);
}
}
次にRestControllerを作成します。HTMLを返す場合は@Controllerですが、文字を返すだけなので@RestControllerにしています。
package jp.co.confrage;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Sts2Controller {
@RequestMapping("/")
public String home() {
return "test-desu";
}
}
これでプロジェクトを右クリックし、「実行」-「Spring Boot アプリケーション」を選択して、http://localhost:8080/にアクセスすれば、文字が表示されます。

KHI入社して退社。今はCONFRAGEで正社員です。関西で140-170/80~120万から受け付けております^^
得意技はJS(ES20xx),Java,AWSの大体のリソースです
コメントはやさしくお願いいたします^^
座右の銘は、「狭き門より入れ」「願わくは、我に七難八苦を与えたまえ」です^^





コメント