对于 WebSphere Liberty Profile,bootstrap.properties 文件中的反斜杠字符

For WebSphere Liberty Profile, backslash character inside bootstrap.properties file

我对 bootstrap.properties 文件中的“\”(反斜杠)字符有疑问。

我首先在 bootstrap.properties 文件中定义一个变量:

var1=AB\AC

然后,我在 server.xml 文件中定义了一个 jndiEntry:

<jndiEntry value="${var1}" jndiName="jndi/var1" id="var1">

当我在我的代码中查找 jndi 条目时,'\' 丢失了。如果我使用双反斜杠,即“\\”,那么我得到的是正斜杠,即 'AB/AC'.

如何输入'\'字符?

Liberty 将对所有变量执行路径规范化,除非该属性被定义为密码类型。目前解决这个问题的唯一方法是在 server.xml 而不是 bootstrap.properties 中包含反斜杠字符。

例如,在server.xml中:

<jndiEntry value="${var1}${var2}" jndiName="jndi/var1" id="var1">

bootstrap.properties:

var1=AB
var2=BC

根据 Liberty 文档,对位于 bootstrap.properties 文件

中的所有变量执行路径规范化

by replacing repeated forward and backward slashes with a single forward slash, unless the value starts with double forward or backward slashes, which remain unchanged.

然而,根据他们"Best practices" section:

If you need to set the value of a variable to contain repeated forward slashes, as are sometimes used for JDBC driver connection URLs, break the value into two parts at the double slashes. By placing the double forward slashes as the initial characters, normalization is avoided. For example, to store the value "jdbc:db2://host_name.com", use two variables:

URL_PART_1="jdbc:db2:" URL_PART_2="//host_name.com"