首页 > 其他分享 >Springboot项目部署时使用Mail注入Bean时的Constructor threw exception

Springboot项目部署时使用Mail注入Bean时的Constructor threw exception

时间:2024-09-12 10:14:58浏览次数:1  
标签:25 exception Springboot 465 端口 TCP Constructor 服务器 true

缘起:

今天打算把写了好一段时间的项目提溜到服务器上转转,然后在启动的时候就发现了个问题,在日志跑到【JobFactory set to: org.springframework.scheduling.quartz.SpringBeanJobFactory@31e7afde】的时候他就不动了,然后等了好一会他才抛出了个异常【org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.mail.MailSenderValidatorAutoConfi....】,然后前面还有个【Constructor threw exception】
大概就是构造器运行的时候出问题吧,这里直接说解决方案。


​ 这里的问题其实是因为STMP服务器连不上导致的,因为服务端的25端口是没有被放行的。

第一种解决方案

​ 所以第一种方案就昭然若揭,把25端口放了,但是这个放端口是需要申请的,看着比较麻烦

​ [TCP 25端口解封申请-阿里云帮助中心_-阿里云帮助中心 (aliyun.com)](https://help.aliyun.com/document_detail/56130.html#:~:text=出于安全考虑,阿里云默认封禁TCP 25端口出方向的访问流量,即您的阿里云云服务器无法通过TCP 25端口连接外部地址。 背景信息 TCP,25端口的出方向封禁可能影响您通过TCP 25 端口连接第三方邮件服务商的SMTP服务器对外部发送邮件。 如果您需要使用阿里云上的云服务器对外部发送邮件,建议您使用 阿里云邮 产品或者使用第三方邮件服务商提供的465端口。)

第二种解决方案

​ 第二种方案就是使用STMP服务器的另一个端口,即465

​ 像这样在application配置项中,把端口改成465,开启SSL即可

  mail:
    host: smtp.163.com
    protocol: smtp
    default-encoding: UTF-8
    username: [email protected]
    password: xxxxxxx
    test-connection: true
    properties:
      mail:
        smtp:
          auth: true
          starttls:
            enable: true
            required: true
          ssl:
            enable: true
          socketFactory:
            port: 465
            class: javax.net.ssl.SSLSocketFactory
    port: 465

标签:25,exception,Springboot,465,端口,TCP,Constructor,服务器,true
From: https://www.cnblogs.com/molu-sleep/p/18409627

相关文章