在微服务整合dubbo,以为微服务版的若依为例

在微服务整合dubbo,以为微服务版的若依为例

  • 一、环境
  • 二、整合过程
    • 1、父模块依赖
    • 2、生产者
    • 3、消费者
  • 三、修改若依的服务调用方式为dubbo
    • 1、改造系统模块
    • 2、改造认证授权中心
  • 四、整合过程遇到的问题
    • 1、出现循环引用
    • 2、出现依赖冲突
    • 3、启动出现端口号被占用
    • 4、出现某个类找不到
    • 5、找不到生产者

一、环境

微服务版若依3.6.3
dubbo2021.0.1
nacos2.2.1

二、整合过程

1、父模块依赖

<?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>com.ruoyi</groupId><artifactId>ruoyi</artifactId><version>3.6.3</version><name>human</name><url>http://www.ruoyi.vip</url><description>若依管理系统</description><properties><ruoyi.version>3.6.3</ruoyi.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-boot.version>2.7.13</spring-boot.version><spring-cloud.version>2021.0.8</spring-cloud.version><spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version><spring-boot-admin.version>2.7.10</spring-boot-admin.version><swagger.fox.version>3.0.0</swagger.fox.version><swagger.core.version>1.6.2</swagger.core.version><tobato.version>1.27.2</tobato.version><kaptcha.version>2.3.3</kaptcha.version><pagehelper.boot.version>1.4.7</pagehelper.boot.version><druid.version>1.2.16</druid.version><dynamic-ds.version>3.5.2</dynamic-ds.version><commons.io.version>2.11.0</commons.io.version><velocity.version>2.3</velocity.version><fastjson.version>2.0.34</fastjson.version><jjwt.version>0.9.1</jjwt.version><minio.version>8.2.2</minio.version><poi.version>4.1.2</poi.version><transmittable-thread-local.version>2.14.3</transmittable-thread-local.version><dubbo.version>2021.0.1.0</dubbo.version><hutool-all.version>5.8.16</hutool-all.version><lombok.version>1.18.24</lombok.version><minio.version>8.2.2</minio.version><guava.version>33.0.0-jre</guava.version></properties><!-- 依赖声明 --><dependencyManagement><dependencies><!-- SpringCloud 微服务 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><!-- SpringCloud Alibaba 微服务 --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>${spring-cloud-alibaba.version}</version><type>pom</type><scope>import</scope></dependency><!-- SpringBoot 依赖配置 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>${spring-boot.version}</version><type>pom</type><scope>import</scope></dependency><!-- FastDFS 分布式文件系统 --><dependency><groupId>com.github.tobato</groupId><artifactId>fastdfs-client</artifactId><version>${tobato.version}</version></dependency><!-- Swagger 依赖配置 --><dependency><groupId>io.swagger</groupId><artifactId>swagger-models</artifactId><version>${swagger.core.version}</version></dependency><dependency><groupId>io.swagger</groupId><artifactId>swagger-annotations</artifactId><version>${swagger.core.version}</version></dependency><!-- 验证码 --><dependency><groupId>pro.fessional</groupId><artifactId>kaptcha</artifactId><version>${kaptcha.version}</version></dependency><!-- pagehelper 分页插件 --><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper-spring-boot-starter</artifactId><version>${pagehelper.boot.version}</version></dependency><!-- io常用工具类 --><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>${commons.io.version}</version></dependency><!-- excel工具 --><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>${poi.version}</version></dependency><!-- 代码生成使用模板 --><dependency><groupId>org.apache.velocity</groupId><artifactId>velocity-engine-core</artifactId><version>${velocity.version}</version></dependency><!-- JSON 解析器和生成器 --><dependency><groupId>com.alibaba.fastjson2</groupId><artifactId>fastjson2</artifactId><version>${fastjson.version}</version></dependency><!-- JWT --><dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt</artifactId><version>${jjwt.version}</version></dependency><!-- 线程传递值 --><dependency><groupId>com.alibaba</groupId><artifactId>transmittable-thread-local</artifactId><version>${transmittable-thread-local.version}</version></dependency><!-- 核心模块 --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-core</artifactId><version>${ruoyi.version}</version></dependency><!-- 接口模块 --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-swagger</artifactId><version>${ruoyi.version}</version></dependency><!-- 安全模块 --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-security</artifactId><version>${ruoyi.version}</version></dependency><!-- 权限范围 --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-datascope</artifactId><version>${ruoyi.version}</version></dependency><!-- 多数据源 --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-datasource</artifactId><version>${ruoyi.version}</version></dependency><!-- 分布式事务 --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-seata</artifactId><version>${ruoyi.version}</version></dependency><!-- 日志记录 --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-log</artifactId><version>${ruoyi.version}</version></dependency><!-- 缓存服务 --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-redis</artifactId><version>${ruoyi.version}</version></dependency><!-- 系统接口 --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-api-system</artifactId><version>${ruoyi.version}</version></dependency><!-- Dubbo --><!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-dubbo --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId><version>${dubbo.version}</version></dependency><!-- hutool工具类--><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>${hutool-all.version}</version></dependency><!-- Lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></dependency><!-- Minio --><dependency><groupId>io.minio</groupId><artifactId>minio</artifactId><version>${minio.version}</version></dependency><!--这个依赖是整合dubbo时要用到的--><!-- https://mvnrepository.com/artifact/com.google.guava/guava --><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>${guava.version}</version></dependency></dependencies></dependencyManagement><modules><module>ruoyi-auth</module><module>ruoyi-gateway</module><module>ruoyi-visual</module><module>ruoyi-modules</module><module>ruoyi-api</module><module>ruoyi-common</module></modules><packaging>pom</packaging><dependencies><!-- bootstrap 启动器 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>${java.version}</source><target>${java.version}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin></plugins><pluginManagement><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>${spring-boot.version}</version><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></pluginManagement></build><repositories><repository><id>public</id><name>aliyun nexus</name><url>https://maven.aliyun.com/repository/public</url><releases><enabled>true</enabled></releases></repository></repositories><pluginRepositories><pluginRepository><id>public</id><name>aliyun nexus</name><url>https://maven.aliyun.com/repository/public</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></pluginRepository></pluginRepositories></project>

2、生产者

