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 + "!";
    }
}


相关文章
|
人工智能 NoSQL Java
【SpringAIAlibaba新手村系列】(8)持久化会话与 Redis 内存管理
本文详解 Spring AI 的会话记忆机制,从内存版 MemorySaver 到 Redis 版 RedisSaver,实现 AI 对话的上下文连续性。文章以 ReactAgent 为核心,讲解如何通过 threadId 管理会话线程,并将 Agent 状态持久化到 Redis 中。
2239 5
|
NoSQL 算法 Java
【工具类用法】Hutool里的生成唯一Id唯的工具类
【工具类用法】Hutool里的生成唯一Id唯的工具类
1924 0
|
2月前
|
弹性计算 运维 安全
阿里云服务器免费领取攻略:个人新用户3个月、学生1年,涵盖个人/学生/企业申领渠道、服务器配置及运维全流程实操指南
免费ECS为零预算群体打开了一扇接触云计算的大门:个人用户最长三个月、学生最长一年,从注册到上手全流程都不复杂。但免费终究有边界,额度和时间到了要么续要么释放,别让账单悄悄产生。拿到机器后第一件事做好安全加固,只开必要端口,把风险降到最低。然后尽情用这台免费算力去部署、去调试、去积累你的云端实战经验。
751 1
|
Java Maven
Maven - Error:java: Annotation processing is not supported for module cycles. Please ensure that all
Maven - Error:java: Annotation processing is not supported for module cycles. Please ensure that all
2654 0
Maven - Error:java: Annotation processing is not supported for module cycles. Please ensure that all
|
缓存 NoSQL Java
避免缓存失效的三大杀手:缓存击穿、穿透与雪崩的解决方案
避免缓存失效的三大杀手:缓存击穿、穿透与雪崩的解决方案
2128 0
|
安全 Java 数据库连接
Java报错javax.net.ssl.SSLException MESSAGE: closing inbound before receiving peer‘s close_notify解决方法
Java报错javax.net.ssl.SSLException MESSAGE: closing inbound before receiving peer‘s close_notify解决方法
Java报错javax.net.ssl.SSLException MESSAGE: closing inbound before receiving peer‘s close_notify解决方法
|
数据采集 存储
4个步骤:如何使用 SwiftSoup 和爬虫代理获取网站视频
本文介绍了如何使用SwiftSoup库和爬虫代理技术抓取网站视频资源。通过安装SwiftSoup、获取HTML内容、解析HTML以提取视频链接,以及设置爬虫代理来绕过访问限制,可以实现高效、灵活的视频资源获取。示例代码展示了一个完整的过程,包括下载并存储视频文件到设备。结合这两种技术,可以有效应对网站访问挑战,方便地获取互联网视频资源。
1169 3
4个步骤:如何使用 SwiftSoup 和爬虫代理获取网站视频
|
数据采集 存储 分布式计算
ClickHouse大规模数据导入优化:批处理与并行处理
【10月更文挑战第27天】在数据驱动的时代,高效的数据导入和处理能力是企业竞争力的重要组成部分。作为一位数据工程师,我在实际工作中经常遇到需要将大量数据导入ClickHouse的需求。ClickHouse是一款高性能的列式数据库系统,非常适合进行大规模数据的分析和查询。然而,如何优化ClickHouse的数据导入过程,提高导入的效率和速度,是我们面临的一个重要挑战。本文将从我个人的角度出发,详细介绍如何通过批处理、并行处理和数据预处理等技术优化ClickHouse的数据导入过程。
1928 0
|
JavaScript
npm报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
2105 1
|
消息中间件 Java RocketMQ
微服务架构师的福音:深度解析Spring Cloud RocketMQ,打造高可靠消息驱动系统的不二之选!
【8月更文挑战第29天】Spring Cloud RocketMQ结合了Spring Cloud生态与RocketMQ消息中间件的优势,简化了RocketMQ在微服务中的集成,使开发者能更专注业务逻辑。通过配置依赖和连接信息,可轻松搭建消息生产和消费流程,支持消息过滤、转换及分布式事务等功能,确保微服务间解耦的同时,提升了系统的稳定性和效率。掌握其应用,有助于构建复杂分布式系统。
646 0

热门文章

最新文章