我尝试使用将一个属性引用到 messages.properties 中的另一个属性。 在网上寻找答案时大多是这样回答的:
referenced.text.property=Some text
new.text.property=${referenced.text.property}
但它仅输出“${referenced.text.property}”,在 thymeleaf 中不带引号。 此代码仅适用于 application.properties
订单很重要!
你需要有
referenced.text.foo
之前 new.text.foo
示例:https://github.com/NoraUi/NoraUi/blob/master/src/test/resources/UnitTest4CLI.properties
在java中你可以编写这个命令:
protected static Properties initPropertiesFile(ClassLoader loader, String propertiesFileName) {
if (loader != null) {
final InputStream in = loader.getResourceAsStream(propertiesFileName);
final Properties props = new Properties();
try {
if (in == null) {
log.error(Messages.getMessage(CONTEXT_PROPERTIES_FILE_NOT_FOUND), propertiesFileName);
} else {
log.info("Reading properties file ({}).", propertiesFileName);
props.load(in);
}
} catch (final IOException e) {
log.error("error Context.initPropertiesFile()", e);
}
log.info("Loaded properties from {} = {}.", propertiesFileName, props);
return props;
}
return null;
}
Springboot:
--spring.config.location=your/path/application.yml
Maven:
<filters>
<filter>src/main/resources/messages.properties</filter>
</filters>