1.SpringBoot的特点
为基于Spring的开发提供更快的入门体验
开箱即用,没有代码生成,也无需XML配置。同时也可以修改默认值来满足特定的需求
提供了一些大型项目中常见的非功能性特性,如嵌入式服务器、安全、指标,健康检测、外部配置等
SpringBoot不是对Spring功能上的增强,而是提供了一种快速使用Spring的方式
2.SpringBoot的核心功能
起步依赖
起步依赖本质上是一个Maven项目对象模型(Project Object Model,POM),定义了对其他库的传递依赖,这些东西加在一起即支持某项功能。简单的说,起步依赖就是将具备某种功能的坐标打包到一起,并提供一些默认的功能。
自动配置
Spring Boot的自动配置是一个运行时(更准确地说,是应用程序启动时)的过程,考虑了众多因素,才决定Spring配置应该用哪个,不该用哪个。该过程是Spring自动完成的。
3.代码实现
1>创建Maven工程并且 添加SpringBoot的起步依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
2>SpringBoot要集成SpringMVC进行Controller的开发,所以项目要导入web的启动依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--alibaba数据库连接驱动-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.6</version>
</dependency>
<!--@Data自动生成gen set方法坐标-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
需要安装插件:

4 编写SpringBoot引导类
要通过SpringBoot提供的引导类起步SpringBoot才可以进行访问
@SpringBootApplication
//申明当前类是一个配置类
public class BootDemoApplication {
public static void main(String[] args) {
SpringApplication.run(BootDemoApplication.class, args);
}
}
5编写SpringBoot引导类要通过SpringBoot提供的引导类起步SpringBoot才可以进行访问2.1.4 编写Controlle
@RestController
//@RestController 可以返回json但无法使用配置的视图解析器
public class HeloController {
@Autowired
private DataSource dataSource;
//@GetMapping 等同于@RequestMapping(value = "/hello",method = RequestMethod.GET)
@GetMapping("hello")
public String hello() {
return "hello spring-Boot";
}
}
6测试
1>运行
2>访问
原文:https://www.cnblogs.com/asndxj/p/11443282.html