1.什么是SpringBoot
Spring從開始繁雜的XML配置,每個Bean都是一個標簽洽洁,每個組件之間的關(guān)系都是基于xml痘系,感覺開發(fā)個功能一半的時間都在配xml,到后來加入了Annotation注解饿自,免除了大部分xml配置汰翠,但是如同 component scan/annotation-driven等還是需要配置xml。然而SpringBoot就內(nèi)置了絕大部分的常規(guī)配置昭雌,讓一個程序能最快的在Spring下跑起來复唤。
2.對開發(fā)環(huán)境的要求
推薦 IDE+Maven
3.一個HelloWorld程序
3.1新建一個Maven工程
3.2pom加入官方推薦的SpringBoot parent,以及mvc與aop(暫時用不上)所需的web
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<dependencies>
<!-- 對mvc aop的支持 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependencies>
3.3 新建一個App類,嗯烛卧,就可以跑了
@RestController
@SpringBootApplication
public class App {
@RequestMapping("/")
public String hello(){
return "Hello world!";
}
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
此處注意一點佛纫,RestController注解返回的都是JSON字符串數(shù)據(jù),也可以直接寫RESTFul的接口总放,等于給每一個方法都增加了ResponseBody注解呈宇。
其中@SpringBootApplication申明讓spring boot自動給程序進行必要的配置,等價于以默認屬性使用@Configuration局雄,@EnableAutoConfiguration和@ComponentScan甥啄。也就是這個注解極大減輕了xml配置。
訪問你的localhost:8080/看看吧炬搭!