因为我要调用若依的文件服务,所以直接将文件服务作为生产者。依赖如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://maven.apache.org/POM/4.0.0"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><groupId>com.ruoyi</groupId><artifactId>ruoyi-modules</artifactId><version>3.6.3</version></parent><modelVersion>4.0.0</modelVersion><artifactId>ruoyi-modules-file</artifactId><description>ruoyi-modules-file文件服务</description><dependencies><!-- SpringCloud Alibaba Nacos --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!-- SpringCloud Alibaba Nacos Config --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><!-- SpringCloud Alibaba Sentinel --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId></dependency><!-- SpringBoot Actuator --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- FastDFS --><dependency><groupId>com.github.tobato</groupId><artifactId>fastdfs-client</artifactId></dependency><!-- RuoYi Api System --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-api-system</artifactId></dependency><!-- RuoYi Common Swagger --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-swagger</artifactId></dependency><!-- Dubbo --><!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-dubbo --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId></dependency><!-- hutool工具类--><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId></dependency><!-- Minio --><dependency><groupId>io.minio</groupId><artifactId>minio</artifactId></dependency><!-- Mysql Connector --><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId></dependency><!-- RuoYi Common DataSource --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-datasource</artifactId></dependency><!-- RuoYi Common DataScope --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-datascope</artifactId></dependency></dependencies><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>

主要是这个依赖

<!-- Dubbo -->
<!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-dubbo -->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId><version>2021.0.1.0</version>
</dependency>

先在文件服务的 bootstrap.yml 加上如下配置,解决循环引用

在这里插入图片描述

# Tomcat
server:port: 9300# Spring
spring:application:# 应用名称name: ruoyi-filemain:allow-circular-references: true  # 中断循环引用profiles:# 环境配置active: devcloud:nacos:discovery:# 服务注册地址server-addr: 127.0.0.1:8848config:# 配置中心地址server-addr: 127.0.0.1:8848# 配置文件格式file-extension: yml# 共享配置shared-configs:- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

如何在nacos中对应的配置文件中添加如下配置:

在这里插入图片描述

# dubbo相关配置
dubbo:protocol:name: dubbo  # dubbo协议port: -1  # -1表示端口从20880开始递增,不会造成端口冲突registry:address: nacos://127.0.0.1:8848# check: false  # dubbo默认有启动检查scan:base-packages: com.ruoyi.file.service

接着在启动类中加上 @EnableDubbo 注解

在这里插入图片描述

接着是dubbo的接口,接口放在这里

在这里插入图片描述

具体如下:

package com.ruoyi.system.api;import com.ruoyi.system.api.domain.SysFileInfo;
import org.springframework.web.multipart.MultipartFile;import java.util.List;/*** dubbo文件接口** @author:gan* @date: 2024-01-30 09:58*/
public interface DubboFileService {/*** 文件上传接口原始** @param file 上传的文件* @return 访问地址* @throws Exception*/String uploadFile(MultipartFile file) throws Exception;/*** 文件上传接口(自定义)** @param file 上传的文件* @param secondPath 文件二级路径* @return 访问地址* @throws Exception*/SysFileInfo upload(MultipartFile file, String secondPath) throws Exception;/*** 文件上传接口(自定义)** @param file 上传的文件* @return 访问地址* @throws Exception*/SysFileInfo upload(MultipartFile file) throws Exception;/*** 根据文件id查询文件* @param params* @return*/List<SysFileInfo> getSysFileInfoList(SysFileInfo params);
}

对应的实现类

package com.ruoyi.file.service;import com.ruoyi.system.api.DubboFileService;
import com.ruoyi.system.api.domain.SysFileInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.web.multipart.MultipartFile;import javax.annotation.Resource;
import java.util.List;/*** dubbo文件服务** @author:gan* @date: 2024-02-21 17:53*/
@DubboService(version = "1.0.0")
public class DubboFileServiceImpl implements DubboFileService {@Resourceprivate IMinioSysFileService minioSysFileService;@Overridepublic String uploadFile(MultipartFile file) throws Exception {return minioSysFileService.uploadFile(file);}@Overridepublic SysFileInfo upload(MultipartFile file, String secondPath) throws Exception {return minioSysFileService.upload(file, secondPath);}@Overridepublic SysFileInfo upload(MultipartFile file) throws Exception {return minioSysFileService.upload(file);}@Overridepublic List<SysFileInfo> getSysFileInfoList(SysFileInfo params) {return minioSysFileService.getSysFileInfoList(params);}
}

其实要用的方法都在 IMinioSysFileService 的实现类中写好了,这里只是为了使用 @DubboService 注解。

然后启动文件服务

在这里插入图片描述

再查看nacos中的服务列表

在这里插入图片描述

可以看到生产者已经启动成功了。

3、消费者

在 ruoyi-modules 模块下新建了一个 名为 common-test 的模块作为消费者,依赖如下:

<?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>ruoyi-modules</artifactId><groupId>com.ruoyi</groupId><version>3.6.3</version></parent><modelVersion>4.0.0</modelVersion><artifactId>common-test</artifactId><dependencies><!-- SpringCloud Alibaba Nacos --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!-- SpringCloud Alibaba Nacos Config --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><!-- SpringCloud Alibaba Sentinel --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId></dependency><!-- SpringBoot Actuator --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- Swagger UI --><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>${swagger.fox.version}</version></dependency><!-- Mysql Connector --><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId></dependency><!-- RuoYi Api System --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-api-system</artifactId></dependency><!-- RuoYi Common DataSource --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-datasource</artifactId></dependency><!-- RuoYi Common DataScope --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-datascope</artifactId></dependency><!-- RuoYi Common Swagger --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-swagger</artifactId></dependency><!-- Dubbo --><!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-dubbo --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId></dependency><!--这个依赖是整合dubbo时要用到的--><!-- https://mvnrepository.com/artifact/com.google.guava/guava --><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId></dependency></dependencies></project>

添加项目中的 bootstrap.yml 配置文件,具体内容如下:

# Tomcat
server:port: 9302# Spring
spring:application:# 应用名称name: common-testmain:allow-circular-references: true  # 中断循环引用profiles:# 环境配置active: devcloud:nacos:discovery:# 服务注册地址server-addr: 127.0.0.1:8848config:# 配置中心地址server-addr: 127.0.0.1:8848# 配置文件格式file-extension: yml# 共享配置shared-configs:- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

在nacos中添加名为 common-test-dev.yml 的配置,具体内容如下:

