java - 类需要一个找不到的“java.lang.String”类型的 bean
问题描述
我尝试在 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
有人可以告诉我我做错了什么谢谢。
解决方案
final
从中删除sqsQueueMail
。
@Value("${aws.sqs.queue.mail}")
private String sqsQueueMail;
那应该可以解决您的问题。不知何故,变量@RequiredArgsConstructor
的@Value
注释没有被解析,这使得应用程序寻找类型的 beanString
推荐阅读
- hyperledger-fabric - Implicit policy evaluation failed when creating a new channel
- jquery - jQuery id 选择器正在选择所有元素
- ios - 自 iOS 13 以来 - App Store Connect 中删除了很多应用程序,任何人都可以检查您的应用程序是否也发生这种情况
- sql - 如果第一行已在 SQL 中更新,则更新后续行数据
- c - mismatched comparison in XC8
- javascript - 如何让 React-Dates DayPicker 单个 DateController 使用自定义输入
- git - `git notes append` creates additional blank line
- c++11 - 是否可以根据二进制搜索来实现 std::lower_bound ?
- java - 使用自定义异常处理特定场景
- google-apps-script - 脚本 - DriveApp.getFilesByName - 获取最新版本?