快速構建一個 Springboot
阿新 • • 發佈:2017-07-07
pan -1 conf tomcat one feature 添加 自動配置 span
快速構建一個 Springboot
官網:http://projects.spring.io/spring-boot/
Spring Boot可以輕松創建可以“運行”的獨立的,生產級的基於Spring的應用程序。我們對Spring平臺和第三方圖書館有一個看法,所以你可以從最開始的時候開始吧。大多數Spring Boot應用程序需要很少的Spring配置。
特征
- 創建獨立的Spring應用程序
- 直接嵌入Tomcat,Jetty或Undertow(不需要部署WAR文件)
- 提供有意思的“啟動”POM來簡化您的Maven配置
- 盡可能自動配置彈簧
- 提供生產就緒功能,如指標,運行狀況檢查和外部化配置
- 絕對沒有代碼生成
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方法運行
快速構建一個 Springboot