# spring配置
spring:servlet:multipart:maxFileSize: 30MBmaxRequestSize: 30MBdatasource:druid:stat-view-servlet:enabled: trueloginUsername: adminloginPassword: 123456dynamic:druid:initial-size: 5min-idle: 5maxActive: 20maxWait: 60000timeBetweenEvictionRunsMillis: 60000minEvictableIdleTimeMillis: 300000validationQuery: SELECT 1 FROM DUALtestWhileIdle: truetestOnBorrow: falsetestOnReturn: falsepoolPreparedStatements: truemaxPoolPreparedStatementPerConnectionSize: 20filters: stat,slf4jconnectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000connectTimeout: 1800000socketTimeout: 1800000datasource:# 主库数据源master:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/hr-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8username: rootpassword: 123456druid: # 配置数据库连接参数connectTimeout: 1800000socketTimeout: 1800000# mybatis配置
mybatis:# 搜索指定包别名typeAliasesPackage: com.common.test# 配置mapper的扫描,找到所有的mapper.xml映射文件mapperLocations: classpath:mapper/**/*.xmlconfiguration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl# dubbo相关配置
dubbo:protocol:name: dubbo  # dubbo协议port: -1     # -1表示端口从20880开始递增,不会造成端口冲突registry:address: nacos://127.0.0.1:8848consumer:check: false  # dubbo默认有启动检查retries: 0  # dubbo内置的重试机制

接着在服务启动类中加上 @EnableDubbo 注解

在这里插入图片描述

消费者的测试接口

在这里插入图片描述

package com.common.test.service;/*** 测试接口** @author:gan* @date: 2024-02-04 16:45*/
public interface CommonService {/*** 测试dubbo调用* @return*/Object testDubbo();
}

接口实现类

在这里插入图片描述

package com.common.test.service.impl;import com.common.test.service.CommonService;
import com.ruoyi.system.api.DubboFileService;
import com.ruoyi.system.api.domain.SysFileInfo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;import java.util.List;/*** 测试接口实现类** @author:gan* @date: 2024-02-04 16:47*/
@Service
public class CommonServiceImpl implements CommonService {@DubboReference(version = "1.0.0")private DubboFileService dubboFileService;@Overridepublic Object testDubbo() {SysFileInfo selectSysFileInfoParams = new SysFileInfo();selectSysFileInfoParams.setFileId("1752583940597551104");List<SysFileInfo> sysFileInfoList = dubboFileService.getSysFileInfoList(selectSysFileInfoParams);System.out.println(sysFileInfoList.get(0));return sysFileInfoList.get(0);}
}

测试前端控制器

在这里插入图片描述

package com.common.test.controller;import com.common.test.service.CommonService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;/*** 测试controller** @author:gan* @date: 2024-02-04 16:48*/
@RestController
@RequestMapping("/test")
public class CommonController {@Resourceprivate CommonService commonService;@GetMapping("/testDubbo")public AjaxResult test() {AjaxResult result = null;try {result = AjaxResult.success(commonService.testDubbo());} catch (Exception e) {e.printStackTrace();result = AjaxResult.error(e.getMessage());} finally {return result;}}
}

然后启动测试服务

在这里插入图片描述

再查看服务列表

在这里插入图片描述

可以看到消费者也启动成功了。

这里只是测试,就不需要用token了,在 ruoyi-gateway 的配置文件中加上如下配置:

在这里插入图片描述

在这里插入图片描述

重启 ruoyi-gateway 服务,再进行接口测试

在这里插入图片描述

三、修改若依的服务调用方式为dubbo

在开始之前,先给小伙伴们打个预防针,改造的过程会比较麻烦,这里以依赖冲突为最,若是对dubbo、若依不够熟悉或者怕麻烦的就跳过这一块。这里放个局部修改图:

在这里插入图片描述

看到这里如果没有跳过,那就开始吧。

1、改造系统模块

先引入依赖,父依赖和前面的父依赖一样,这里是处理系统模块的依赖,添加如下依赖:

<!-- Dubbo -->
<!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-dubbo -->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency><!--这个依赖是整合dubbo时要用到的-->
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId>
</dependency>

然后排除掉 openfeign 的依赖,去掉若依自带的日志模块:

在这里插入图片描述

如果没有排掉,启动服务时会报 openfeign 和 dubbo 的依赖冲突的错。去掉日志模块是因为日志中也使用了 openfeign 。

完整依赖如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://maven.apache.org/POM/4.0.0"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><parent><groupId>com.ruoyi</groupId><artifactId>ruoyi-modules</artifactId><version>3.6.3</version></parent><modelVersion>4.0.0</modelVersion><artifactId>ruoyi-modules-system</artifactId><description>ruoyi-modules-system系统模块</description><dependencies><!-- SpringCloud Alibaba Nacos --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!-- SpringCloud Alibaba Nacos Config --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><!-- SpringCloud Alibaba Sentinel --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId></dependency><!-- SpringBoot Actuator --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- Swagger UI --><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>${swagger.fox.version}</version></dependency><!-- Mysql Connector --><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId></dependency><!-- RuoYi Common DataSource --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-datasource</artifactId></dependency><!-- RuoYi Common DataScope --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-datascope</artifactId><exclusions><exclusion><groupId>io.github.openfeign</groupId><artifactId>feign-core</artifactId></exclusion><exclusion><groupId>io.github.openfeign</groupId><artifactId>feign-slf4j</artifactId></exclusion></exclusions></dependency><!--        &lt;!&ndash; RuoYi Common Log &ndash;&gt;-->
<!--        <dependency>-->
<!--            <groupId>com.ruoyi</groupId>-->
<!--            <artifactId>ruoyi-common-log</artifactId>-->
<!--        </dependency>--><!-- RuoYi Common Swagger --><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-swagger</artifactId></dependency><!-- hutool工具包--><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId></dependency><!-- Dubbo --><!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-dubbo --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId></dependency><!--这个依赖是整合dubbo时要用到的--><!-- https://mvnrepository.com/artifact/com.google.guava/guava --><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId></dependency></dependencies><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>

然后在启动类中去掉 openfeign 的注解,再加上 dubbo 的注解

在这里插入图片描述

然后在 nacos 中系统模块的配置文件中加上 dubbo 的相关配置

在这里插入图片描述

# dubbo相关配置
dubbo:protocol:name: dubbo  # dubbo协议port: -1  # -1表示端口从20880开始递增,不会造成端口冲突registry:address: nacos://127.0.0.1:8848# check: false  # dubbo默认有启动检查scan:base-packages: com.ruoyi.system.service

