Spring Boot是由Pivotal團隊提供的全新架構,其設計目的是用來簡化新Spring應用的初始搭建以及開發過程。Spring Boot 緻力于提供一種開箱即用的開發環境,進而提高開發效率。多年以來,Spring IO平台飽受非議的一點就是大量的XML配置以及複雜的依賴管理。Pivotal團隊開發Spring Boot的目标之一就是實作免XML配置。然而從Spring Boot目前效果來看,其功能遠遠超出了最初的目的。
話不多說,直接開始Boot的第一個Holle Word。在這裡使用Maven建構,你也可以直接将Boot的依賴包放到項目中。
1、建立maven工程
2、将在pom檔案中加入spring boot的依賴
`<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.6.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>`
3、建立一個測試類内容如下
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);
}
}
4、運作你的項目,通路http://127.0.0.1:8080即可。
至此spring bootHolle world完畢!關于啟動項目有多種方法,下篇文章中再進行細說!
參考資料spring官網https://docs.spring.io/spring-boot/