スプリングガイド-起動/コアライブラリ/構築方法

5319 ワード

いちじしどうばね


📖 ✏️

  • TILシリーズの記事は「毎日学ぶ知識のかけらを記録する」です.これは、共有ではなく個人学習を記録するために作成されます.
  • の他のシリーズで作成された共有用のロケーションは、いつでも個別に作成されます.主に、TILシリーズで作成されたコンテンツから特定のトピックを選択し、より深い学習とまとめを行います.
  • @SpringBootApplication
    public class HelloSpringApplication {
    
    	public static void main(String[] args) {
    		SpringApplication.run(HelloSpringApplication.class, args);
    	}
    
    }
    main()が最初に運転され、SpringApplication.run()のパラメータクラスが運転を開始し、スプリングガイドが運転を開始します.@SpringBootApplicationが宣言されたため、スプリング起動アプリケーションが実行されます.
    カーネルTomcat Webサーバが独自に動作すると、スプリングガイドが実行されます.

    スプリングガイドのコアライブラリ


    SpringBootには多くの異なるライブラリがあり、それらの間には異なる段階の依存関係があります.
    スプリングガイドは依存性を自動的に管理するため、必要なすべてのライブラリを自動的にインポートします.
    スプリングガイドのコアライブラリを以下に示します.
  • spring-boot-starter-web
    -spring-boot-start-tomcat:Tomcat(Webサーバ)
    -spring-webmvc:springWeb MVC
  • spring-boot-start-thymeleaf:時間軸テンプレートエンジン(View)
  • スプリング-boot-starter(汎用):スプリングガイド+スプリングコア+ログ記録
    - spring-boot
    - spring-core
    - spring-boot-starter-logging logback, slf4j
  • スプリングガイドが「ホーム」(Welcome Page)を検索する方法


    7.1.6. Welcome Page
    Spring Boot supports both static and templated welcome pages. It first looks for an index.html file in the configured static content locations. If one is not found, it then looks for an indext template. If either is found, it is automatically used as the welcome page of the application.
    ソース:https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-welcome-page

    画像の出所:金英漢<スプリング入門-コード学習のスプリング起動、Web MVC、DBアクセス技術>課程資料
    index.htmlでコントローラに移動すると、viewResolverは値を返して画面を検索します.
    Spring BootテンプレートエンジンはviewNameマッピングをサポートします.

    スプリングガイドの構築と実行

  • ./gradlew build
  • cd build/libs
  • java -jar hello-spring-0.0.1-SNAPSHOT.jar
  • 運転確認
  • サーバ上で実行する場合は、サーバにjava -jar (파일명).jar を入れて実行するだけです.
     woply@Jaeminui-MacBookPro  ~/study/hello-spring   master   ll
    total 48
    -rw-r--r--@ 1 woply  staff   1.4K  1  5 06:47 HELP.md
    drwxr-xr-x  6 woply  staff   192B  1  5 16:32 build
    -rw-r--r--@ 1 woply  staff   498B  1  5 06:47 build.gradle
    drwxr-xr-x@ 3 woply  staff    96B  1  5 06:47 gradle
    -rwxr-xr-x@ 1 woply  staff   7.9K  1  5 06:47 gradlew
    -rw-r--r--@ 1 woply  staff   2.7K  1  5 06:47 gradlew.bat
    drwxr-xr-x  3 woply  staff    96B  1  5 16:58 out
    -rw-r--r--@ 1 woply  staff    34B  1  5 06:47 settings.gradle
    drwxr-xr-x@ 4 woply  staff   128B  1  5 06:47 src
    
     ✘ woply@Jaeminui-MacBookPro  ~/study/hello-spring   master  ./gradlew build
    
     woply@Jaeminui-MacBookPro  ~/study/hello-spring   master  cd build
    
     woply@Jaeminui-MacBookPro  ~/study/hello-spring/build   master  cd libs
    
     woply@Jaeminui-MacBookPro  ~/study/hello-spring/build/libs   master  java -jar hello-spring-0.0.1-SNAPSHOT.jar
    ビルドフォルダを削除するとき./gradlewcleanを実行します.
    既存のコンストラクションファイルを完全に消去して再構築する場合./gradle clean buildを実行します.

    スプリングガイドの静的コンテンツ機能


    SpringBootの公式文書では、/staticパスにある静的コンテンツが使用されています.

    ソース:https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-static-content

    /statucパスにhtmlファイルを入れ、urlにファイル名を入れてhtmlファイルを読み込む

    SpringBootの内部では、最初から/staticのパスを検索しません.
    ない場合は、urlを要求するコントローラを検索し、/resoutces/statichello-static.htmlファイルを検索します.