目录
特别注意:
组件版本关系
毕业版本依赖关系(推荐使用)?
基础环境准备
Nacos 服务注册与发现
安装 Nacos
先关闭本机mysql
启动临时容器
用mysql客户端连接你的容器,然后导入nacos的数据表
服务器开启端口
本机开启端口
?启动nacos
测试nacos
?微服务框架搭建
????????创建父工程
创建子模块
配置XML
配置yaml文件
?Mysql导入数据库
CodeGenerator 模板生成器
?运行
成功之后会生成:
?Account账户类Controller类中写上测试方法
User项目下创建feign目录以及feign接口
?User子项目下创建启动类application类
user-service controller 添加一个测试接口
?运行测试能否获得数据
特别注意:
Spring Cloud Alibaba 项目都是基于 Spring Cloud,而 Spring Cloud 项目又是基于 Spring Boot 进行开发,所以三者之间的版本关系特别重要,一旦选错版本,项目就没法运行
版本说明 遵循这个官方的版本说明解决版本冲突的问题(课件下面的版本仅供参考)
组件版本关系
Spring Cloud Alibaba Version | Sentinel Version | Nacos Version | RocketMQ Version | Dubbo Version | Seata Version | 2.2.6.RELEASE | 1.8.1 | 1.4.2 | 4.4.0 | 2.7.8 | 1.3.0 | 2021.1 or 2.2.5.RELEASE or 2.1.4.RELEASE or 2.0.4.RELEASE | 1.8.0 | 1.4.1 | 4.4.0 | 2.7.8 | 1.3.0 | 2.2.3.RELEASE or 2.1.3.RELEASE or 2.0.3.RELEASE | 1.8.0 | 1.3.3 | 4.4.0 | 2.7.8 | 1.3.0 | 2.2.1.RELEASE or 2.1.2.RELEASE or 2.0.2.RELEASE | 1.7.1 | 1.2.1 | 4.4.0 | 2.7.6 | 1.2.0 | 2.2.0.RELEASE | 1.7.1 | 1.1.4 | 4.4.0 | 2.7.4.1 | 1.0.0 | 2.1.1.RELEASE or 2.0.1.RELEASE or 1.5.1.RELEASE | 1.7.0 | 1.1.4 | 4.4.0 | 2.7.3 | 0.9.0 | 2.1.0.RELEASE or 2.0.0.RELEASE or 1.5.0.RELEASE | 1.6.3 | 1.1.1 | 4.4.0 | 2.7.3 | 0.7.1 |
毕业版本依赖关系(推荐使用)?
Spring Cloud Version | Spring Cloud Alibaba Version | Spring Boot Version | Spring Cloud 2020.0.1 | 2021.1 | 2.4.2 | Spring Cloud Hoxton.SR9 | 2.2.6.RELEASE | 2.3.2.RELEASE | Spring Cloud Greenwich.SR6 | 2.1.4.RELEASE | 2.1.13.RELEASE | Spring Cloud Hoxton.SR3 | 2.2.1.RELEASE | 2.2.5.RELEASE | Spring Cloud Hoxton.RELEASE | 2.2.0.RELEASE | 2.2.X.RELEASE | Spring Cloud Greenwich | 2.1.2.RELEASE | 2.1.X.RELEASE | Spring Cloud Finchley | 2.0.4.RELEASE(停止维护,建议升级) | 2.0.X.RELEASE | Spring Cloud Edgware | 1.5.1.RELEASE(停止维护,建议升级) | 1.5.X.RELEASE |
?
基础环境准备
根据版本说明中的推荐,我们这里选择SpringBoot的版本为2.4.2,SpringCloud Alibaba的版本则为2021.1,组件对应关系如下
内容主要基于三个微服务:用户服务AccountService,订单服务OrderService,产品服务ProductService
用到的组件有:
- 注册中心、配置中心 Nacos
- 限流 Sentinel
- 分布式事务 Seata
- 网关 SpringCloud Gateway
- 认证授权 Spring Cloud Oauth2
- docker、docker-compose
由于用到的组件相对较多,部署会很繁琐,最关键的是没有资源服务器,所以在开发过程中我会逐渐将一些组件使用docker-compose部署
本篇内容就是使用Dokcer-compose部署Nacos,Sentinel,MySQL,作为后面的文章的基础环境
?
Nacos 服务注册与发现
安装 Nacos
docker pull nacos/nacos-server:1.4.1
由于nacos需要依赖于MySQL作为资源存储,所以在编写完整docker-compose之前我会先用docker启动临时的mysql容器,然后准备好nacos需要的数据库
容器化MySQL
先关闭本机mysql
docker rm -f $(docker ps -qa)
docker run --rm --name mysql -e MYSQL_ROOT_PASSWORD=123456 -v /app/cloud/mysql/data:/var/lib/mysql -p 3306:3306 -d mysql:5.7
此处需要挂载宿主机目录,在启动docker-compse后就不需要再次初识化数据。
-
用mysql客户端连接你的容器,然后导入nacos的数据表
nacos/nacos-mysql.sql at develop · alibaba/nacos · GitHub
服务器开启端口
本机开启端口
# 这里尽量开放一下服务器的端口
查看防火墙状态:
systemctl status firewalld
systemctl stop firewalld
systemctl start firewalld
开启端口:
firewall-cmd --zone=public --add-port=3306/tcp --permanent
查询端口号8080是否开启:
firewall-cmd --query-port=3306/tcp
重启防火墙:
firewall-cmd --reload
查询有哪些端口是开启的:
firewall-cmd --list-port
?启动nacos
docker-compose up -d nacos
?
测试nacos
? ? ? ? 进入网页
? ? ? ? ?配置文件
?发布
?
?查看数据库是否有该条数据
?
?微服务框架搭建
????????创建父工程
????????项目昵称:spring-cloud-alibaba
??????? pom.xml配置??删除? .dea 与 src 文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>springcloudalibaba</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>user-service</module>
<module>account-service</module>
<module>record-service</module>
<module>common-service</module>
</modules>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8 </maven.compiler.target>
<java.version>1.8</java.version>
<!--springcloud版本-->
<springcloud-version>2020.0.1</springcloud-version>
<!--springcloudalibaba-版本-->
<springcloud-alibaba-version>2021.1</springcloud-alibaba-version>
<!--mybatis-plus的版本-->
<mp-version>3.5.1</mp-version>
<!--mysql的版本-->
<mysql-version>8.0.13</mysql-version>
<!--mybatis-plus代码生成器-->
<mp-generator>3.5.2</mp-generator>
<!--mybatis-plus模板生成器-->
<mp-velocity>2.3</mp-velocity>
<!--接口文档版本-->
<knife4j-version>2.0.7</knife4j-version>
</properties>
<!--springboot的版本-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
</parent>
<dependencyManagement>
<dependencies>
<!--spring-cloud-alibaba的依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${springcloud-alibaba-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring-cloud的依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${springcloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mp-version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>${mp-generator}</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>${mp-velocity}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j-version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
创建子模块
在你的父工程中建立多个模块的Maven项目
公共CommonService
账户服务AccountService
账单服务RecordService
用户服务UserService
?
配置XML
CommonService
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springcloudalibaba</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>common-service</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
其他子项目全部引用common.service
<dependency>
<groupId>org.example</groupId>
<artifactId>common-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!--nacos注册中心 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
配置yaml文件
在每个子项目resources建立application.yaml文件,配置如下
spring:
application:
name: user-service #子项目名称
cloud:
nacos:
discovery:
server-addr: 106.52.242.189 #自己的服务器
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://106.52.242.189:3306/bank?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 123456
server:
port: 8181 #随便取但是每个子项目的要不一样
mybatis-plus:
mapper-locations: classpath*:/mapper/*Mapper.xml
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
type-aliases-package: com.qiu.common.entity #自己的目录
?
?Mysql导入数据库
/*
Navicat Premium Data Transfer
Source Server : localhost
Source Server Type : MySQL
Source Server Version : 80013
Source Host : localhost:3306
Source Schema : onlinebank
Target Server Type : MySQL
Target Server Version : 80013
File Encoding : 65001
Date: 15/06/2022 16:09:13
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for account
-- ----------------------------
DROP TABLE IF EXISTS `account`;
CREATE TABLE `account` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`card_no` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`password` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`balance` int(6) NULL DEFAULT NULL,
`status` int(11) NULL DEFAULT NULL,
`user_id` int(11) NULL DEFAULT NULL COMMENT '关联用户的id',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of account
-- ----------------------------
INSERT INTO `account` VALUES (1, '1', '110', 300, 1, 1);
INSERT INTO `account` VALUES (2, '2', '123456', 300, 1, 1);
INSERT INTO `account` VALUES (3, '3', '123123', 300, 0, 1);
INSERT INTO `account` VALUES (4, '4', '456456', 200, 0, 1);
-- ----------------------------
-- Table structure for transaction_record
-- ----------------------------
DROP TABLE IF EXISTS `transaction_record`;
CREATE TABLE `transaction_record` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`card_no` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`transaction_date` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`amout` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`balance` int(19) NULL DEFAULT NULL,
`transaction_type` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`remark` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 27 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of transaction_record
-- ----------------------------
INSERT INTO `transaction_record` VALUES (22, '1', '2021-11-08', '100', 500, '取款', '备注1');
INSERT INTO `transaction_record` VALUES (23, '2', '2021-11-08', '100', 200, '存款', '备注1');
INSERT INTO `transaction_record` VALUES (24, '1', '2021-11-08', '100', 400, '取款', '备注1');
INSERT INTO `transaction_record` VALUES (25, '3', '2021-11-08', '100', 300, '存款', '备注1');
INSERT INTO `transaction_record` VALUES (26, '1', '2022-04-19', '100', 300, '取款', '转账给2账户100');
INSERT INTO `transaction_record` VALUES (27, '2', '2022-04-19', '100', 300, '存款', '收到1账户转账100');
-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '编号',
`username` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户名',
`phone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '手机号',
`create_time` datetime(0) NOT NULL COMMENT '创建时间',
`update_time` datetime(0) NOT NULL COMMENT '修改时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of user
-- ----------------------------
INSERT INTO `user` VALUES (1, 'ange', '17670753912', '2022-06-15 15:43:57', '2022-06-15 15:43:59');
SET FOREIGN_KEY_CHECKS = 1;
CodeGenerator 模板生成器
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.fill.Column;
import com.baomidou.mybatisplus.generator.fill.Property;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/**
* @program: spring-cloud-alibaba
* @description: 代码生成器
* @author: Mr.Kuang
* @create: 2022-05-18 10:14
**/
public class CodeGenerator {
public static void main(String[] args) {
/*数据库配置*/
DataSourceConfig dataSourceConfig =
new DataSourceConfig
.Builder("jdbc:mysql://112.74.102.54:3306/onlinebank?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true","root","")
.dbQuery(new MySqlQuery())
.build();
/*创建一共代码生成器对象*/
AutoGenerator generator = new AutoGenerator(dataSourceConfig);
//String property = System.getProperty(scanner("请输入项目路径"));
/*全局配置*/
GlobalConfig globalConfig = new GlobalConfig.Builder()
.fileOverride()
.outputDir(scanner("请输入你的项目路径") + "/src/main/java")
.author("HaiGee").disableOpenDir()
//.enableKotlin()
//.enableSwagger()
.dateType(DateType.TIME_PACK)
.commentDate("yyyy-MM-dd")
.build();
generator.global(globalConfig);
/*包配置(PackageConfig)*/
PackageConfig packageConfig = new PackageConfig.Builder()
.parent("com.kuang.common")
//.moduleName("blog")
.entity("entity")
.service("service")
.serviceImpl("service.impl")
.mapper("mapper")
.xml("mapper")
.controller("controller")
//.other("other")
//.pathInfo(Collections.singletonMap(OutputFile.mapper, "D://"))
//.pathInfo(Collections.singletonMap(OutputFile.xml, "D://"))
.build();
generator.packageInfo(packageConfig);
TemplateConfig templateConfig = new TemplateConfig.Builder()
.disable(TemplateType.ENTITY)
.entity("/templates/entity.java")
.service("/templates/service.java")
.serviceImpl("/templates/serviceImpl.java")
.mapper("/templates/mapper.java")
.xml("/templates/mapper.xml")
.controller("/templates/controller.java")
.build();
generator.template(templateConfig);
/*策略配置*/
StrategyConfig strategyConfig = new StrategyConfig.Builder()
.enableCapitalMode()
.enableSkipView()
.disableSqlFilter()
//.likeTable(new LikeTable("USER"))
.addInclude(getTables(scanner("请输入表名,多个英文逗号分隔?所有输入 all")))
.addTablePrefix("transaction_")
//.addFieldSuffix("_flag")
/* .entityBuilder()
.controllerBuilder()
.mapperBuilder()
.serviceBuilder()*/
.build();
strategyConfig.entityBuilder()
//.superClass(BaseEntity.class)
.disableSerialVersionUID()
.enableChainModel()
.enableLombok()
.enableRemoveIsPrefix()
.enableTableFieldAnnotation()
.enableActiveRecord()
.versionColumnName("version")
.versionPropertyName("version")
.logicDeleteColumnName("deleted")
.logicDeletePropertyName("deleted")
.naming(NamingStrategy.underline_to_camel)
.columnNaming(NamingStrategy.underline_to_camel)
//.addSuperEntityColumns("id", "created_by", "created_time", "updated_by", "updated_time")
//.addIgnoreColumns("age")
.addTableFills(new Column("create_time", FieldFill.INSERT))
.addTableFills(new Property("update_time", FieldFill.INSERT_UPDATE))
.idType(IdType.AUTO)
.formatFileName("%s")
.build();
strategyConfig.controllerBuilder()
//.superClass(BaseController.class)
//.enableHyphenStyle()
.enableRestStyle()
.formatFileName("%sController")
.build();
strategyConfig.serviceBuilder()
//.superServiceClass(BaseService.class)
// .superServiceImplClass(BaseServiceImpl.class)
.formatServiceFileName("%sService")
.formatServiceImplFileName("%sServiceImp")
.build();
strategyConfig
.mapperBuilder()
.superClass(BaseMapper.class)
//.enableMapperAnnotation()
//.enableBaseResultMap()
//.enableBaseColumnList()
//.cache(MyMapperCache.class)
.formatMapperFileName("%sMapper")
.formatXmlFileName("%sMapper")
.build();
generator.strategy(strategyConfig);
/*执行代码生成器*/
generator.execute();
}
// 处理 all 情况
protected static List<String> getTables(String tables) {
return "all".equals(tables) ? Collections.emptyList() : Arrays.asList(tables.split(","));
}
/**
* <p>
* 读取控制台内容
* </p>
*/
public static String scanner(String tip) {
Scanner scanner = new Scanner(System.in);
StringBuilder help = new StringBuilder();
help.append("请输入" + tip + ":");
System.out.println(help.toString());
if (scanner.hasNext()) {
String ipt = scanner.next();
if (StringUtils.isNotBlank(ipt)) {
return ipt;
}
}
throw new MybatisPlusException("请输入正确的" + tip + "!");
}
}
?运行
路径输入自己的?
?
成功之后会生成:
entity? service? mapper? controller
四个包,把里面对应的文件放置到对应的子项目下,此处需要自己手动在子项目处建立以上四个包,完成效果去下
?Account账户类Controller类中写上测试方法
/**
* <p>
* 前端控制器
* </p>
*
* @author qiugetee
* @since 2022-06-16
*/
@RestController
@RequestMapping("/account")
public class AccountController {
@Autowired
private AccountService accountService;
@Value("${server.port}")
private String port;
@GetMapping("/getAccountList")
public Result getAccountList(){
List<Account> list=accountService.list();
return Result.ok().data("list",list);
}
@GetMapping("/getAccountByUserId/{id}")
public Result getAccountByUserId(@PathVariable("id") Integer id){
LambdaQueryWrapper<Account> wrapper=new LambdaQueryWrapper<>();
wrapper.eq(Account::getUser_id,id);
List<Account> account=accountService.list(wrapper);
return Result.ok().data("account",account).data("port",port);
}
?
User项目下创建feign目录以及feign接口
/**
* 功能描述: <br>
* 〈用户调用账单的远程服务〉
* @Param:
* @Return:
* @Author: Mr.Qiu
* @Date:
*/
@FeignClient("account-service")
public interface AccountFeign {
@GetMapping("/account/getAccountByUserId/{id}")
Result getAccountByUserId(@PathVariable("id") Integer id);
}
?
?User子项目下创建启动类application类
package com.qiu.user;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* 功能描述: <br>
* 〈用户启动器类〉
* @Param:
* @Return:
* @Author: Mr.Qiu
* @Date:
*/
//开启feign的远程调用服务
@EnableFeignClients
@SpringBootApplication
@EnableDiscoveryClient
@MapperScan("com.qiu.user.mapper")
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class,args);
}
}
?
user-service controller 添加一个测试接口
/**
* <p>
* 前端控制器
* </p>
*
* @author qiugetee
* @since 2022-06-16
*/
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private AccountFeign accountFeign;
@GetMapping("/getUserList")
public List<User> getUserList(){
List<User> users = userService.list();
System.out.println(users.size());
return users;
}
@GetMapping("/getAccountByUserId/{id}")
public Result getAccountByUserId(@PathVariable("id") Integer id){
Result result=accountFeign.getAccountByUserId(id);
return result;
}
}
?
?运行测试能否获得数据
数据访问成功?
?
查看nacos
?
?
?
?
|