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


相关文章
|
Java Spring
【Spring常见错误】Initialization failed for ‘https://start.spring.io‘
📋📋 精彩摘要:新建SpringBoot项目时,使用官网连接创建项目报错: Initialization failed for 'https://start.spring.io' Please check URL, network and proxy settings. 本文将提供两种解决方式参考。
8244 0
【Spring常见错误】Initialization failed for ‘https://start.spring.io‘
|
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
1015 0
Maven - Error:java: Annotation processing is not supported for module cycles. Please ensure that all
|
6月前
|
Kubernetes 容器
error: no configuration has been provided, try setting KUBERNET
error: no configuration has been provided, try setting KUBERNET
66 0
IDEA添加Swagger2:Parameter 0 of method linkDiscoverers in org. springframework hateoas.config.Hateoasconfiguration required a single bean, but 15 were found:
IDEA添加Swagger2:Parameter 0 of method linkDiscoverers in org. springframework hateoas.config.Hateoasconfiguration required a single bean, but 15 were found
|
3月前
Dependencies unknown
Dependencies unknown
28 0
|
6月前
|
JavaScript 前端开发
如何解决 Critical dependency: the request of a dependency is an expression ?
如何解决 Critical dependency: the request of a dependency is an expression ?
89 0
|
6月前
|
Java Maven 开发工具
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.3.RELEASE:repac
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.1.3.RELEASE:repac
48 0
|
NoSQL Java Redis
Unsatisfied dependency expressed through field /Injection of autowired dependencies failed 解决方法
根据报错的关键字,大底的意思就是依赖方面的问题。
340 0
Error creating bean with name ‘userServiceImpl‘: Unsatisfied dependency expressed through field ‘bas
Error creating bean with name ‘userServiceImpl‘: Unsatisfied dependency expressed through field ‘bas
418 0
ERROR: cuvid requested, but not all dependencies are satisfied: ffnvcodec
ERROR: cuvid requested, but not all dependencies are satisfied: ffnvcodec
111 0