去掉日志模块再起编译时系统模块的前端控制器应该都会报错,需要把报错的地方注释掉或者去掉,我这里以参数管理的前端控制器为例:

在这里插入图片描述

完成了这些系统模块应该能正常启动了。

在这里插入图片描述

2、改造认证授权中心

但还没结束,启动系统模块后使用默认的 admin 登录,我们会发现报错 admin 不存在。

查找原因:

一开始以为是 admin 账号误删了,看了一下数据库发现账号还在,看了一下控制台,发现是认证授权中心的 SysLoginService
类中报错了,原来是 SysLoginService 这个类使用了系统接口模块的 RemoteUserService 中的
getUserInfo 方法,也就是使用了 openfeign ,用来调用系统模块的根据用户名查询用户接口,虽然认证授权中心中还存在 openfeign 依赖,但是系统模块的已被排除了,自然就报错了。

解决办法:

注释或者去掉认证授权中心 openfeign 相关的使用,以 dubbo 代之。

同样,先处理依赖的问题,经过观察,发现认证授权中心的 openfeign 相关的依赖在如下依赖中,做出排除

在这里插入图片描述

然后加上 dubbo 相关的依赖:

<!-- Dubbo -->
<!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-dubbo -->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency><!--这个依赖是整合dubbo时要用到的-->
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId>
</dependency>

完整依赖如下:

<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><groupId>com.ruoyi</groupId><artifactId>ruoyi</artifactId><version>3.6.3</version></parent><modelVersion>4.0.0</modelVersion><artifactId>ruoyi-auth</artifactId><description>ruoyi-auth认证授权中心</description><dependencies><!-- SpringCloud Alibaba Nacos --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!-- SpringCloud Alibaba Nacos Config --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><!-- SpringCloud Alibaba Sentinel --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-sentinel</artifactId></dependency><!-- SpringBoot Web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- SpringBoot Actuator --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- RuoYi Common Security--><dependency><groupId>com.ruoyi</groupId><artifactId>ruoyi-common-security</artifactId><exclusions><exclusion><groupId>io.github.openfeign</groupId><artifactId>feign-core</artifactId></exclusion><exclusion><groupId>io.github.openfeign</groupId><artifactId>feign-slf4j</artifactId></exclusion></exclusions></dependency><!-- Dubbo --><!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-dubbo --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId></dependency><!--这个依赖是整合dubbo时要用到的--><!-- https://mvnrepository.com/artifact/com.google.guava/guava --><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId></dependency></dependencies><build><finalName>${project.artifactId}</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></build></project>

然后在 nacos 中认证授权中心的配置文件中加上如下配置:

在这里插入图片描述

# dubbo相关配置
dubbo:protocol:name: dubbo  # dubbo协议port: -1     # -1表示端口从20880开始递增,不会造成端口冲突registry:address: nacos://127.0.0.1:8848consumer:check: false  # dubbo默认有启动检查retries: 0  # dubbo内置的重试机制

接着在启动类中去掉 openfeign 的注解,再加上 dubbo 的注解

在这里插入图片描述

然后用 dubbo 的方式写一个接口,以用户服务 RemoteUserService 为例,写一个对应的 DubboUserService 用来替换用户服务 RemoteUserService

在这里插入图片描述

完整代码如下:

package com.ruoyi.system.api;import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;/*** dubbo用户服务** @author:gan* @date: 2024-02-28 10:36*/
public interface DubboUserService {/*** 通过用户名查询用户信息* @param username  用户名* @return*/public LoginUser getUserInfo(String username);/*** 注册用户信息** @param sysUser 用户信息* @return 结果*/public Boolean registerUserInfo(SysUser sysUser);
}

其实现类就放在系统模块的包下,完整代码如下:

