快速构建一个 Springboot

快速构建一个 Springboot 

官网:http://projects.spring.io/spring-boot/

Spring Boot可以轻松创建可以“运行”的独立的,生产级的基于Spring的应用程序。我们对Spring平台和第三方图书馆有一个看法,所以你可以从最开始的时候开始吧。大多数Spring Boot应用程序需要很少的Spring配置。

特征

  • 创建独立的Spring应用程序
  • 直接嵌入Tomcat,Jetty或Undertow(不需要部署WAR文件)
  • 提供有意思的“启动”POM来简化您的Maven配置
  • 尽可能自动配置弹簧
  • 提供生产就绪功能,如指标,运行状况检查和外部化配置
  • 绝对没有代码生成也不需要XML配置

1、在pom.xml中添加springboot相关依赖jar包

 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 2     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 3     <modelVersion>4.0.0</modelVersion>
 4 
 5     <groupId>com.wisezone</groupId>
 6     <artifactId>springboot</artifactId>
 7     <version>0.0.1-SNAPSHOT</version>
 8     <packaging>jar</packaging>
 9 
10     <name>springboot</name>
11     <url>http://maven.apache.org</url>
12 
13     <properties>
14         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15     </properties>
16 
17     <parent>
18         <groupId>org.springframework.boot</groupId>
19         <artifactId>spring-boot-starter-parent</artifactId>
20         <version>1.4.1.RELEASE</version>
21     </parent>
22 
23     <dependencies>
24         <dependency>
25             <groupId>org.springframework.boot</groupId>
26             <artifactId>spring-boot-starter-web</artifactId>
27         </dependency>
28     </dependencies>
29 
30     <build>
31         <plugins>
32             <plugin>
33                 <groupId>org.springframework.boot</groupId>
34                 <artifactId>spring-boot-maven-plugin</artifactId>
35             </plugin>
36         </plugins>
37     </build>
38 </project>

2、创建一个SampleController.java类

package com.wisezone.springboot;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;

@Controller
@EnableAutoConfiguration
public class SampleController
{
    @RequestMapping("/home")
    @ResponseBody
    String home() {
        return "Hello World!";
    }

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

Console:main方法运行

原文地址:https://www.cnblogs.com/wdh1995/p/7128888.html