Java “如何逃离”@&引用;在属性文件spring boot中

Java “如何逃离”@&引用;在属性文件spring boot中,java,spring-boot,properties-file,Java,Spring Boot,Properties File,我有一个spring boot应用程序,它连接到salesforce,从salesforce获取数据并将数据推送到SQL server DB中。 我正在尝试从application.properties文件获取所有属性。 我的密码有@,因此在执行过程中读取该属性时,我的密码是“example”,而不是“example”example@country" 我检查了一些有用的链接,但没有运气,任何帮助都是感激的 获取配置道具的实用程序包 package SFToJav

我有一个spring boot应用程序,它连接到salesforce,从salesforce获取数据并将数据推送到SQL server DB中。 我正在尝试从application.properties文件获取所有属性。 我的密码有@,因此在执行过程中读取该属性时,我的密码是“example”,而不是“example”example@country"

我检查了一些有用的链接,但没有运气,任何帮助都是感激的

获取配置道具的实用程序包

                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而不是只获取“示例”

仅供参考。我可以直接使用下面的密码连接到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));

通常,您不必转义
@
,也可以在
属性文件中使用转义的
\\@

mail.address=user\\@domain.com
但我在使用它进行身份验证时遇到了一些问题。在这种情况下,您可能希望将编码的
%40
用于
@

# replace @ in email with %40
mail.address=user%40domain.com

您是否尝试过
\@
或\\@?您使用的是哪个版本的spring boot?我不必转义
@
字符。它适用于
@
\@
。使用spring boot 2.1.4.Am和2.1.6进行测试,我尝试了\@和\ \@两种方法,但得到的错误是:此行有多个标记-在'@'处缺少换行符-在'\'处缺少换行符-'用户名'是未知属性
# replace @ in email with %40
mail.address=user%40domain.com