我今天已经为此奋斗了几个小时。我从http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html#_sending_mails上的文档开始,它并没有真正说明具体步骤。它只是说开发人员可以包含一个 Bean XML,然后是 autowire MailSender
。我已经尝试了许多变体,但无法使用 spring-cloud-aws 让它工作。我终于求助于直接包含 aws-java-sdk-ses 并手动配置类。
这是一个简单的项目,展示了我的尝试: 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-mail ( 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 的依赖项(https://github.com/deinspanjer/aws-ses-test/tree/try-with-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
,但没有帮助。
我希望有人能够引导我朝着正确的方向前进。