LoginSignup
0
3

More than 3 years have passed since last update.

最短!STS4でSpring bootの基礎の基礎の基礎

Posted at

概要

STSとSpringBootを初めて使う人向けの手順となります。

STS4上にて、以下の方法を確認します。
- Spring bootのデモサイト作成
- デモサイトの実行
- プロジェクトのExportとImport
- 実行ファイル作成

デモサイトの作成

プロジェクトの作成

  • ファイル->新規->Springスターター・プロジェクト を選択 boot001.png

新規Spring スターター・プロジェクト

  • 名前: demo
  • その他はデフォルト
  • 「次へ」を押下 boot002.png

新規Springスターター・プロジェクト依存関係

  • フィルタ:web
  • Web : Spring Web を選択
  • 「次へ」を押下 boot004.png

新規Springスターター・プロジェクト

  • 「完了」を押下 boot005.png

完了

  • 右下のステータスを確認
  • コンテンツのインポートやビルドが完了するまで待つ boot006.png

デモサイトにhtmlを追加

  • パッケージ・エクスプローラー
    > demo > src/main/resources
    > static
    に、index.htmlファイルを作成
     ※staticを右クリックし、新規->ファイルを押下
     以下を入力し、[完了]を押下。  ファイル名 : index.html boot010.png

デモサイトの実行

Spring Boot アプリケーション実行

  • 実行からSpring Boot アプリケーションを選択 boot011.png
  • コンソールに以下が表示されます boot012.png

Webブラウザで開く

  • Bootダッシュボードからdemoを選択
  • 右クリックでメニューを開き、webブラウザを開く を選択 boot013.png
  • ブラウザ確認 boot014.png

プロジェクトのExport

エクスポートの実行

boot020.png

選択

  • アーカイブ・ファイルを選択 boot021.png

アーカイブ・ファイル

  • 宛先アーカイブ・ファイル に出力先を入力
  • 「完了」を押下 boot022.png

プロジェクトのImport

インポートの実行

  • 前提:同名のプロジェクトはリネームまたは削除しておくこと boot030.png

選択

  • 既存プロジェクトをワークスペースへ を選択 boot031.png

プロジェクトのインポート

  • 宛先アーカイブ・ファイル に出力先を入力
  • 「完了」を押下 boot032.png
  • 取り込まれたことを確認 boot033.png

実行ファイル作成

Mavenビルドの実行

  • 実行から Mavenビルド を選択 boot040.png

構成の編集

  • ゴール: clean package を入力
  • 「実行」を押下 boot041.png

ファイルの確認

  • demo~.jarが作成されていることを確認
$ cd ~
$ cd workspace-sts4/demo/target
$ ls
classes                             generated-sources       maven-status
demo-1-0.0.1-SNAPSHOT.jar           generated-test-sources  surefire-reports
demo-1-0.0.1-SNAPSHOT.jar.original  maven-archiver          test-classes

ファイルの実行

  • STS4上にてbootアプリケーションを起動していない事を確認。
  • 以下を実行し、ブラウザで確認する。
$ java -jar demo-1-0.0.1-SNAPSHOT.jar 

boot050.png

boot051.png


以上となります。

使い方における基本となりますので、知っておいても損はないと思います。

当手順は、2020/04/19時点にて、実行できることを確認しております。

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3