package com.ruoyi.system.service.impl;import com.ruoyi.common.core.utils.VerifyUtil;
import com.ruoyi.system.api.DubboUserService;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysPermissionService;
import org.apache.dubbo.config.annotation.DubboService;import javax.annotation.Resource;/*** dubbo用户服务 业务处理层** @author:gan* @date: 2024-02-28 10:41*/
@DubboService(version = "1.0.0")
public class DubboUserServiceImpl implements DubboUserService {@Resourceprivate SysUserMapper sysUserMapper;@Resourceprivate ISysPermissionService permissionService;@Resourceprivate ISysConfigService configService;@Overridepublic LoginUser getUserInfo(String username) {SysUser sysUser = sysUserMapper.selectUserByUserName(username);VerifyUtil.checkParam(sysUser, "用户名或密码错误!");LoginUser sysUserVo = new LoginUser();sysUserVo.setSysUser(sysUser);sysUserVo.setRoles(permissionService.getRolePermission(sysUser));  // 角色集合sysUserVo.setPermissions(permissionService.getMenuPermission(sysUser));  // 权限集合return sysUserVo;}@Overridepublic Boolean registerUserInfo(SysUser sysUser) {configService.selectConfigByKey("sys.account.registerUser");if (!Boolean.TRUE.equals(configService.selectConfigByKey("sys.account.registerUser"))) {throw new RuntimeException("当前系统没有开启注册功能!");}String username = sysUser.getUserName();VerifyUtil.checkParam(sysUserMapper.checkUserNameUnique(username), "保存用户'" + username + "'失败,注册账号已存在!");return sysUserMapper.insertUser(sysUser) > 0;}
}

其中 VerifyUtil 是自己写的判空工具类,可以用自己的方式判空。

接着在 SysLoginService 类中注释掉用户服务 RemoteUserService 相关的逻辑,再以dubbo用户服务 DubboUserService 代之:

在这里插入图片描述

日志服务 RemoteLogService 也是同理。改造完成,再成功启动后就可以登录了。

这里贴一下我的日志服务代码

在这里插入图片描述

完整代码如下:

package com.ruoyi.system.api;import com.ruoyi.system.api.domain.SysLogininfor;
import com.ruoyi.system.api.domain.SysOperLog;/*** dubbo日志服务** @author:gan* @date: 2024-02-28 11:21*/
public interface DubboLogService {/*** 保存系统日志** @param sysOperLog 日志实体* @return 结果*/public Boolean saveLog(SysOperLog sysOperLog);/*** 保存访问记录** @param sysLogininfor 访问实体* @return 结果*/public Boolean saveLogininfor(SysLogininfor sysLogininfor);
}

对应实现类也在系统模块

package com.ruoyi.system.service.impl;import com.ruoyi.system.api.DubboLogService;
import com.ruoyi.system.api.domain.SysLogininfor;
import com.ruoyi.system.api.domain.SysOperLog;
import com.ruoyi.system.mapper.SysLogininforMapper;
import com.ruoyi.system.mapper.SysOperLogMapper;
import org.apache.dubbo.config.annotation.DubboService;import javax.annotation.Resource;/*** dubbo日志服务  服务层处理** @author:gan* @date: 2024-02-28 11:24*/
@DubboService(version = "1.0.0")
public class DubboLogServiceImpl implements DubboLogService {@Resourceprivate SysOperLogMapper operLogMapper;@Resourceprivate SysLogininforMapper logininforMapper;@Overridepublic Boolean saveLog(SysOperLog sysOperLog) {return operLogMapper.insertOperlog(sysOperLog) > 0;}@Overridepublic Boolean saveLogininfor(SysLogininfor sysLogininfor) {return logininforMapper.insertLogininfor(sysLogininfor) > 0;}
}

以dubbo日志服务替换掉 SysRecordLogService 类中的日志服务

在这里插入图片描述

四、整合过程遇到的问题

1、出现循环引用

我想着文件模块整合dubbo,引入依赖、加上注解之后报错如下:

在这里插入图片描述

***************************
APPLICATION FAILED TO START
***************************Description:The dependencies of some of the beans in the application context form a cycle:targeterBeanPostProcessor defined in class path resource [com/alibaba/cloud/dubbo/autoconfigure/DubboOpenFeignAutoConfiguration.class]com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository (field private com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository.dubboMetadataConfigServiceProxy)com.alibaba.cloud.dubbo.service.DubboMetadataServiceProxy
┌─────┐
|  com.alibaba.cloud.dubbo.autoconfigure.DubboMetadataAutoConfiguration (field private com.alibaba.cloud.dubbo.metadata.resolver.MetadataResolver com.alibaba.cloud.dubbo.autoconfigure.DubboMetadataAutoConfiguration.metadataResolver)
└─────┘Action:Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

虽然他已经提示要加上配置:

# Spring
spring:main:allow-circular-references: true  # 中断循环引用

但是我nacos的配置中加上之后没有效果

在这里插入图片描述

重启还是报那个错。

应该在对应模块的 bookstrap.yml 文件中加配置

在这里插入图片描述
再次重启

在这里插入图片描述

看来配置生效了,再看看nacos中有没有dubbo中的服务

在这里插入图片描述

2、出现依赖冲突

我想要在系统模块中使用 dubbo ,但引入 dubbo 相关依赖:

<!-- Dubbo -->
<!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-dubbo -->
<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>

报错如下:

在这里插入图片描述

***************************
APPLICATION FAILED TO START
***************************Description:An attempt was made to call a method that does not exist. The attempt was made from the following location:com.alibaba.cloud.dubbo.metadata.RestMethodMetadata.<init>(RestMethodMetadata.java:80)The following method did not exist:feign.MethodMetadata.queryMapEncoded()ZThe calling method's class, com.alibaba.cloud.dubbo.metadata.RestMethodMetadata, was loaded from the following location:jar:file:/D:/environment/Maven/apache-maven-3.6.0/repository/com/alibaba/cloud/spring-cloud-starter-dubbo/2021.0.1.0/spring-cloud-starter-dubbo-2021.0.1.0.jar!/com/alibaba/cloud/dubbo/metadata/RestMethodMetadata.classThe called method's class, feign.MethodMetadata, is available from the following locations:jar:file:/D:/environment/Maven/apache-maven-3.6.0/repository/io/github/openfeign/feign-core/11.10/feign-core-11.10.jar!/feign/MethodMetadata.classThe called method's class hierarchy was loaded from the following locations:feign.MethodMetadata: file:/D:/environment/Maven/apache-maven-3.6.0/repository/io/github/openfeign/feign-core/11.10/feign-core-11.10.jarAction:Correct the classpath of your application so that it contains compatible versions of the classes com.alibaba.cloud.dubbo.metadata.RestMethodMetadata and feign.MethodMetadata

原来系统模块使用了 openfeign 进行服务调用,引入 dubbo 相关的依赖后就依赖冲突了,可以排除系统模块中的 openfeign 依赖或者移除 dubbo 依赖,我这里选择了前者

在这里插入图片描述

3、启动出现端口号被占用

生产者已经启动,消费者启动时报错:

在这里插入图片描述

java.lang.IllegalStateException: Failed to execute CommandLineRunnerat org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:771)at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752)at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)at com.common.test.CommonTestApplication.main(CommonTestApplication.java:19)
Caused by: org.apache.dubbo.rpc.RpcException: Fail to start server(url: dubbo://192.168.1.12:20880/com.alibaba.cloud.dubbo.service.DubboMetadataService?anyhost=true&application=common-test&bind.ip=192.168.1.12&bind.port=20880&channel.readonly.sent=true&codec=dubbo&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&group=common-test&heartbeat=60000&interface=com.alibaba.cloud.dubbo.service.DubboMetadataService&metadata-type=remote&methods=getAllServiceKeys,getServiceRestMetadata,getExportedURLs,getAllExportedURLs&pid=27496&qos.enable=false&release=2.7.15&revision=2021.0.1.0&service.name=ServiceBean:common-test/com.alibaba.cloud.dubbo.service.DubboMetadataService:1.0.0&side=provider&timestamp=1708501506423&version=1.0.0) Failed to bind NettyServer on /192.168.1.12:20880, cause: Address already in use: bindat org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.createServer(DubboProtocol.java:350)at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.openServer(DubboProtocol.java:322)at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.export(DubboProtocol.java:305)at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:64)at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:75)at org.apache.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:66)at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java)at org.apache.dubbo.registry.integration.RegistryProtocol.lambda$doLocalExport$2(RegistryProtocol.java:262)at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)at org.apache.dubbo.registry.integration.RegistryProtocol.doLocalExport(RegistryProtocol.java:260)at org.apache.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:212)at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:62)at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:73)at org.apache.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:64)at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java)at org.apache.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:518)at org.apache.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:339)at org.apache.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:314)at org.apache.dubbo.config.ServiceConfig.export(ServiceConfig.java:238)at com.alibaba.cloud.dubbo.service.DubboMetadataServiceExporter.export(DubboMetadataServiceExporter.java:82)at com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository.getDubboMetadataServiceMetadata(DubboServiceMetadataRepository.java:288)at com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository$$FastClassBySpringCGLIB$$1.invoke(<generated>)at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)at com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository$$EnhancerBySpringCGLIB$$1.getDubboMetadataServiceMetadata(<generated>)at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.attachDubboMetadataServiceMetadata(DubboServiceRegistrationAutoConfiguration.java:172)at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.attachDubboMetadataServiceMetadata(DubboServiceRegistrationAutoConfiguration.java:166)at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.lambda$null$0(DubboServiceRegistrationAutoConfiguration.java:131)at java.lang.Iterable.forEach(Iterable.java:75)at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.lambda$onDubboBootstrapStarted$1(DubboServiceRegistrationAutoConfiguration.java:130)at java.util.concurrent.ConcurrentHashMap.forEach(ConcurrentHashMap.java:1597)at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.onDubboBootstrapStarted(DubboServiceRegistrationAutoConfiguration.java:129)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:344)at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:229)at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:166)at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421)at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)at com.alibaba.cloud.dubbo.bootstrap.DubboBootstrapStartCommandLineRunner.run(DubboBootstrapStartCommandLineRunner.java:46)at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:768)... 5 common frames omitted
Caused by: org.apache.dubbo.remoting.RemotingException: Failed to bind NettyServer on /192.168.1.12:20880, cause: Address already in use: bindat org.apache.dubbo.remoting.transport.AbstractServer.<init>(AbstractServer.java:73)at org.apache.dubbo.remoting.transport.netty4.NettyServer.<init>(NettyServer.java:79)at org.apache.dubbo.remoting.transport.netty4.NettyTransporter.bind(NettyTransporter.java:35)at org.apache.dubbo.remoting.Transporter$Adaptive.bind(Transporter$Adaptive.java)at org.apache.dubbo.remoting.Transporters.bind(Transporters.java:56)at org.apache.dubbo.remoting.exchange.support.header.HeaderExchanger.bind(HeaderExchanger.java:44)at org.apache.dubbo.remoting.exchange.Exchangers.bind(Exchangers.java:70)at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.createServer(DubboProtocol.java:348)... 56 common frames omitted
Caused by: java.net.BindException: Address already in use: bindat sun.nio.ch.Net.bind0(Native Method)at sun.nio.ch.Net.bind(Net.java:433)at sun.nio.ch.Net.bind(Net.java:425)at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:141)at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:562)at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1334)at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:600)at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:579)at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:973)at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:260)at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:356)at io.netty.util.concurrent.AbstractEventExecutor.runTask$$$capture(AbstractEventExecutor.java:174)at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java)at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:167)at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java)at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)at java.lang.Thread.run(Thread.java:748)

