Spring Boot Serial 1:springアプリケーションの構築


一:Spring Boot概要
  Spring BootはSpringフレームの新しいサブプロジェクトで、Spring 4.0プロジェクトを作成するために使用されています。Springの様々なコンポーネントを自動的に配置して、コード生成とXMLプロファイルに依存していません。Spring Bootは、一般的なシーンに対する推奨コンポーネント構成も提供する。Spring BootはSpringフレームを使用した場合の開発効率を大幅に向上させることができます。
二:Spring Boot応用
  Spring Bootを通じて、新しいSpringアプリケーションを作成するのは非常に容易になり、また作成したSpringアプリケーションは通用する最適な実践に適合しています。次に、簡単な例を通してSpring Bootの応用について説明します。
1、pom.xmlファイル:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>myproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.5.RELEASE</version>
    </parent>

    <!-- Add typical dependencies for a web application -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <!-- Package as an executable jar -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>
2、アプリケーションを実行するjavaクラス:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
public class Application {
	  @RequestMapping("/")
	    String home() {
	        return "Hello World!";
	    }

	    public static void main(String[] args) throws Exception {
	        SpringApplication.run(Application.class, args);
	    }

}
3、起動プログラム:
  直接Application.javaを実行します。
4、アクセスアプリケーション:
  http://localhost:8080
  ページ出力ハローワールド!