spring boot致力於,幫助開發者快速構建spring應用。省略在繁瑣的文件配置。html
使用spring boot很容易建立相對獨立,適用於生產環境的spring應用。前端
建立相對獨立的spring 應用。java
嵌入tomcat,jetty,等應用服務器。而不須要生成war包。再部署到服務器。web
提供相對固定的基礎配置已經配置模板,從而簡化你的maven配置。spring
方便的spring自動化配置。tomcat
提供準生成環境的功能,如健康檢測。服務器
使用maven,或者gradle能夠很是方便的建立spring-boot入門應用。mvc
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.2.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
hello/SampleController.javaapp
package hello; 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("/") @ResponseBody String home() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(SampleController.class, args); } }
以上代碼當中,@Controller、 @RequestMapping、@ResponseBody都是spring mvc中常見的註解。其中Controller註解用於標記,該類是一個controller,@ResponseBody用於標記該方法返回值直接做爲處理結果返回給前端,而不須要去尋找試圖。這兩個註解可使用@RestController代替。
@EnableAutoConfiguration這個註解告訴spring根據classpath引入的包,即根據依賴關係來進行自動配置。因爲該工程是spring-boot-stater-web工程,默認添加了一些如tomcat,spring-web包等。所以spring會嘗試以spring-web工程來配置工程。maven