核心!
场景starter - xxxxAutoConfiguration - 导入xxx组件 - 绑定xxxProperties – 绑定配置文件项
开始
内嵌服务器?springboot优势初体验!
- 创建maven工厂,pom中添加依赖
- 编写main函数,类上标明@SpringBootApplication
- Controller层 使用@RestController注解
- 在resource目录下创建配置文件application.properties
- 使用maven进行打包,通过命令行手动部署在Tomcat服务器中。cmd命令窗口下输入:
java -jar springboot-1.0-SNAPSHOT.jar
springboot依赖管理与版本仲裁
之所以只引入一个spring-boot-starter-parent这个jar包,在spring-boot-dependencies中springboot当前版本自动为开发者实现jar包导入管理。若开发者向更改当前依赖jar包版本号,只需在pom文件中就近原则声明properties自定义修改版本号,实现版本仲裁。
包扫描
使用@SpringBootApplication(scanBasePackages=“com.lwt”)或者不使用前者(前者包含后者)使用@ComponentScan
自动配置原理
spring-boot-starter-web-2.3.4.RELEASE.pom到spring-boot-starter-2.3.4.RELEASE.pom到spring-boot-autoconfigure-2.3.4.RELEASE.pom
前期简单总结
- 引入依赖
- 查看自动配置 debug=true Negative/Positive
- application.properties配置参照
https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#common-application-properties 官网。
开发技巧
- lombok @Data
- dev-tools
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
- spring-Initailizr 初始化向导,返璞归真。