英文:
Spring boot + Spring mail :Standard {PORT} issue
问题
你好,我在将 Spring 邮件功能添加到我的应用程序后遇到了问题。以下是出现问题的 app.properties 配置:
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>
每次启动应用程序时,我都会收到以下错误:
描述:
无法将属性绑定到 java.lang.Integer 下的 'server.port':
属性:server.port
值:${PORT}
来源:类路径资源 [application.properties]:20:13
原因:无法将 java.lang.String 转换为 java.lang.Integer
操作:
更新应用程序的配置
由于某种原因,似乎我无法在基本的 8080 端口上进行请求。因此,我将 server.port 修改为以下内容 server.port=${PORT:9191}
,这样可以工作,但由于某些原因,我的一些页面存在请求问题。奇怪的是,我在另一个应用程序中也使用了相同的配置,而且不需要将端口修改为不同的数字就可以正常工作。为什么会出现这种情况呢?我希望能够继续使用标准端口。
非常感谢您的帮助!
英文:
Hello i have an issue after i have added spring mail to my application.These are the app.propreties where the issue is.
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true
server.port=${PORT}
this is how i am binding it in the EmailConfig class
@Value("${spring.mail.port}")
private int port;
also this is the mail i am using
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
Every time i start the app i receive this error:
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
For some reason it seems that i cannot make requests on basic 8080 port.So i have modified the server.port to this server.port=${PORT:9191}
and it works but i get some requests issue with some of my pages for some reason.
Thing is , i have this same configuration on another application and it works without me having to modify the port to a different number.Why is this happening? i would like to remain on standard port.
Any help would be greatly appreciated !
答案1
得分: 1
app.properties
文件中有一个server.port
属性,而在代码中你试图访问${spring.mail.port}
,但该值为空。
英文:
app.properties
have server.port
property while in the code you try to access ${spring.mail.port}
which is empty.
答案2
得分: 1
如果您想保持在标准端口上,从您的 application.properties 文件中删除 server.port
这一行(这样它将在 8080 端口上运行)。
server.port
- 用于配置应用程序在非标准端口上运行的设置。
spring.mail.port
- 用于配置 SMTP 服务器端口。如果您的 SMTP 服务器使用标准端口,则不需要配置此属性。
具有相同配置的其他应用程序将在环境变量或系统属性中设置 PORT 值。无法在不为 PORT 变量分配任何值的情况下运行应用程序,因为它是配置参数。
英文:
If you want to remain on standard port, remove the line server.port from your application.properties (so it runs on 8080).
server.port
- used to configure the application to run in different port other than standard port.
spring.mail.port
- used to configure smtp server port. If your SMTP server is using standard port, you don't need to configure this property.
The other application that has the same configuration would have the PORT value set in either environment variables or system properties. It's not possible to run the application without assigning any value to PORT variable as it is a configuration parameter.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论