原因:

这是因为生产者启动时,20880这个端口被占用,消费者尝试使用20880端口启动就报错了

报错日志中也提到了

在这里插入图片描述

可以在配置文件中加入指定端口号或者使用端口号递增,这里选择后者。

在这里插入图片描述

# dubbo相关配置
dubbo:protocol:name: dubbo  # dubbo协议port: -1     # -1表示端口从20880开始递增,不会造成端口冲突registry:address: nacos://127.0.0.1:8848consumer:check: false  # dubbo默认有启动检查retries: 0  # dubbo内置的重试机制

4、出现某个类找不到

就是模块启动时报错:Caused by: java.lang.ClassNotFoundException

在这里插入图片描述

java.lang.IllegalStateException: Failed to execute CommandLineRunnerat org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:771)at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752)at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)at com.common.test.CommonTestApplication.main(CommonTestApplication.java:19)
Caused by: java.lang.reflect.UndeclaredThrowableException: Failed to invoke event listener method
HandlerMethod details: 
Bean [com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration]
Method [public void com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.onDubboBootstrapStarted(com.alibaba.cloud.dubbo.bootstrap.event.DubboBootstrapStartedEvent)]
Resolved arguments: 
[0] [type=com.alibaba.cloud.dubbo.bootstrap.event.DubboBootstrapStartedEvent] [value=com.alibaba.cloud.dubbo.bootstrap.event.DubboBootstrapStartedEvent[source=com.alibaba.cloud.dubbo.bootstrap.DubboBootstrapWrapper@30afac00]]at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:361)at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:229)at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:166)at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421)at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378)at com.alibaba.cloud.dubbo.bootstrap.DubboBootstrapStartCommandLineRunner.run(DubboBootstrapStartCommandLineRunner.java:46)at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:768)... 5 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/google/common/collect/Mapsat org.apache.dubbo.registry.nacos.util.NacosInstanceManageUtil.<clinit>(NacosInstanceManageUtil.java:39)at org.apache.dubbo.registry.nacos.NacosRegistry.doSubscribe(NacosRegistry.java:187)at org.apache.dubbo.registry.support.FailbackRegistry.subscribe(FailbackRegistry.java:299)at org.apache.dubbo.registry.ListenerRegistryWrapper.subscribe(ListenerRegistryWrapper.java:105)at org.apache.dubbo.registry.integration.RegistryProtocol.export(RegistryProtocol.java:232)at org.apache.dubbo.rpc.protocol.ProtocolListenerWrapper.export(ProtocolListenerWrapper.java:62)at org.apache.dubbo.rpc.protocol.ProtocolFilterWrapper.export(ProtocolFilterWrapper.java:73)at org.apache.dubbo.qos.protocol.QosProtocolWrapper.export(QosProtocolWrapper.java:64)at org.apache.dubbo.rpc.Protocol$Adaptive.export(Protocol$Adaptive.java)at org.apache.dubbo.config.ServiceConfig.doExportUrlsFor1Protocol(ServiceConfig.java:518)at org.apache.dubbo.config.ServiceConfig.doExportUrls(ServiceConfig.java:339)at org.apache.dubbo.config.ServiceConfig.doExport(ServiceConfig.java:314)at org.apache.dubbo.config.ServiceConfig.export(ServiceConfig.java:238)at com.alibaba.cloud.dubbo.service.DubboMetadataServiceExporter.export(DubboMetadataServiceExporter.java:82)at com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository.getDubboMetadataServiceMetadata(DubboServiceMetadataRepository.java:288)at com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository$$FastClassBySpringCGLIB$$1.invoke(<generated>)at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)at com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepository$$EnhancerBySpringCGLIB$$1.getDubboMetadataServiceMetadata(<generated>)at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.attachDubboMetadataServiceMetadata(DubboServiceRegistrationAutoConfiguration.java:172)at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.attachDubboMetadataServiceMetadata(DubboServiceRegistrationAutoConfiguration.java:166)at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.lambda$null$0(DubboServiceRegistrationAutoConfiguration.java:131)at java.lang.Iterable.forEach(Iterable.java:75)at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.lambda$onDubboBootstrapStarted$1(DubboServiceRegistrationAutoConfiguration.java:130)at java.util.concurrent.ConcurrentHashMap.forEach(ConcurrentHashMap.java:1597)at com.alibaba.cloud.dubbo.autoconfigure.DubboServiceRegistrationAutoConfiguration.onDubboBootstrapStarted(DubboServiceRegistrationAutoConfiguration.java:129)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:344)... 14 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Mapsat java.net.URLClassLoader.findClass(URLClassLoader.java:382)at java.lang.ClassLoader.loadClass(ClassLoader.java:424)at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)at java.lang.ClassLoader.loadClass(ClassLoader.java:357)... 51 common frames omitted

