简体   繁体   English

如何在Play Framework(Java)2.3.x中的application.conf文件中为键设置值

[英]How to set a value to a key in application.conf file in Play Framework (Java) 2.3.x

I have Play mailer configured on application.conf file with one email id . 我在application.conf文件中配置了具有一个电子邮件ID的Play邮件程序。 how can i change the email dynamically during run time ? 如何在运行时动态更改电子邮件? The idea is to configure multiple email IDs on a single play application . 这个想法是在一个播放应用程序上配置多个电子邮件ID。 eg ; 例如; for sales , the email must be sent from sale@abc.com and for purchase , purchase@abc.com 对于销售,必须从sale@abc.com发送电子邮件,对于购买,必须从purchase@abc.com发送电子邮件

smtp.host=smtp.zoho.com
smtp.port=465
smtp.ssl=true
smtp.user= "info@abc.com"
smtp.password= "something"

i can get the string value using Play.application().configuration().getString("smtp.host"); 我可以使用Play.application().configuration().getString("smtp.host");获得字符串值Play.application().configuration().getString("smtp.host"); ; ; how do we set it during run time ? 我们如何在运行时设置它?

Play Configuration wraps Typesafe Config , which is immutable. Play Configuration包装了Typesafe Config ,它是不可变的。 So you cannot modify a config after creation. 因此,创建后无法修改配置。 You can only create another config based on this one, overriding some properties. 您只能基于此配置创建另一个配置,从而覆盖某些属性。

The recipients of emails are set in your code, using the addTo method on a play.libs.mailer.Email object : https://github.com/playframework/play-mailer/blob/2.x/sample/app/controllers/ApplicationJava.java#L18 使用play.libs.mailer.Email对象上的addTo方法在您的代码中设置电子邮件的收件人: https : //github.com/playframework/play-mailer/blob/2.x/sample/app/controllers /ApplicationJava.java#L18

Not to be confused with the login and password of your SMTP provider. 不要与SMTP提供程序的登录名和密码混淆。 These are sets in application.conf : https://github.com/playframework/play-mailer/blob/2.x/sample/conf/application.conf#L65 这些是在application.conf中设置的: https : //github.com/playframework/play-mailer/blob/2.x/sample/conf/application.conf#L65

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM