${site.name} incorrectly replaced
Version and maven dependencies
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.2.0.RELEASE</version>
</dependency>
Use current version of code:
//spring 引入
import org.springframework.util.PropertyPlaceholderHelper;
//我的引入
//import com.litb.auto.zeus.propexec.PropertyPlaceholderHelper;
import java.util.Properties;
public class TestProp {
public static void main(String[] args) {
String originalValue = "spring.eldal.${site.name}.datasource.master.jdbcUrl=jdbc:mysql://${${site.name}_inbox_master.master.jdbcUrl}/${site.name}_inbox_master?useSSL=false&autoReconnect=true&allowMultiQueries=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull";
Properties props = new Properties();
props.setProperty("site.name", "foo_value");
// props.setProperty("foo_value_inbox_master.master.jdbcUrl", "foo_value");
PropertyPlaceholderHelper helper =
new PropertyPlaceholderHelper(
"${", "}");
String resolvedValue = helper.replacePlaceholders(originalValue, props);
// resolvedValue = helper.replacePlaceholders(resolvedValue, props);
// System.out.println("Original value: " + originalValue);
System.out.println("Resolved value: " + resolvedValue);
}
}
Resolved value:
spring.eldal.foo_value.datasource.master.jdbcUrl=jdbc:mysql://${${site.name}_inbox_master.master.jdbcUrl}/foo_value_inbox_master?useSSL=false&autoReconnect=true&allowMultiQueries=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
Using my modified code:
//spring 引入
//import org.springframework.util.PropertyPlaceholderHelper;
//我的引入
import com.litb.auto.zeus.propexec.PropertyPlaceholderHelper;
import java.util.Properties;
public class TestProp {
public static void main(String[] args) {
String originalValue = "spring.eldal.${site.name}.datasource.master.jdbcUrl=jdbc:mysql://${${site.name}_inbox_master.master.jdbcUrl}/${site.name}_inbox_master?useSSL=false&autoReconnect=true&allowMultiQueries=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull";
Properties props = new Properties();
props.setProperty("site.name", "foo_value");
// props.setProperty("foo_value_inbox_master.master.jdbcUrl", "foo_value");
PropertyPlaceholderHelper helper =
new PropertyPlaceholderHelper(
"${", "}");
String resolvedValue = helper.replacePlaceholders(originalValue, props);
// resolvedValue = helper.replacePlaceholders(resolvedValue, props);
// System.out.println("Original value: " + originalValue);
System.out.println("Resolved value: " + resolvedValue);
}
}
Resolved value:
spring.eldal.foo_value.datasource.master.jdbcUrl=jdbc:mysql://${foo_value_inbox_master.master.jdbcUrl}/foo_value_inbox_master?useSSL=false&autoReconnect=true&allowMultiQueries=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
in the code IndexOf is changed to lastIndexOf
Comment From: anii1827
I would like to work on this issue!
Comment From: cloudmisst
You can use me to modify this file first, download this file to the local project, and select my file when importing.
Comment From: snicoll
Thanks for the report. Please move that all code in text in a small sample that we can run ourselves. You can do that by attaching a zip to this issue or pushing the code to a GitHub repository.
Comment From: cloudmisst
demo.zip has been uploaded, any advice is welcome, thank you!
Thanks for the report. Please move that all code in text in a small sample that we can run ourselves. You can do that by attaching a zip to this issue or pushing the code to a GitHub repository.
Comment From: snicoll
Can you remove all the noise there? The expression does not need to be that complex to reproduce what you're trying to describe. I am not sure if you're reporting a bug or if you have a question. Unfortunately, we need the report to be actionable before being able to spend time on it. Changing from indexOf
to lastIndexOf
might not be the right move.
Comment From: cloudmisst
Can you remove all the noise there? The expression does not need to be that complex to reproduce what you're trying to describe. I am not sure if you're reporting a bug or if you have a question. Unfortunately, we need the report to be actionable before being able to spend time on it. Changing from to might not be the right move.
indexOf``lastIndexOf
I have removed the redundant code and supplemented the relevant issue description.Thank you!
Comment From: snicoll
Thanks for the additional detail.
My understanding is that there should be a complete replacement here rather than missing one ${site.name}
foo_value_inbox_master.master.jdbcUrl
is not specified. If you specify it, it is replaced as expected. If you create the helper to not ignore unresolved property placeholder then you get the following:
Exception in thread "main" java.lang.IllegalArgumentException: Could not resolve placeholder 'foo_value_inbox_master.master.jdbcUrl' in value "spring.eldal.${site.name}.datasource.master.jdbcUrl=jdbc:mysql://${${site.name}_inbox_master.master.jdbcUrl}/${site.name}_inbox_master?useSSL=false&autoReconnect=true&allowMultiQueries=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:112)
at com.example.demo.propexec.TestPropError.main(TestPropError.java:23)
Comment From: cloudmisst
感谢您提供额外的细节。
我的理解是,这里应该有一个完整的替代品,而不是缺少一个${site.name}
foo_value_inbox_master.master.jdbcUrl
未指定。如果指定它,则会按预期替换它。如果创建帮助程序不忽略未解析的属性占位符,则会得到以下结果:
Exception in thread "main" java.lang.IllegalArgumentException: Could not resolve placeholder 'foo_value_inbox_master.master.jdbcUrl' in value "spring.eldal.${site.name}.datasource.master.jdbcUrl=jdbc:mysql://${${site.name}_inbox_master.master.jdbcUrl}/${site.name}_inbox_master?useSSL=false&autoReconnect=true&allowMultiQueries=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull" at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178) at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:112) at com.example.demo.propexec.TestPropError.main(TestPropError.java:23)
This is not an overlooked issue, I don't want to check the configuration The correct result I need should be as follows: spring.eldal.foo_ Value. datasource. master. jdbcUrl=jdbc: mysql://${foo_value inbox_master. master. jdbcUrl}/foo_ Value_ Inbox_ Master? UseSSL=false&autoReconnect=true&allowMultiQueries=true&characterEncoding=utf8&zeroDateTimeBehavior=convertTonull
Comment From: cloudmisst
感谢您提供额外的细节。
我的理解是,这里应该有一个完整的替代品,而不是缺少一个${site.name}
foo_value_inbox_master.master.jdbcUrl
未指定。如果指定它,则会按预期替换它。如果创建帮助程序不忽略未解析的属性占位符,则会得到以下结果:
Exception in thread "main" java.lang.IllegalArgumentException: Could not resolve placeholder 'foo_value_inbox_master.master.jdbcUrl' in value "spring.eldal.${site.name}.datasource.master.jdbcUrl=jdbc:mysql://${${site.name}_inbox_master.master.jdbcUrl}/${site.name}_inbox_master?useSSL=false&autoReconnect=true&allowMultiQueries=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull" at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178) at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:112) at com.example.demo.propexec.TestPropError.main(TestPropError.java:23)
This is not an overlooked issue, I don't want to check the configuration The correct result I need should be as follows: spring.eldal.foo_ Value. datasource. master. jdbcUrl=jdbc: mysql://${foo_value inbox_master. master. jdbcUrl}/foo_ Value_ Inbox_ Master? UseSSL=false&autoReconnect=true&allowMultiQueries=true&characterEncoding=utf8&zeroDateTimeBehavior=convertTonull