春のブートエントリhelloWord簡単な例

新しいプロジェクトを作成しますspringboot 1

あなたはここで見ることができますhttps://blog.csdn.net/qq_43560721/article/details/104653470

2. [スタート]書き込みシンプルhelloWord

新しいコントローラを作成します。

package com.example.officialwebsite.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController{
    @RequestMapping("/hello")
    public String hello(){
        return "hello word spring boot!";
    }
}

スキャンパッケージを追加するための注意起動クラス

package com.example.officialwebsite;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan("com.example.officialwebsite.*")
public class OfficialwebsiteApplication {

    public static void main(String[] args) {
        SpringApplication.run(OfficialwebsiteApplication.class, args);
        System.out.println("哈哈*=*");

    }

}

3.プロジェクトを実行

:ブラウザを入力HTTP:// localhostを:8888 /こんにちは

 

 

+ = @Controller @ResponseBody @RestController
@RequestMapping:アドレスマッピング処理のコメントの要求は、クラスやメソッドのために使用することができます。GetMapping、PostMapping、PutMapping、DeleteMapping、また書くことができる PatchMapping

 

@SpringBootApplication =(デフォルトプロパティ)@Configuration + @EnableAutoConfiguration + @ComponentScan。

@Configurationアノテーションを識別するクラスタイプは、ソース春のIoCコンテナのビーン定義として使用することができます。@Bean注釈は@Bean注釈方法で、スプリングを指示Springアプリケーションコンテキストでビーンとして登録されなければならないオブジェクトを返します。

@EnableAutoConfiguration:、Beanクラスをあなたが望むものを推測して設定しようとすると、通常は自動的にクラスパスとあなたのBean定義に基づいて自動的に自動的に構成し、コンテキスト春に構成することができます。

@ComponentScan:自動的@Componentクラスでマークされ、コントローラ@、リポジトリ@、サービス@ @Componentノートの下にサブを含め、当然のことながら、Beanとして登録されたパッケージの下に指定されたすべてをスキャンします。

 

 

公開された141元の記事 ウォン称賛33 ビュー50000 +

おすすめ

転載: blog.csdn.net/qq_43560721/article/details/104669851
おすすめ