电影网站开发开题报告,沪上家居装修官网,有没有学做蛋糕的网站和视频,wordpress爬虫采集一、服务架构比较 单体架构#xff1a;简单方便#xff0c;高度耦合#xff0c;扩展性差#xff0c;适合小型项目。例如#xff1a;学生管理系统 分布式架构#xff1a;松耦合#xff0c;扩展性好#xff0c;但架构复杂#xff0c;难度大。适合大型互联网项目#x…一、服务架构比较 单体架构简单方便高度耦合扩展性差适合小型项目。例如学生管理系统 分布式架构松耦合扩展性好但架构复杂难度大。适合大型互联网项目例如京东、淘宝 微服务一种良好的分布式架构方案 ①优点拆分粒度更小、服务更独立、耦合度更低 ②缺点架构非常复杂运维、监控、部署难度提高 SpringCloud是微服务架构的一站式解决方案集成了各种优秀微服务功能组件
二、服务拆分原则 不同微服务不要重复开发相同业务 微服务数据独立不要访问其它微服务的数据库 微服务可以将自己的业务暴露为接口供其它微服务调用
三、实现远程调用
3.3.1 案例分析
修改order-service中的根据id查询订单业务要求在查询订单的同时根据订单中包含的userId查询出用户信息一起返回。 3.3.2 注册RestTemplate 首先我们在order-service服务中的OrderApplication启动类中注册RestTemplate实例
package cn.itcast.order;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;MapperScan(cn.itcast.order.mapper)
SpringBootApplication
public class OrderApplication {public static void main(String[] args) {SpringApplication.run(OrderApplication.class, args);}Beanpublic RestTemplate restTemplate() {return new RestTemplate();}
}
3.3.3 修改服务
修改order-service服务中的cn.itcast.order.service包下的OrderService类中的queryOrderById方法
package cn.itcast.order.service;import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;Service
public class OrderService {Autowiredprivate OrderMapper orderMapper;Autowiredprivate RestTemplate restTemplate;public Order queryOrderById(Long orderId) {// 1.查询订单Order order orderMapper.findById(orderId);//2.利用RestTemplate发起http请求查询用户String url http://localhost:8081/user/order.getUserId();User user restTemplate.getForObject(url, User.class); //自动反序列化//封装user到Orderorder.setUser(user);//4.返回return order;}
}