更多内容,点击了解: https://how2j.cn/k/springcloud/springcloud-single/2036.html?p=81777
步骤 1 : 先运行,看到效果,再学习
老规矩,先下载下载区(点击进入)的可运行项目,配置运行起来,确认可用之后,再学习做了哪些步骤以达到这样的效果。
运行 ProductServiceApplication, 然后访问地址:
http://127.0.0.1:8080/products
就可以看到如图所示的效果了。
步骤 2 : 模仿和排错
在确保可运行项目能够正确无误地运行之后,再严格照着教程的步骤,对代码模仿一遍。
模仿过程难免代码有出入,导致无法得到期望的运行结果,此时此刻通过比较正确答案 ( 可运行项目 ) 和自己的代码,来定位问题所在。
采用这种方式,学习有效果,排错有效率,可以较为明显地提升学习速度,跨过学习路上的各个槛。
推荐使用diffmerge软件,进行文件夹比较。把你自己做的项目文件夹,和我的可运行项目文件夹进行比较。
这个软件很牛逼的,可以知道文件夹里哪两个文件不对,并且很明显地标记出来
这里提供了绿色安装和使用教程:diffmerge 下载和使用教程
步骤 3 : Springboot
关于 springboot 本身的学习, 如果不会,可以先去站长的 springboot 教程专区学习:Springboot入门
步骤 4 : pom.xml
springcloud 我们会使用 Finchley 这个版本,而它对 springboot 的版本依赖是 2.0.3.RELEASE, 所以我们会用 2.0.3.RELEASE 这个版本的 springboot 来撸。
|
步骤 5 : ProductServiceApplication
ProductServiceApplication 启动类, 这里使用代码指定端口的方式,免得有同学8080端口被占用了,自己都不知道,老是折磨自己~
|
步骤 6 : Product
实体类
|
步骤 7 : ProductService
服务类,这里直接在内存里提供数据了,免得大家配数据库配来配去,还配不对,影响学习。。。
|
步骤 8 : ProductController
控制器
|
步骤 9 : products.html
thymeleaf 文件, 用来遍历数据。 thymeleaf 不熟悉的同学,跳过去学习: thymeleaf 入门 基于 springboot 方式
|
步骤 10 : application.properties
springboot 配置信息,主要是 thymeleaf 的相关配置
|
步骤 11 : 单体结构
这个项目很简单,就做两件事: 1. 提供数据 2. 展示数据。 这就是一个典型的单体结构。
它把两个服务 提供数据和展示数据 放在了一起,这就会出现固有的缺点。
1. 如果要修改数据部分的代码, 那么必须把整个项目重新编译打包部署。 虽然展示部分,什么都没变但是也会因为重新部署而暂时不能使用,要部署完了,才能使用。
2. 如果提供数据部分出现了问题,比如有的开发人员改错了,抛出了异常,会导致整个项目不能使用,展示数据部分也因此受到影响。
3. 性能瓶颈难以突破
4. 等等。。。
以上就是单体结构的问题,接下来,站长就会带着大家,把这个单体结构的项目,改造成为springcloud 微服务分布式架构,通过观察和参与改造过程,就能够掌握和理解 springcloud啦。
更多内容,点击了解: https://how2j.cn/k/springcloud/springcloud-single/2036.html?p=81777