Injection of @DubboReference dependencies is failed;

简介: Injection of @DubboReference dependencies is failed;

启动Dubbo服务的时候报错了Injection of @DubboReference dependencies is failed; nested exception is java.lang.IllegalStateException: zookeeper not connected

依赖:

<!--    属性配置-->
    <properties>
        <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.3.12.RELEASE</spring.boot.version>
        <dubbo.version>3.0.0</dubbo.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo</artifactId>
            <version>${dubbo.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-dependencies-zookeeper</artifactId>
            <version>${dubbo.version}</version>
            <type>pom</type>
        </dependency>
        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                    <include>**/*.html</include>
                </includes>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

配置:

server.port=8081
dubbo.application.name=application-name
dubbo.registry.address=zookeeper://192.168.122.128:2181
dubbo.protocol.name=dubbo
dubbo.protocol.port=-1
dubbo.registry.timeout=60000

启动类:

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnableDubbo
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

消费端:

import com.example.dubbo.service.HelloService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
    @DubboReference(check = false)
    private HelloService helloService;
    @GetMapping("/hello")
    public String sayHello(@RequestParam String name) {
        return helloService.sayHello(name);
    }
}

提供者:

import com.example.dubbo.service.HelloService;
import org.apache.dubbo.config.annotation.DubboService;
@DubboService
public class HelloServiceImpl implements HelloService {
    @Override
    public String sayHello(String name) {
        return "Hello, " + name + "!";
    }
}

解决办法其实就是@DubboService添加接口类即可,代码如下:

import com.example.dubbo.service.HelloService;
import org.apache.dubbo.config.annotation.DubboService;
@DubboService(interfaceClass = HelloService.class)
public class HelloServiceImpl implements HelloService {
    @Override
    public String sayHello(String name) {
        return "Hello, " + name + "!";
    }
}


相关文章
|
存储 SQL 分布式计算
浅谈MPP数据库-Vertica
用过这块数据库3年时间,很多功能非常强大,POC做了很多数据库,查询性能可以说是最好的,推荐一下
3124 2
|
缓存 JSON 算法
(三).NET Core WebAPI集成JWT,实现身份验证
前两篇文章给大家介绍了在.NET Core中如何使用Swagger的文章,那今天给大家分享一下JWT 在做接口开发的同学可能都有感受,我的接口如何保护的问题,如果没有身份验证,那不是接口完全暴露在外面,任意使人调用,这显然不是我们想要的一种结果。当然做身份验证的方式有多种,今天给大家讲一种比较流行了,标准的身份验证JWT 什么是JWT?
|
算法 安全 Java
java对zip、rar、7z文件带密码解压实例
本文采用java语言实现了对zip和rar、7z文件的解压统一算法。并对比了相应的解压速度,支持传入密码进行在线解压。
2315 0
java对zip、rar、7z文件带密码解压实例
|
5月前
|
存储 算法 安全
JVM虚拟机篇
JVM虚拟机篇
388 0
|
网络协议 安全 网络安全
免费申请 HTTPS 证书的八大方法
免费申请 HTTPS 证书的八大方法
12418 0
|
运维 监控 Cloud Native
设计与构建 FinOps 流程、团队、体系与目标
企业 FinOps 实施不是一蹴而就的项目,如果您正在推进企业云原生 FinOps 落地,除了选择合适的技术手段,企业内部的流程和体系建设也尤为重要。
164564 104
|
SQL 存储 数据管理
SQL数据库的使用指南:从入门到精通
随着信息技术的飞速发展,数据库已成为各类企业和组织不可或缺的一部分。作为最流行的数据库管理系统之一,SQL数据库广泛应用于各种场景,如数据存储、数据管理、数据分析等。本文将详细介绍SQL数据库的使用方法,帮助初学者快速入门,并帮助有经验的开发者深化理解。一、SQL数据库基础首先,我们需要理解SQL数
600 2
|
NoSQL 关系型数据库 MySQL
Tomcat、MySQL、Redis最大支持说明
综上所述,Tomcat、MySQL、Redis的并发处理能力均非固定值,而是通过合理的配置与优化策略,结合系统硬件资源,共同决定了它们在实际应用中的表现。开发者应根据应用的具体需求和资源条件,对这些组件进行细致的调优,以达到最佳性能表现。
190 1
|
关系型数据库 MySQL 数据库
使用Docker搭建MySQL数据库服务
本文介绍了如何使用Docker搭建MySQL数据库服务。首先,通过`docker pull mysql:5.7`命令拉取MySQL 5.7镜像,然后运行`docker run`命令创建并启动容器。接着,使用`docker exec`进入容器并创建MySQL用户及授权。最后,通过MySQL客户端如Navicat测试连接,验证安装成功。Docker简化了MySQL的部署和管理,确保环境一致性。
|
存储 JSON 资源调度
next.js博客搭建_react-markdown渲染内容(第三步)
next.js博客搭建_react-markdown渲染内容(第三步)
526 1

热门文章

最新文章