SpringBoot初期チュートリアルのプロジェクト構造(一)
9797 ワード
SpringBoot初期チュートリアルのプロジェクト構造
1概要
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
Features Create stand-alone Spring applications Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files) Provide opinionated ‘starter’ POMs to simplify your Maven configuration Automatically configure Spring whenever possible Provide production-ready features such as metrics, health checks and externalized configuration Absolutely no code generation and no requirement for XML configuration
上記は公式の英語の説明で、大体翻訳した後は以下の通りです.
SpringBootは、本番中の独立したプログラムを構築する上で非常に簡単で、簡単な構成だけで実行できます.大体以下の特徴があります.独立Springアプリケーション を作成は、組み込まれたTomcat、Jetty or Undertowを使用できます.war を配備する必要はありません.は、maven構成 を簡略化するためにstarter pomを提供する.自動構成Spring は、metrics、health checks and externalized configuration などの生産環境の特性を提供する.コード生成およびXML構成要件 は絶対にありません.
2.クイックスタート
この統一はspring-boot-starter-parentをparentとしているので
次のプラグインはSpringbootを実行するために使用されます.通常、mainメソッドを直接実行する方法と、次のプラグインを使用して実行する方法の2つがあります.2つの方法には違いがあります.プロジェクトでリソースにアクセスする必要がある場合は、プラグインで実行する必要があります.そうしないと、リソースにアクセスできません.
上はmaven構成で、次にプログラム全体のエントリを構成する必要があります.
mainメソッドやプラグインを実行すれば、正常にアクセスできる簡単なcontrollerを以下に書きます.これは、controllerとApplicationが1つのパッケージの下に置かれていることに注意してください.次にスキャンされたパッケージを構成する必要がない場合は
3.構成の詳細
application.yamlファイルの詳細
application.yamlはアプリケーション全体のプロファイルであり、SpringBootは自動的にロードされ、SpringBootは様々なコンポーネントに対してアプリケーションを提供する.yamlは構成を行い,後で詳細に説明する.
1概要
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run”. We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
Features
上記は公式の英語の説明で、大体翻訳した後は以下の通りです.
SpringBootは、本番中の独立したプログラムを構築する上で非常に簡単で、簡単な構成だけで実行できます.大体以下の特徴があります.
2.クイックスタート
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>1.4.1.RELEASEversion>
parent>
<modelVersion>4.0.0modelVersion>
<artifactId>springboot-1artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<version>1.4.1.RELEASEversion>
plugin>
plugins>
build>
project>
この統一はspring-boot-starter-parentをparentとしているので
spring-boot-starter-web
はバージョン番号を記入する必要はありません
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>1.4.1.RELEASEversion>
parent>
次のプラグインはSpringbootを実行するために使用されます.通常、mainメソッドを直接実行する方法と、次のプラグインを使用して実行する方法の2つがあります.2つの方法には違いがあります.プロジェクトでリソースにアクセスする必要がある場合は、プラグインで実行する必要があります.そうしないと、リソースにアクセスできません.
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<version>1.4.1.RELEASEversion>
plugin>
上はmaven構成で、次にプログラム全体のエントリを構成する必要があります.
AppApplication
@SpringBootApplication
public class AppApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(AppApplication.class, args);
}
}
mainメソッドやプラグインを実行すれば、正常にアクセスできる簡単なcontrollerを以下に書きます.これは、controllerとApplicationが1つのパッケージの下に置かれていることに注意してください.次にスキャンされたパッケージを構成する必要がない場合は
@RestController
public class IndexController {
@GetMapping("/index")
public ResponseEntity helloWord() {
return ResponseEntity.ok("hello word");
}
}
3.構成の詳細
@SpringBootApplication
この注釈は組み合わせ注釈であり、複数の注釈の機能を集約し、具体的なソースコードは以下の通りである.
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class))
public @interface SpringBootApplication {
//
Class>[] exclude() default {};
// beanName
String[] excludeName() default {};
//
@AliasFor(annotation = ComponentScan.class, attribute = "basePackages")
String[] scanBasePackages() default {};
//
@AliasFor(annotation = ComponentScan.class, attribute = "basePackageClasses")
Class>[] scanBasePackageClasses() default {};
}
@EnableAutoConfiguration
この注記はSpringBootの自動構成項目を起動するために使用されます.この注記は追加する必要があります.そうしないと、SpringBootはデフォルトで多くの構成項目が構成されているため、下図に示すように構成項目が自動的に構成され、一部は他のjarパッケージ構成を参照する必要があります.application.yamlファイルの詳細
application.yamlはアプリケーション全体のプロファイルであり、SpringBootは自動的にロードされ、SpringBootは様々なコンポーネントに対してアプリケーションを提供する.yamlは構成を行い,後で詳細に説明する.