【发布时间】:2021-07-09 16:43:19
【问题描述】:
我正在为 YAML 格式的配置文件尝试 Pebble 模板。此值来自另一个 YAML 文件。那就是——
- value.yml 包含:-
server:
-
box1:
host:"12345"
- config.yml 包含:-
server:
-
env: "abc"
host: {{ server.box1.host }}
我可以将 config.yml 读取为字符串并创建一个 Pebble 模板。使用评估,我可以用名称未嵌套的上下文变量替换模板(例如 {{ serverBox1Host }} --> 这有效)。
如果我使用 {{ server.box1.host }},我会得到 com.mitchellbosecke.pebble.error.RootAttributeNotFoundException: Root attribute [server] does not exist or can't be access and strict变量设置为真。 如果我将 strictVariables 设置为 false,则 {{ server.box1.host }} 将替换为空。
如何解决?
context.put("server.box1.host", "suriya" );
我参考了: https://www.programcreek.com/java-api-examples/?api=com.mitchellbosecke.pebble.PebbleEngine
我正在使用“字符串模板”:
new PebbleEngine.Builder()
.strictVariables(true)
.newLineTrimming(false)
.loader(new StringLoader())
.build();
谢谢
【问题讨论】: