使用 spring-cloud-azure-starter-servicebus-jms 连接到 Azure 服务总线

问题描述 投票:0回答:0

我正在尝试遵循有关使用 spring-cloud-azure-starter-servicebus-jms 连接到 azure 服务总线的 Microsoft 文档。

Ref 但没有运气 .

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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.4</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.demo</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.3-SNAPSHOT</version>
    <name>springcloud-servicebus-1</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.azure.spring</groupId>
            <artifactId>spring-cloud-azure-starter-servicebus-jms</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.azure.spring</groupId>
                <artifactId>spring-cloud-azure-dependencies</artifactId>
                <version>4.6.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Java代码

package com.example.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsTemplate;

@SpringBootApplication
@EnableJms
public class Sample implements CommandLineRunner {

    private static final Logger LOGGER = LoggerFactory.getLogger(Sample.class);
    private static final String TOPIC_NAME = "loan-app";
    private static final String SUBSCRIPTION_NAME = "loan-app-sub";

    @Autowired
    private JmsTemplate jmsTemplate;

    public static void main(String[] args) {
        SpringApplication.run(Sample.class, args);
    }

    @Override
    public void run(String... args) {
        LOGGER.info("Sending message");
        jmsTemplate.convertAndSend(TOPIC_NAME, "Hello Word");
    }

    @JmsListener(destination = TOPIC_NAME, containerFactory = "topicJmsListenerContainerFactory", subscription = SUBSCRIPTION_NAME)
    public void receiveMessage(String message) {
        LOGGER.info("Message received: {}", message);
    }

}

错误:


应用程序启动失败


描述:

com.example.demo.Sample 中的字段 jmsTemplate 需要一个无法找到类型为“org.springframework.jms.core.JmsTemplate”的 bean。

注入点有如下注解: - @org.springframework.beans.factory.annotation.Autowired(required=true)

spring-cloud spring-jms spring-cloud-azure
© www.soinside.com 2019 - 2024. All rights reserved.