SpringBoot框架Day01之核心与内嵌服务器HelloWorld和开发向导

核心!

场景starter - xxxxAutoConfiguration - 导入xxx组件 - 绑定xxxProperties – 绑定配置文件项

开始

内嵌服务器?springboot优势初体验!

  1. 创建maven工厂,pom中添加依赖
  2. 编写main函数,类上标明@SpringBootApplication
  3. Controller层 使用@RestController注解
  4. 在resource目录下创建配置文件application.properties
  5. 使用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

前期简单总结

  1. 引入依赖
  2. 查看自动配置 debug=true Negative/Positive
  3. application.properties配置参照
    https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#common-application-properties 官网。

开发技巧

  1. lombok @Data
  2. dev-tools
<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
  1. spring-Initailizr 初始化向导,返璞归真。

猜你喜欢

转载自blog.csdn.net/m0_47119598/article/details/113184147