Nacos+Gateway使用lb: xxxservice不起作用 ,Can not get service instances from nacos, serviceId=null

1 问题

在nacos和gateway整合的时候,报错

java.lang.IllegalStateException: Can not get service instances from nacos, serviceId=null

意思是服务找不到,在nacos里面找不到,可是明明已经看见了啊,已经注册进去了啊,为啥找不到,
gateway里面的这个是通过服务名找项目
在这里插入图片描述
所以就出在这个问题上;

就是你的版本问题了,这个整合版本问题是坑,意思是你得找可以使用这个lb模式的版本才可以;

使用其他版本,可以使用http的形式,但是如果你想要使用lb这个模式,就得找对版本

目前我找到一个

2 解决

首先是父项目的依赖,直接使用我的这个,你的那些版本,可能不支持,或者有解决的方法,但是你得花时间找,直接拿上我的这个版本就可以

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <modules>
<!--        <module>order</module>-->
<!--        <module>stock</module>-->
<!--        <module>order-ribbon</module>-->
<!--        <module>order-nacos</module>-->
        <module>stock-nacos</module>
        <module>order-openfeign</module>
        <module>gateway</module>
<!--        <module>nacos-config</module>-->
<!--        <module>order-sentinel</module>-->
<!--        <module>gateway</module>-->
        <!--        <module>Sentinel-demo</module>-->
    </modules>
<!--    <parent>-->
<!--        <groupId>org.springframework.boot</groupId>-->
<!--        <artifactId>spring-boot-starter-parent</artifactId>-->
<!--        <version>2.3.2.RELEASE</version>-->
<!--        <relativePath/> &lt;!&ndash; lookup parent from repository &ndash;&gt;-->
<!--    </parent>-->
    <!--属性集合-->
    <properties>
        <java.version>1.8</java.version>
        <java.version>1.8</java.version>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>

        <spring.boot.version>2.5.5</spring.boot.version>
        <spring.cloud.version>2020.0.4</spring.cloud.version>
        <spring.cloud.bootstrap.version>3.0.4</spring.cloud.bootstrap.version>
        <spring.cloud.alibaba.version>2021.1</spring.cloud.alibaba.version>
        <stream.cloud.version>3.1.4</stream.cloud.version>

        <gateway.version>3.0.4</gateway.version>

<!--        <java.version>1.8</java.version>-->
<!--        <spring.cloud.alibaba.version>2.2.5.RELEASE</spring.cloud.alibaba.version>-->
<!--        <spring.cloud.version>Hoxton.SR8</spring.cloud.version>-->
<!--        <spring.boot.version>2.3.11.RELEASE</spring.boot.version>-->
    </properties>

    <groupId>com.jing</groupId>
    <artifactId>jing</artifactId>
    <version>0.0.1-SNAPSHOT</version>
<!--    <packaging>pom</packaging>-->
    <name>jing</name>
    <description>Demo project for Spring Boot</description>

    <dependencies>
<!--        <dependency>-->
<!--            <groupId>com.alibaba.csp</groupId>-->
<!--            <artifactId>sentinel-core</artifactId>-->
<!--            <version>1.8.0</version>-->
<!--        </dependency>-->

        <!--        springboot-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-dependencies -->
<!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-dependencies</artifactId>-->
<!--            <version>Hoxton.SR3</version>-->
<!--            <type>pom</type>-->
<!--            <scope>import</scope>-->
<!--        </dependency>-->
        <!--引入注册中心阿里巴巴-->
        <!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-alibaba-nacos-discovery -->
<!--        <dependency>-->
<!--            <groupId>com.alibaba.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>-->
<!--            <version>2.0.2.RELEASE</version>-->
<!--        </dependency>-->

<!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-dependencies</artifactId>-->
<!--            <version>${spring.cloud.version}</version>-->
<!--            <type>pom</type>-->

<!--        </dependency>-->
        <!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-alibaba-nacos-config -->
<!--        <dependency>-->
<!--            <groupId>com.alibaba.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>-->
<!--            <version>2.2.6.RELEASE</version>-->
<!--        </dependency>-->

<!--        <dependency>-->
<!--            <groupId>com.alibaba.cloud</groupId>-->
<!--            <artifactId>spring-cloud-alibaba-dependencies</artifactId>-->
<!--            <version>${spring.cloud.alibaba.version}</version>-->
<!--            <type>pom</type>-->

