Spring Boot JMS侦听器-org.springframework.jms.config.JmsListenerEndpointRegistry.isAutoStartup()Z

时间:2019-04-05 06:10:33

标签: java amazon-sqs spring-jms

我已经设置了一个JmsListener来从sqs队列中读取消息。 首先,我创建了如下配置类来设置ConnectionFactory和JMSTemplate

 @Configuration
 @EnableJms
 public class SQSJmsConfig {
 private AWSCredentialsProvider awsCredentialsProvider;

 @Value("${aws.ses.accessKey}")
 private String accessKey;

 @Value("${aws.ses.secretKey}")
 private String secretKey;

 @Bean
 public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
    AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
    awsCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);

    SQSConnectionFactory sqsConnectionFactory = new SQSConnectionFactory(new ProviderConfiguration(),
            AmazonSQSClientBuilder.standard().withRegion(Regions.US_EAST_1).withCredentials(awsCredentialsProvider));

    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(sqsConnectionFactory);
    factory.setDestinationResolver(new DynamicDestinationResolver());
    factory.setConcurrency("3-10");
    factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
    return factory;
}

@Bean
public JmsTemplate defaultJmsTemplate() {
    AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
    awsCredentialsProvider = new AWSStaticCredentialsProvider(awsCredentials);

    SQSConnectionFactory sqsConnectionFactory = new SQSConnectionFactory(new ProviderConfiguration(),
            AmazonSQSClientBuilder.standard().withRegion(Regions.US_EAST_1).withCredentials(awsCredentialsProvider));

    return new JmsTemplate(sqsConnectionFactory);
 }
}

然后我创建了一个JmsListener方法来从sqs队列中读取消息

@Service
public class SQSQueueService {
private static final Logger log = LoggerFactory.getLogger(SQSQueueService.class);

@JmsListener(destination = "${aws.sqs.queueName}")
public void readPlan(SQSEmailStatusQueue sqsEmailStatusQueue) {
    try {
        log.info("SNS notification received from SQS queue");
        String message = sqsEmailStatusQueue.getMessage();
        System.out.println(message);
    } catch (Exception e) {
        log.error(e.getMessage());
    }
 }
}

之后,当我运行项目时,出现以下异常

  

java.lang.AbstractMethodError:org.springframework.jms.config.JmsListenerEndpointRegistry.isAutoStartup()Z

此异常的原因是什么?

2 个答案:

答案 0 :(得分:0)

问题出在依赖项上。

`<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jms</artifactId>
    <version>5.1.6.RELEASE</version>
</dependency>`

我从中删除了版本。然后它起作用了。 有人可以解释一下为什么会这样吗?

答案 1 :(得分:0)

如果您的应用程序使用spring-boot-starter-parent并另外取决于:

,则可能发生失败。
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jms</artifactId>
  <version>${spring.jms.version}</version>
</dependency>

利用父级提供的这种依赖关系:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-activemq</artifactId>
</dependency>