Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者的。
最好的文档来源自官方的《Spring Boot Reference Guide》,是这样介绍的:
Spring Boot makes it easy to create stand-alone,
production-grade Spring based Applications that you can
“just run”...Most Spring Boot applications need very little Spring configuration.
在以前的spring项目中,都会面对大量繁琐的配置。而Spring Boot 则能让我们在不需要过多的配置下,轻松快速地搭建Spring Web应用,开箱即用,只要通过just run(可能是 java -jar 或 tomcat 或 maven插件run 或 shell脚本),就可以启动项目,没有代码生成,需很少的XML配置,从而快速使用spring框架。
因为“习惯优先于配置”的原则,使得Spring Boot在快速开发应用和微服务架构实践中得到广泛应用!
开发一个简单的Spring Boot应用
(1) 创建webMaven工程(注意:Application启动类放在com.hlx.springboot)
(2)在pom.xml中添加相应的包
<!-- Spring Boot 启动父依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<dependencies>
<!-- Spring Boot web依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.3.3.RELEASE</version>
</dependency>
<!-- Junit单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
(3)编写Control类
/**
* Spring Boot
* @author Administrator
*
*/
@RestController
public class HelloController {
@RequestMapping("/") //访问根目录
public String show() throws Exception{
return "this is Spring-boot Test!";
}
}
@SpringBootApplication
public class Application {
public static void main(String[] args) {
// 程序启动入口
// 启动嵌入式的Tomcat并初始化Spring环境及其各Spring组件
SpringApplication.run(Application.class, args);
}
}
(5)编写测试类(忽略)
(6)启动应用类
查看Tomcat已启动
在IE浏览器查看
GitHub: https://github.com/yuanhangs/myrepository