今天我一直为此奋战了几个小时。我从http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html#_sending_mails的文档开始,对于具体步骤并没有多少说明。它只是说开发人员可以包含一个Bean XML,然后自动装载MailSender
。我已经尝试过以及许多变体,并且无法使用spring-cloud-aws进行工作。我终于采取直接包括aws-java-sdk-ses并手动配置类。通过AWS SES让Spring Boot应用程序发送简单的电子邮件需要什么配置步骤?
下面是一个简单的项目证明什么,我已经试过: https://github.com/deinspanjer/aws-ses-test
该项目编译,但是当我运行它,我得到:
Parameter 0 of constructor in com.example.awssestest.AwsSesTestApplication required a bean of type 'org.springframework.mail.MailSender' that could not be found.
- Bean method 'mailSender' not loaded because @ConditionalOnClass did not find required class 'javax.mail.internet.MimeMessage'
- Bean method 'simpleMailSender' not loaded because @ConditionalOnClass did not find required class 'com.amazonaws.services.simpleemail.AmazonSimpleEmailService'
- Bean method 'javaMailSender' not loaded because @ConditionalOnClass did not find required class 'com.amazonaws.services.simpleemail.AmazonSimpleEmailService'
如果我尝试添加的javax邮件(https://github.com/deinspanjer/aws-ses-test/tree/try-with-javax-mail-api ),则错误更改:
Parameter 0 of constructor in com.example.awssestest.AwsSesTestApplication required a bean of type 'org.springframework.mail.MailSender' that could not be found.
- Bean method 'mailSender' not loaded because AnyNestedCondition 0 matched 2 did not; NestedCondition on MailSenderAutoConfiguration.MailSenderCondition.JndiNameProperty @ConditionalOnProperty (spring.mail.jndi-name) did not find property 'jndi-name'; NestedCondition on MailSenderAutoConfiguration.MailSenderCondition.HostProperty @ConditionalOnProperty (spring.mail.host) did not find property 'host'
- Bean method 'simpleMailSender' not loaded because @ConditionalOnClass did not find required class 'com.amazonaws.services.simpleemail.AmazonSimpleEmailService'
- Bean method 'javaMailSender' not loaded because @ConditionalOnClass did not find required class 'com.amazonaws.services.simpleemail.AmazonSimpleEmailService'
相反,如果我尝试显式的增加在AWS上的Java-SDK-SES(依赖),我得到这个错误,而不是:
Parameter 0 of constructor in com.example.awssestest.AwsSesTestApplication required a bean of type 'org.springframework.mail.MailSender' that could not be found.
- Bean method 'mailSender' not loaded because @ConditionalOnClass did not find required class 'javax.mail.internet.MimeMessage'
- Bean method 'javaMailSender' in 'MailSenderAutoConfiguration' not loaded because @ConditionalOnClass did not find required class 'javax.mail.Session'
- Bean method 'simpleMailSender' in 'MailSenderAutoConfiguration' not loaded because @ConditionalOnMissingClass found unwanted class 'org.springframework.cloud.aws.mail.simplemail.SimpleEmailServiceJavaMailSender'
对于这个错误,我尝试添加一个@Qualifier("simpleMailSender")
注释到@Autowired
,但它并没有帮助。
我希望有人能够引导我走向正确的方向。
看起来您缺少在AwsSesTestApplication类中导入@ImportResource(“/ aws-mail.xml”)。 – skadya
我只是尝试将该注释添加到应用程序类,但它不会更改错误消息。 – deinspanjer