【问题标题】:How to access application.properties from freemarker template如何从 freemarker 模板访问 application.properties
【发布时间】:2021-07-27 01:38:14
【问题描述】:

在freemarker模板中,我们可以像这样访问spring messages.properties

messages.properties:

...
my.message=foo
...

example.ftl:

<@spring.message 'my.messsage'/>

输出:

foo

有没有办法对 application.properties 和其他活动配置文件中定义的属性做同样的事情?尝试以相同的方式访问产生了以下错误:

No message found under code 'my.prop' for locale 'xx_XX'

编辑: 我已经看到了一些对依赖项进行额外配置的示例,但我正在寻找一种更简单的方法,因为这些建议会严重影响当前代码

【问题讨论】:

    标签: spring-boot templates freemarker properties-file


    【解决方案1】:

    是的,您只需在它们前面加上他们的参考或其他......

    所以不是 my.message,它可能是 app.someProperty

    【讨论】:

    • 这是否意味着在我的示例中,如果我在application.properties 中有my.property,它将是app.my.property
    猜你喜欢
    • 2016-05-01
    • 2015-09-11
    • 2012-05-22
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    • 2013-02-24
    相关资源
    最近更新 更多