类需要找不到类型为'java.lang.String'的bean

时间:2020-03-02 06:43:06

标签: java spring-boot java.lang.class

我尝试在Spring中进行邮件服务。我使用的是Spring-Boot版本2.1.7.Release和amazon-sqs-java-messaging-lib版本1.0.8。

我的代码如下:

    @Service
@RequiredArgsConstructor
public class MailService {

private static final Logger logger = Logger.getLogger(MailService.class.getName());
private final AmazonSQS amazonSQS;

@Value("${aws.sqs.queue.mail}")
private final String sqsQueueMail;

public void sendMail(final SQSMailParams mailParams) {

    final String queueUrl = amazonSQS.getQueueUrl(sqsQueueMail).getQueueUrl();

    try {
        final String messageBody = SQSMailParams.createSQSMailParams(mailParams, mailParams.getTemplateKey(), mailParams.getProcessId()).toJson();
        final SendMessageRequest sendMessageRequest = new SendMessageRequest(queueUrl, messageBody);
        sendMessageRequest.setMessageGroupId("TOLL-BOX-MAIL");

        amazonSQS.sendMessage(sendMessageRequest);
        logger.info("TOLL-BOX mail added to mail queue");
    } catch (JsonProcessingException e) {
        logger.error("Mail cannot be added to the mail queue: " + String.join(",", mailParams.recipients) + "." + e);
    }

    }
}

但是我通过运行代码遇到以下失败。

2020-03-02 07:34:00.242 ERROR 10568 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of constructor in de.svg.tollbox.service.MailService required a bean of type 'java.lang.String' that could not be found.


Action:

Consider defining a bean of type 'java.lang.String' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:43565', transport: 'socket'

Process finished with exit code 1

有人能告诉我我做错了什么吗?

1 个答案:

答案 0 :(得分:1)

final中删除sqsQueueMail

@Value("${aws.sqs.queue.mail}")
private String sqsQueueMail;

那应该可以解决您的问题。 不知何故,使用@RequiredArgsConstructor时,变量的@Value注释无法解析,这使应用程序查找类型为String的bean