采用 nacos 做为配置中心及路由中心
所有配置文件都是从配置中心获取:
配置文件:nacos--->dev-->cloud-config.properties
公用组件
learn-cloud-common 获取配置中心配置文件,所有的learn-cloud-* 都要依赖
learn-shop-base-common 依赖learn-cloud-common,所有的learn-shop-admin-* 和learn-shop-core-* 都要依赖
learn-shop-base-pojo po和vo以及ex,所有的learn-shop-admin-* 和learn-shop-core-* 都要依赖
learn-shop-base-tools 公用工具
核心服务,端口:87**:
nacos 注册中心,分布式配置中心 端口:8761
learn-cloud-getaway 路由网关,端口:8771
seata 分布式事务管理中心,端口:8721
后端业务服务,端口:88**:
learn-shop-admin-user 用户管理服务,端口:8801
learn-shop-admin-system 系统管理服务,端口:8811
前台业务服务,端口:89**:
learn-shop-core-order 购物车服务,端口:8901
learn-shop-core-cart 购物车服务,端口:
learn-shop-core-product 购物车服务,端口:8911
learn-shop-core-search 搜索服务,端口:8981
learn-shop-core-seckill 秒杀服务,端口:8921
项目启动顺序:
- nacos
- seata
- learn-cloud-getaway
- 启动业务服务
访问:(通过路由)
注册中心、配置中心:
http://localhost:8761/nacos/index.html
用户名/密码:nacos/nacos
业务服务:
http://localhost:8771/core-order #订单相关
http://localhost:8771/admin-user #用户相关
RabbitMQ: 管理页面
http://localhost:15672
用户名/密码:admin/admin123
Druid: 管理页面
http://localhost:/druid
Swagger2: 管理页面
http://localhost:/swagger-ui.html(查看单个)
http://localhost:8771/swagger-ui.html(查看聚合)
或者进入注册中心点击实例链接直接查看
注意:
0.特别提醒:如果使用本地配置文件需要修改learn-cloud-config下的resources里面的application.yml的search-locations修改为本地路径
1.添加新服务时,要在learn-cloud-gateway中添加路由表
core-order:
path: /core-order/**
serviceId: learn-shop-core-order
2.使用配置中心时,
配置中心启动时会向注册中心注册,这里注册中心还没启动会报异常,不用关心
如果是learn-cloud-* pom中添加learn-cloud-common依赖
如果是learn-shop-admin-* 和learn-shop-core-* pom中添加learn-shop-base-common依赖
3.项目启动先要条件
- RabbitMQ, rabbitmq-server.bat
添加新用户:admin 密码:admin123,修改admin用为超级管理员
查询所有用户:rabbitmqctl.bat list_users
添加新用户: rabbitmqctl.bat add_user username password
赋予用户权限:rabbitmqctl.bat set_user_tags username administrator
在admin中设定虚拟主机(virtual-host)为/learn-default - redis启动
4.swagger2注解使用说明
- 注入 RedisTemplate 需要通过
@Resource
明确指定。因为两个使用的库不同,mybatis 默认使用的 15 号库。
// 正常设值的
@Resource
private RedisTemplate<String, Object> redisTemplate;
// mybatis 设置缓存
@Resource
protected RedisTemplate<String, Object> redisCacheTemplate;
HTTP Method 与 CURD 数据处理操作对应
POST Create 新增一个没有id的资源
GET Read 取得一个资源
PUT Update 更新一个资源。或新增一个含 id 资源(如果 id 不存在)
DELETE Delete 删除一个资源