我有一個實用程序類,它具有與電子郵件發件人相關的常用配置,配置根據環境如Staging
和Production
進行更改。現在我該如何動態選擇基於環境的配置?如何根據JAVA環境動態選擇配置?
這裏是我的代碼,
EmailUtility.java
package com.housecar.common;
public class EmailUtility {
//For staging
public static final String FROM_EMAIL_ID = "[email protected]";
public static final String FROM_NAME = "xyz";
static final String SMTP_USERNAME = "[email protected]";
static final String SMTP_PASSWORD = "15sss67$";
public static final String REPLY_EMAIL_ID = "[email protected]";
public static final String MAIL_SMTP_PORT = "587";
public static final String MAIL_SMTP_SOCKET_FACTORY_PORT = "587";
public static final String SMTP_HOST = "smtp.gmail.com";
public static final String MAIL_SMTP_SOCKETFACTORY_CLASS = "javax.net.ssl.SSLSocketFactory";
//for production
/*public static final String FROM_EMAIL_ID = "[email protected]";
public static final String FROM_NAME = "xyz";
static final String SMTP_USERNAME = "AKYeeeELEQAGAA"; // Replace with
// your SMTP
// username.
static final String SMTP_PASSWORD = "gvwwwwwbgpGm/C/LmUYUK5HosQar7mTSwjl5MFeBRR";
public static final String REPLY_EMAIL_ID = "[email protected]";
public static final String MAIL_SMTP_PORT = "587";
public static final String MAIL_SMTP_SOCKET_FACTORY_PORT = "587";
public static final String SMTP_HOST = "email-smtp.us-east-1.amazonaws.com";
public static final String MAIL_SMTP_SOCKETFACTORY_CLASS = "javax.net.ssl.SSLSocketFactory";*/
}
在我的代碼,我手動註釋掉的配置!
你應該看看屬性文件。 –
你有沒有使用任何屬性文件或類似的東西。 ?? –
什麼是動態的?在運行應用程序時更改配置還是僅僅通過啓動? – Patrick