Spring Boot環境構築図文教程

4188 ワード

何がスプリングブックですか?
Spring Bootは通称マイクロサービスです。Spring BootはPivotalチームによって提供される新しいフレームワークであり、その設計目的は新しいSpringアプリケーションの初期構築及び開発過程を簡略化することである。このフレームワークは、特定の方法を使用して配置され、開発者がモデル化された配置を定義する必要がなくなります。このようにSpring Bootは、急速なアプリケーション開発の分野でリーダーとして活躍しています。
1、新たにmavenプロジェクトを作成する
まずワークスペースを選択します

【next】をクリックします

直接デフォルトで【next】をクリックします。

groupidなどを記入してください。そして【finish】はここで全部の新築工事が終わります。
2、関連のjarカバンの導入

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.8.RELEASE</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>

ここで説明します。私達は2つのjarカバンだけを引用しました。実は中には多くのものが含まれています。例えば、spring-book-starter-webのようです。圧縮パッケージを通して開けたら、
中のpomファイルを見ると、以下のような内容が見られます。JAr像springのwebをたくさん引用しています。また、Jsonのjarカバンも含まれています。

<dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-validator</artifactId>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
    </dependency>
  </dependencies>
3、プログラミング入口類

package com.springbooot2;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Hello world!
 *
 */
@SpringBootApplication
public class App 
{
  
  public static void main(String[] args) throws Exception {
    SpringApplication.run(App.class, args);
  }
}
ここで説明します。@Spring Bootationはspringスキャンを識別するために、プログラムの入り口の種類だと彼に教えてくれます。
4、作成要求応答類

package com.springbooot2;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
@Controller
public class FristBlood {
  @RequestMapping("/FristBlood")
  @ResponseBody
  public String hello() {
    return "dont worry,be happy!<br/><br/> <input type=\"submit\" value=\"ok\" />";
  }
}
ここで説明します
@Controllerはコントローラ類の処理を要求します。
@Request Mapping springに詳しいのは全部よく知らないはずです。これはspringのもので、urlマッピングです。
@ResponseBody応答方法は、我々の応答情報が自動的にJson情報に変換されてフロントページに戻ります。
ここに来たらコードを全部消します。私たちが以前に作ったsshやssmのようなフレームワークよりも簡単になりました。もし私たちがあればメールを送るだけです。簡単なサービスで、スプリングブックを使うと便利です。
5、テストコード
プログラムを起動して、ブラウザを開いて、入力:http://localhost:8080/FristBlood
ページ応答の結果を下図のように要求します。

以上が本文の全部です。皆さんの勉強に役に立つように、私たちを応援してください。