<!--        </dependency>-->
    </dependencies>

    <!--全局引入下载依赖地址,并不会引入依赖-->
    <dependencyManagement>
        <!--放在dependencyManagement里的依赖,子maven一定要显式的声明,
          没有放在dependencyManagement里的依赖,子maven直接继承父maven的没放的依赖
      -->
        <!--spring cloud alibaba的版本管理器,通过dependency方式来完成继承-->
        <dependencies>
            <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-starter-parent</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!--Spring Cloud的版本管理-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring.cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>

    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.1</version>

            </plugin>
        </plugins>
    </build>

</project>

gateway项目里面的pom文件

<?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>jing</artifactId>
        <groupId>com.jing</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>gateway</artifactId>

<dependencies>
    <!--gateway依赖,需要有springcloud的依赖管理器,如果没有设置的话,需要指定版本-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>

    <!--nacos服务注册与发现-->
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-loadbalancer</artifactId>
    </dependency>
</dependencies>
</project>

openfeign的项目里面

<?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>jing</artifactId>
        <groupId>com.jing</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>order-openfeign</artifactId>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
<!--        1 <!‐‐ openfeign 远程调用 ‐‐>-->
        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-openfeign -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
<!--            <version>2.2.6.RELEASE</version>-->
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-loadbalancer</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<!--            <version>2.2.6.RELEASE</version>-->
        </dependency>

        <!--        nacos 的服务注册与发现的依赖-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<!--            <version>2.0.2.RELEASE</version>-->
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-bootstrap -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
<!--            <version>3.0.2</version>-->
        </dependency>


        <!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-bootstrap</artifactId>-->
<!--        </dependency>-->

    </dependencies>
</project>

接下来是gateway的配置文件

server:
  port: 8098
spring:
#  main:
#    allow-bean-definition-overriding: true
  application:
    name: gateway

  cloud:
    nacos:
      server-addr: 127.0.0.1:8848
      discovery:
        password: nacos
        namespace: public
        username: nacos
        service: gateway


    # gateway 的配置
    gateway:
      #gateway的配置

      discovery:
        locator:
          enabled: true #是否启动自动识别nacos服务

#      路由规则
      routes:
        - id: orderroute  # 路由唯一的标识
          uri: lb://orderopenfeign
#          断言规则,用于路由规则的匹配
          predicates:
            - Path=/orderserver/**
#  过滤器
          filters:
            - StripPrefix=1  # 作用是  转发之前去掉  第一层的路径


使用以上的pom里面的版本就可以实现了,不会出现
Nacos+Gateway使用lb: xxxservice不起作用;

其他版本的,你们找到解决方法了嘛,欢迎评论,一起进步

### 使用 Qt 打开 VSQT 创建的 .ui 文件 当尝试在 Visual StudioQt 集成环境下打开 `.ui` 文件时,如果遇到设计师界面闪退或乱码等问题,可以按照以下建议进行排查和修复。 #### 1. 确认 Qt 版本兼容性 确保使用的 Qt Designer 的版本与项目中的 Qt 库版本相匹配。不同版本之间可能存在不兼容的情况,这可能导致 UI 文件无法正确加载[^3]。 #### 2. 设置正确的 Qt Designer 路径 有时 IDE 并未自动配置好 Qt Designer 的路径,导致双击 `.ui` 文件时启动失败。可以通过设置工具链选项来指定 Qt 安装目录下的 designer.exe 的确切位置。 #### 3. 检查文件编码格式 对于出现中文或其他特殊字符乱码的现象,可能是由于保存时选择了错误的文字编码所致。应确认源文件采用 UTF-8 编码保存,并且在 Qt Designer 中也支持该编码标准[^2]。 #### 4. 清理缓存重新构建项目 偶尔残留的临时文件会干扰到新的编译过程,清除整个解决方案的中间产物再做一次完整的重建有助于排除潜在冲突[^4]。 #### 5. 更新插件及组件库 保持所有依赖项处于最新状态,特别是那些用于扩展功能的第三方模块,因为开发者社区经常会发布针对特定 bug 或性能优化方面的更新补丁[^1]。 ```cpp // 示例:清理并重置Visual Studio项目的命令行指令 devenv /resetsettings msbuild YourProject.sln /t:Clean;Rebuild /p:Configuration=Release ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一写代码就开心

你的打赏将是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值