Я боролся с этим в течение нескольких часов сегодня. Я начал с документации по адресу http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html#_sending_mails, в котором мало что говорится о конкретных шагах. Он просто говорит, что разработчик может включить XML-компонент Bean, а затем автоматически связать 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
, но это не помогло.
Я надеюсь, что кто-то сможет направить меня в правильном направлении.