springboot是什么_什么是SpringBoot以及怎样快速开始?

什么是SpringBoot?

eb29184bac5624c68e6166b5cd67316f.png

我们以前开发的项目是基于单体架构的。单体架构使用的技术

(1) jsp/sevlet

(2) spring + struts + hibernate

(3) springmvc + mybatis

后面我们会慢慢拆分:

717bcf54d76c32945382aba94bf7b89f.png

基于分布式架构我们可以使用

(1) Http:Springmvc + mybatis

(2) RPC: Dubbo + Spring

(3) 微服务框架:SpringBoot:构建微服务项目。可以快速构建一个web应用,本质上是对Spring的封装,可以简化我们的配置。

1eee842b2f11069fe7c175082b0a161f.png

上面是微服务架构,就是把一组小的服务互相协调、互相配合。并且完成功能。每个服务运行在其独立的进程中,服务与服务之间采用轻量级的通信机制互相协作(通常是基于HTTP协议的RESTfulAPI)。每个服务都围绕着具体业务进行构建,并且能够被独立的部署到生产环境中。

SpringBoot快速开始

第一种:创建一个空的maven项目,然后导入SpringBoot相关的jar包

① 父工程依赖:

org.springframework.bootspring-boot-starter-parent2.0.8.RELEASE

② Spring mvc-web依赖

org.springframework.bootspring-boot-starter-web

③ 引入Spring Boot插件,可以支持我们将web应用程序打包可运行jar

org.springframework.bootspring-boot-maven-plugin

④ 编写程序入口:

@SpringBootApplicationpublic class HelloWorldApplication {    public static void main( String[] args ) {        SpringApplication.run(HelloWorldApplication.class,args);    }}

⑤ 编写Controller

@RestControllerpublic class HelloWorldController {    @RequestMapping("/hello")    public String hello(){        return  "Hello world";    }}

注意:自己写的组件必须放在主启动的 所在的包或者其子包下,如果不遵守这个规则,则可以自定义加载:使用@ComponentScan指定。

⑥运行main函数运行程序,访问http://localhost:8080/hello,或者执行mvc package将项目打成jar包,用java -jar xxx.jar直接运行。

c8502fa5c82daf01fb25930318dd4e9f.png

第二种:通过idea创建一个SpringBoot项目

69b35d75359d9980dcf33dc390b8bca6.png
b30c71941b5e7a93aaf47f5ac5c83966.png

下面就是编写自己的 业务,和上面一样。

为什么我只需要引用Spring-boot-starter-parent 和 spring-boot-starter-web就可以快速开发mvc的项目

我们看一下我们引用的 Spring-boot-starter-parent

真正起作用的是:

 org.springframework.boot        spring-boot-dependencies        2.0.8.RELEASE../../spring-boot-dependencies

再点击进去,我们就会看到版本依赖:

da1c6f1124734ee1693355a3c83436b6.png
5aba036a8333a2cb729c55b1a0f166b2.png

我们常用的依赖都在上面。

我们在分析spring-boot-starter-web引入了什么jar包

org.springframework.boot      spring-boot-starter      2.0.8.RELEASEcompileorg.springframework.boot      spring-boot-starter-json      2.0.8.RELEASEcompileorg.springframework.boot      spring-boot-starter-tomcat      2.0.8.RELEASEcompileorg.hibernate.validator      hibernate-validator      6.0.14.Finalcompileorg.springframework      spring-web      5.0.12.RELEASEcompileorg.springframework      spring-webmvc      5.0.12.RELEASEcompile

从上面可以看到,spring-boot-starter-web 自动为 我们引入了Spring-web,Spring-webmvc和相关的校验,还有tomcat。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值