2017-03-10 2 views
0

Spring Initializer、埋め込みTomcat、Thymeleafテンプレートエンジン、およびパッケージを実行可能なJARファイルとして使用して、Spring Boot Webアプリケーションを生成しました。使用SpringBootでのJavaMailSenderの使用

技術:私は「

春ブーツ1.4.2.RELEASE、春4.3.4.RELEASE、Thymeleaf 2.1.5.RELEASE、Tomcatの埋め込み8.5.6、Mavenの3、Javaの8

電子メール

@Service 
public class MailClient { 

    protected static final Logger looger = LoggerFactory.getLogger(MailClient.class); 

    @Autowired 
    private JavaMailSender mailSender; 

    private MailContentBuilder mailContentBuilder; 

    @Autowired 
    public MailClient(JavaMailSender mailSender, MailContentBuilder mailContentBuilder) { 
     this.mailSender = mailSender; 
     this.mailContentBuilder = mailContentBuilder; 
    } 

    //TODO: in a properties 
    public void prepareAndSend(String recipient, String message) { 
     MimeMessagePreparator messagePreparator = mimeMessage -> { 
      MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage); 
      messageHelper.setFrom("[email protected]"); 
      messageHelper.setTo(recipient); 
      messageHelper.setSubject("Sample mail subject"); 
      String content = mailContentBuilder.build(message); 
      messageHelper.setText(content, true); 
     }; 
     try { 
      if (looger.isDebugEnabled()) { 
       looger.debug("sending email to " + recipient); 
      } 
      mailSender.send(messagePreparator); 
     } catch (MailException e) { 
      looger.error(e.getMessage()); 
     } 
    } 
} 

を送信するには、このサービスを作成した。しかし、私はこのエラーを得たVEのときSpringBootApplication初期

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

Description: 

Binding to target [email protected]d11 failed: 

    Property: spring.mail.defaultEncoding 
    Value: UTF-8 
    Reason: Failed to convert property value of type 'java.lang.String' to required type 'java.nio.charset.Charset' for property 'defaultEncoding'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.nio.charset.Charset] 


Action: 

Update your application's configuration 

これは私のapplication.propertiesです

spring.mail.host=localhost 
spring.mail.port=25 
spring.mail.username= 
spring.mail.password= 
spring.mail.protocol=smtp 
spring.mail.defaultEncoding=UTF-8 

答えて

1

プロパティと同じ行にコメントを付けることはできません。 Everycommentは、エラーメッセージが

Value: 25 # SMTP server port 

を示す「#」 始まるので、値は文字列'25#SMTPサーバポートである」と整数に変換することができない独自の行になければなりません。

性質上、独自の行にコメントを移動:

# SMTP server port 
spring.mail.port=25 
関連する問題