首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure ServiceBus:无法找到的“com.microsoft.azure.servicebus.ITopicClient”

Azure ServiceBus:无法找到的“com.microsoft.azure.servicebus.ITopicClient”
EN

Stack Overflow用户
提问于 2021-02-17 13:21:17
回答 1查看 380关注 0票数 0

在尝试运行应用程序时,我面临以下问题

2021-02-17T18:16:38.159+05:30 com.example.demo.service.ServiceBusProducer中构造函数的APP/PROC/WEB/0参数0需要一个无法找到的'com.microsoft.azure.servicebus.ITopicClient‘类型的bean。2021-02-17T18:16:38.159+05:30 APP/PROC/WEB/0注入点有以下注释:

2021-02-17T18:16:38.159+05:30 APP/PROC/WEB/0 - @org.springframework.beans.factory.annotation.Autowired(required=true)

2021-02-17T18:16:38.159+05:30 APP/PROC/WEB/0行动:

2021-02-17T18:16:38.159+05:30 APP/PROC/WEB/0考虑在配置中定义'com.microsoft.azure.servicebus.ITopicClient‘类型的bean。

我定义了如下所示的依赖项

代码语言:javascript
复制
<dependency>
    <groupId>com.microsoft.azure</groupId>
    <artifactId>azure-servicebus-spring-boot-starter</artifactId>
    <version>2.2.4</version>
</dependency>

下面是ServiceBusProducer.java类

代码语言:javascript
复制
package com.example.demo.service;

import com.microsoft.azure.servicebus.ITopicClient;
import com.microsoft.azure.servicebus.Message;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.Instant;

@Log4j2
@Component
@Service
public class ServiceBusProducer implements Ordered {

    @Autowired
    private ITopicClient iTopicClient;

    ServiceBusProducer(ITopicClient iTopicClient) {
        this.iTopicClient = iTopicClient;
    }

    @EventListener(ApplicationReadyEvent.class)
    public void produce() throws Exception {
        this.iTopicClient.send(new Message("Hello @ " + Instant.now().toString()));
    }

    @Override
    public int getOrder() {
        return Ordered.LOWEST_PRECEDENCE;
    }
}

我该如何解决这个问题?com.example.demo.service.ServiceBusProducer需要一个无法找到的'com.microsoft.azure.servicebus.ITopicClient‘类型的bean。

更新了代码,但是仍然面临相同的问题。

代码语言:javascript
复制
package com.example.demo.service;

import com.microsoft.azure.servicebus.ITopicClient;
import com.microsoft.azure.servicebus.Message;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.time.Instant;

@Log4j2
@Component
@Service
public class ServiceBusProducer implements Ordered {

   @Autowired
    private ITopicClient iTopicClient;

   ServiceBusProducer(ITopicClient iTopicClient) {
      this.iTopicClient = iTopicClient;
   }

   @PostConstruct
   private void postConstruct() {
      this.iTopicClient = iTopicClient;
   }

   @EventListener(ApplicationReadyEvent.class)
   public void produce() throws Exception {
      this.iTopicClient.send(new Message("Hello @ " + Instant.now().toString()));
   }

   @Override
   public int getOrder() {
      return Ordered.LOWEST_PRECEDENCE;
   }
}
EN

回答 1

Stack Overflow用户

发布于 2021-02-17 14:21:12

由于您没有提供公共默认构造函数,并且添加了您自己的非默认构造函数,实例化失败。

编辑:

看看类似的问题。您似乎必须初始化ITopicClient bean,否则就会出现命名问题。

添加命名覆盖可能会对此有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66242758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档