[英]How to escape "@" in properties file spring boot
我有一個 Spring Boot 應用程序,它連接到 salesforce 以從 salesforce 獲取數據並將數據推送到 SQL 服務器數據庫中。 我試圖從 application.properties 文件中獲取所有屬性。 我的密碼有@,因此在執行期間讀取該屬性時,我將“example”作為密碼而不是“example@country”
Eg :
Pwd = example@country
我檢查了一些有用的鏈接但沒有運氣,任何幫助表示贊賞
https://docs.oracle.com/cd/E23095_01/Platform.93/ATGProgGuide/html/s0204propertiesfileformat01.html
用於獲取配置道具的實用程序包。
package SFToJava.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
@Configuration
public class configUtility {
@Autowired
private Environment env;
public String getProperty(String pPropertyKey) {
return env.getProperty(pPropertyKey);
}
}
屬性文件:
password = example@country
我在我的服務類中獲取數據如下:
loginParams.add(new BasicNameValuePair("client_id",configUtil.getProperty("consumerKey")));
loginParams.add(new BasicNameValuePair("client_secret", configUtil.getProperty("consumerSecret")));
loginParams.add(new BasicNameValuePair("username", configUtil.getProperty("username")));
loginParams.add(new BasicNameValuePair("password", configUtil.getProperty("password")));
我希望密碼在解析到列表時應該有“example@country”,而不是只獲取“example”。
供參考。 可以直接使用如下密碼連接到 Salesforce
private static final String username = "******";
private static final String password = "example@coutnry";
private static final String consumerKey = "*************8";
private static final String consumerSecret = "************";
loginParams.add(new BasicNameValuePair("client_id", consumerKey));
loginParams.add(new
BasicNameValuePair("client_secret", consumerSecret));
loginParams.add(new
BasicNameValuePair("grant_type", "password"));
loginParams.add(new
BasicNameValuePair("username", username));
loginParams.add(new
BasicNameValuePair("password", password));
通常你不必轉義@
或者你可以在你的.properties
文件中使用轉義的\\\\@
:
mail.address=user\\@domain.com
但是我在使用它進行身份驗證時遇到了一些問題。 在這種情況下,您可能希望對@
使用編碼的%40
:
# replace @ in email with %40
mail.address=user%40domain.com
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.