【问题标题】:How to include message.properties with thymeleaf如何在 thymeleaf 中包含 message.properties
【发布时间】:2015-07-18 08:32:49
【问题描述】:

我正在使用带有百里香叶的弹簧靴。这是我的项目结构:

这是我的应用开始类:

    @EnableAutoConfiguration
@Configuration
@ComponentScan
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class);
    }
}

我的 home.leaf.html 上有这个:<p th:text = "#{username}"></p>

但是当我运行这个应用程序时,我得到的是:??username_en_US??

我尝试了各种方法来解决此配置问题。请问,谁能帮忙?

【问题讨论】:

  • 看来你需要配置你的消息源(设置spring会查找messages.properties的目录)
  • message.properties 重命名为messages.properties
  • 感谢@PedroAffonso 和 M. Deinum。首先我重命名为messages.properties,然后将其移到资源目录下,& Eureka!成功了!

标签: java spring spring-boot thymeleaf


【解决方案1】:

spring boot参考官方文档

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-convert-an-existing-application-to-spring-boot

它说

静态资源可以移动到/public(或/static/resources/META-INF/resources) 在类路径根目录中。相同的 messages.properties(Spring Boot 在 类路径的根目录)。

所以你应该将你的国际化文件创建为messages.properties 并放在根类路径中。

或者您也可以通过在application.properties 文件中添加此条目来将默认位置编辑到更合适的位置

#messages
spring.messages.basename=locale/messages

这样您就可以将文件存储在资源文件夹内的语言环境文件夹中,名称为 messages.properties 或任何特定语言。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-13
    • 2014-04-29
    • 1970-01-01
    • 2021-12-09
    • 2017-08-17
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多