春季启动+春季邮件:标准{PORT}问题

时间:2020-09-20 19:13:28

标签: java spring spring-boot jakarta-mail

您好,我将Spring Mail添加到我的应用程序后遇到了问题。这些是问题所在的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}并可以使用,但是由于某些原因,我的某些页面出现了一些请求问题。 问题是,我在另一个应用程序上具有相同的配置,并且无需将端口修改为其他编号即可正常工作。为什么会这样?我想保留在标准端口上。

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:1)

app.properties具有server.port属性,而您在代码中尝试访问为空的${spring.mail.port}

答案 1 :(得分:1)

如果要保留在标准端口上,请从application.properties中删除server.port行(以便它在8080上运行)。

server.port-用于将应用程序配置为在标准端口以外的其他端口上运行。

spring.mail.port-用于配置smtp服务器端口。如果您的SMTP服务器使用标准端口,则无需配置此属性。

具有相同配置的另一个应用程序将在环境变量或系统属性中设置PORT值。如果不为PORT变量分配任何值,则无法运行该应用程序,因为它是配置参数。