首页 > 解决方案 > Spring boot + Spring mail:标准{PORT}问题

问题描述

您好,在我将 spring 邮件添加到我的应用程序后,我遇到了一个问题。这些是问题所在的 app.propreties。

spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true
server.port=${PORT}

这就是我在 EmailConfig 类中绑定它的方式

@Value("${spring.mail.port}")
    private int port;

这也是我正在使用的邮件

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
            <version>2.3.1.RELEASE</version>
        </dependency>

每次我启动应用程序时,我都会收到此错误:

Description:

Failed to bind properties under 'server.port' to java.lang.Integer:

    Property: server.port
    Value: ${PORT}
    Origin: class path resource [application.properties]:20:13
    Reason: failed to convert java.lang.String to java.lang.Integer

Action:

Update your application's configuration

出于某种原因,我似乎无法在基本的 8080 端口上发出请求。因此,我已将 server.port 修改为此server.port=${PORT:9191}并且它可以工作,但是由于某种原因,我的某些页面出现了一些请求问题。问题是,我在另一个应用程序上具有相同的配置,它无需我将端口修改为不同的数字即可工作。为什么会发生这种情况?我想留在标准港口。

任何帮助将不胜感激 !

标签: javaspringspring-bootjakarta-mail

解决方案


app.propertiesserver.port在您尝试访问的代码中拥有属性,该代码${spring.mail.port}为空。


推荐阅读