一开始想着是不是dubbo的版本的问题,但生产者都已经启动成功了,而且用的还是同一个依赖,就想着加一下这个类的依赖看看能不能解决,依赖如下:

在这里插入图片描述

<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>33.0.0-jre</version>
</dependency>

果然启动成功了。

但也纳闷,为什么同样的dubbo依赖,生产者那边就可以,到了消费者这边就不行了?

既然dubbo依赖是相同的,那肯定就是其他依赖的问题,于是对比了其他依赖,最终发现minio的依赖下包含 com.google.guava 依赖

在这里插入图片描述

那就注释掉 com.google.guava 依赖,加入 minio 依赖试试,结果发现也能启动成功…

太难了,就这个问题折腾了好久(大哭)

5、找不到生产者

生产者和消费者都启动了,但是消费者调用生产者服务时报如下错:

在这里插入图片描述

org.apache.dubbo.rpc.RpcException: No provider available from registry 127.0.0.1:8848 for service com.ruoyi.system.api.DubboFileService:1.0.0 on consumer 192.168.1.12 use dubbo version 2.7.15, please check status of providers(disabled, not registered or in blacklist).at org.apache.dubbo.registry.integration.DynamicDirectory.doList(DynamicDirectory.java:168)at org.apache.dubbo.rpc.cluster.directory.AbstractDirectory.list(AbstractDirectory.java:99)at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.list(AbstractClusterInvoker.java:297)at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:262)at org.apache.dubbo.rpc.cluster.interceptor.ClusterInterceptor.intercept(ClusterInterceptor.java:47)at org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster$InterceptorInvokerNode.invoke(AbstractCluster.java:92)at org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:98)at org.apache.dubbo.registry.client.migration.MigrationInvoker.invoke(MigrationInvoker.java:170)at org.apache.dubbo.rpc.cluster.support.registry.ZoneAwareClusterInvoker.doInvoke(ZoneAwareClusterInvoker.java:112)at org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:265)at org.apache.dubbo.rpc.cluster.interceptor.ClusterInterceptor.intercept(ClusterInterceptor.java:47)at org.apache.dubbo.rpc.cluster.support.wrapper.AbstractCluster$InterceptorInvokerNode.invoke(AbstractCluster.java:92)at org.apache.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:96)at org.apache.dubbo.common.bytecode.proxy0.getSysFileInfoList(proxy0.java)at com.common.test.service.impl.CommonServiceImpl.testDubbo(CommonServiceImpl.java:27)at com.common.test.controller.CommonController.test(CommonController.java:28)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1072)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)at javax.servlet.http.HttpServlet.service(HttpServlet.java:645)at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:209)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178)at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153)at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:90)at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:41002)at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:481)at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:130)at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:390)at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:926)at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1791)at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)at java.lang.Thread.run(Thread.java:748)

分析原因:

我的生产者是若依的文件服务,若依的文件服务原来是用 Feign 进行远程调用的,我只是想把 Feign 改为 dubbo ,就定义了一个和原文件接口相同抽象方法的接口,其实就是接口名不一样,再用文件实现类去实现,这样我就不用重新写方法了,具体如下:

在这里插入图片描述

因为启动没报错,nacos中也有看到对应的服务,就没有多想,就是会一直报这个错,后面就想着单独见一个类加上 @DubboService(version = “1.0.0”) 试试

在这里插入图片描述

结果就调用成功了…

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/710604.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

UVa11726 Crime Scene

题目链接 UVa11726 - Crime Scene 题意 给定n&#xff08;n≤100&#xff09;个物体&#xff0c;每个物体都是一个圆或者k&#xff08;k≤10&#xff09;边形&#xff0c;用长度尽量小的绳子把它们包围起来。 分析 孟加拉国Manzurur Rahman Khan (Sidky)大神出的难题&#xff…

MySQL 核心模块揭秘 | 07 期 | 二阶段提交 (1) prepare 阶段

二阶段提交的 prepare 阶段&#xff0c;binlog 和 InnoDB 各自会有哪些动作&#xff1f; 本文基于 MySQL 8.0.32 源码&#xff0c;存储引擎为 InnoDB。 1. 二阶段提交 二阶段提交&#xff0c;顾名思义&#xff0c;包含两个阶段&#xff0c;它们是&#xff1a; prepare 阶段。…

springboot-基础-eclipse配置+helloword示例

备份笔记。所有代码都是2019年测试通过的&#xff0c;如有问题请自行搜索解决&#xff01; 下一篇&#xff1a;springboot-基础-添加model和controller的简单例子常用注解含义 目录 配置helloword示例新建项目创建文件 配置 spring boot官方有定制版eclipse&#xff0c;也就是…

BUUCTF AWD-Test1

打开靶场是这个有些简陋的界面。 随便点点&#xff0c;找到这个东西。 看到ThinkPHP&#xff0c;思路瞬间清晰&#xff0c;老熟人了。这个就是ThinkPHP漏洞。根据版本我们去找一下poc。 /index.php/?sIndex/\think\View/display&content%22%3C?%3E%3C?php%20phpinfo();…

服务端向客户端推送数据的实现方案

在日常的开发中&#xff0c;我们经常能碰见服务端需要主动推送给客户端数据的业务场景&#xff0c;比如数据大屏的实时数据&#xff0c;比如消息中心的未读消息&#xff0c;比如聊天功能等等。 本文主要介绍SSE的使用场景和如何使用SSE。 服务端向客户端推送数据的实现方案有哪…

