昨天还好好的,突然就不行了。我没有改变任何东西。我是JMS的新手,并遵循了此教程:Tutorial
我只想使用Azure服务总线发送和接收消息。
错误信息:
Field jmsTemplate in com.example.messagesender.MessageSenderApplication required a bean of type 'org.springframework.jms.core.JmsTemplate' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
字符串
操作:
考虑在您的配置中定义一个类型为'org.springframework.jms.core.JmsTemplate'的bean。
Pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-starter-servicebus-jms</artifactId>
<version>6.0.0-beta.4</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-messaging-servicebus</artifactId>
<version>7.14.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jms -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.jms/javax.jms-api -->
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.messaginghub</groupId>
<artifactId>pooled-jms</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-dependencies</artifactId>
<version>5.3.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
型
Java文件:
@SpringBootApplication
@EnableJms
public class MessageSenderApplication implements CommandLineRunner {
private static final Logger LOGGER = LoggerFactory.getLogger(MessageSenderApplication.class);
private static final String QUEUE_NAME = "queue";
@Autowired
private JmsTemplate jmsTemplate;
public static void main(String[] args) {
SpringApplication.run(MessageSenderApplication.class, args);
}
@Override
public void run (String...args){
LOGGER.info("Sending message");
jmsTemplate.convertAndSend(QUEUE_NAME, "Hello World");
}
@JmsListener(destination = QUEUE_NAME, containerFactory = "jmsListenerContainerFactory")
public void receiveMessage (String message){
LOGGER.info("Message received: {}", message);
}
}
型
就像在教程中一样。
我会很感激你的帮助。谢谢你,谢谢
1条答案
按热度按时间esyap4oy1#
您应该在@Configuration文件中创建一个bean,但接收一个工厂作为参数。
字符串