MySQL 自增列解析(Auto_increment)

MySQL数据库为列提供了一种自增属性&#xff0c;当列被定义为自增时。Insert语句对该列即使不提供值&#xff0c;MySQL也会自动为该列生成递增的唯一标识&#xff0c;因此这个特性广泛用于主键的自动生成。 一、自增列的用法 自增列具有自动生成序列值&#xff0c;整型&#…

MYSQL04高级_逻辑架构剖析、查询缓存、解析器、优化器、执行器、存储引擎

文章目录 ①. 逻辑架构剖析②. 服务层 - 查询缓存③. 服务层 - 解析器④. 服务层 - 优化器⑤. 服务层 - 执行器⑥. MySQL8执行原理 ①. 逻辑架构剖析 ①. 服务器处理客户端请求 ②. 连接层 系统(客户端)访问MySQL服务器前,做的第一件事就是建立TCP连接经过三次握手建立连接成…

Linux使用C语言实现通过互斥锁限制对共享资源的访问

互斥锁限制共享资源的访问 主线程中有两个线程&#xff0c;分别输出信息。 #include <stdio.h> #include <pthread.h> #include <unistd.h>int g_data0;void* fun1(void *arg) {printf("t1&#xff1a;%ld thread is create\n", (unsigned long)…

稀疏图带负边的全源最短路Johnson算法

BellmanFord算法 Johnson算法解决的问题 带负权的稀疏图的全源最短路 算法流程 重新设置的每条边的权重都大于或等于0&#xff0c;跑完Djikstra后得到的全源最短路&#xff0c;记得要还原&#xff0c;即&#xff1a;f(u,v) d(u,v) - h[u] h[v] 例题

45、WEB攻防——通用漏洞PHP反序列化POP链构造魔术方法原生类

文章目录 序列化&#xff1a;将java、php等代码中的对象转化为数组或字符串等格式。代表函数serialize()&#xff0c;将一个对象转换成一个字符&#xff1b;反序列化&#xff1a;将数组或字符串等格式还成对象。代表函数unserialize()&#xff0c;将字符串还原成一个对象。 P…

MWC 2024丨Smart Health搭载高通Aware平台—美格发布智能健康看护解决方案,开启健康管理新体验

2月29日&#xff0c;在MWC 2024世界移动通信大会上&#xff0c;全球领先的无线通信模组及解决方案提供商——美格智能正式发布了新一代Cat.1模组SLM336Q&#xff0c;是中低速物联网应用场景的高性价比之选。本次还发布了首款搭载高通Aware™平台的智能看护解决方案MC303&#x…

[万字长文] 从 Vue 3 的项目模板学习 tsconfig 配置

文章目录 一、tsconfig.json 的作用二、基本介绍三、Vue 3 的 tsconfig.json 的结构分析1. 总配置 tsconfig.json2. Web 侧 tsconfig.app.jsona. 继承基础配置b. 包含和排除的文件c. 编译器选项 3. 测试 tsconfig.vitest.jsona. 继承的基础配置b. 包含和排除的文件c. 编译器选项…

OD(13)之Mermaid饼图和象限图

OD(13)之Mermaid饼图和象限图使用详解 Author: Once Day Date: 2024年2月29日 漫漫长路才刚刚开始… 全系列文章可参考专栏: Mermaid使用指南_Once_day的博客-CSDN博客 参考文章: 关于 Mermaid | Mermaid 中文网 (nodejs.cn)Mermaid | Diagramming and charting tool‍‌⁡…

FPGA-学会使用vivado中的存储器资源RAM(IP核)

问题 信号源(例如ADC)以1us一个的速率产生12位的数据现要求获得连续1ms内的数据,通过串口以115200的波特率发到电脑。 分析 数据量是1000个 数据速率不匹配 数据内容未知 数据总数据量有限 数据的使用速度低于数据的产生速度 数据生产和消耗的位宽 数据量相对较…

ywtool check命令及ywtool clean命令

一.ywtool check命令 1.1 ywtool check -I 1.2 ywtool check all 1.3 ywtool check io 1.4 ywtool check elk 1.5 ywtool check php 1.6 ywtool check mysql 1.7 ywtool check nginx 1.8 ywtool check system 1.9 ywtool check docker_nbip [容器名称] 1.10 ywtool check 1.10…

综合练习(一)

目录 列出薪金高于部门 30 的所有员工薪金的员工姓名和薪金、部门名称、部门人数 列出与 ALLEN从事相同工作的所有员工及他们的部门名称、部门人数、领导姓名 Oracle从入门到总裁:https://blog.csdn.net/weixin_67859959/article/details/135209645 列出薪金高于部门 30 的所…

基于JSON的Ollama和LangChain agent

到目前为止&#xff0c;我们都可能意识到&#xff0c;通过为LLMs提供额外的工具&#xff0c;我们可以显著增强它们的功能。 例如&#xff0c;即使是ChatGPT在付费版本中也可以直接使用Bing搜索和Python解释器。OpenAI更进一步&#xff0c;为工具使用提供了经过优化的LLM模型&am…

js方法 提前结束循环

http://t.csdnimg.cn/j0gkOhttp://t.csdnimg.cn/j0gkO 一、各种循环方法如何跳出整个循环&#xff1f; 对于forEach()方法&#xff0c;目前似乎没有比较优雅的跳出整个循环的方法&#xff0c;如果你实在要用forEach()方法并且需要在某种条件下跳出整个循环提高遍历效率&#x…

政安晨:【掌握AI的深度学习工具Keras API】(二)—— 【使用内置的训练循环和评估循环】

渐进式呈现复杂性&#xff0c;是指采用一系列从简单到灵活的工作流程&#xff0c;并逐步提高复杂性。这个原则也适用于模型训练。Keras提供了训练模型的多种工作流程。这些工作流程可以很简单&#xff0c;比如在数据上调用fit()&#xff0c;也可以很高级&#xff0c;比如从头开…

uniapp实战:父子组件传参之子组件数量动态变化

需求说明 现有的设置单元列表,每个带有虚线加号的可以看做是一组设置单元,点击加号可以添加一组设置单元.点击设置单元右上角可以删除对应的设置单元. 实现思路说明 利用数组元素添加或是删除的方式实现页面数量动态变化.由于每个设置单元内容都相同所以单独封装了一个子组件.…