如何在thymeleaf中包含message.properties

我正在使用带百里香的弹簧靴。 这是我的项目结构: 在此处输入图像描述

这是我的App开始课程:

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

我在home.leaf.html上有这个:

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

我已经尝试了各种方法来解决此配置问题。 拜托,有人可以帮忙吗?

请参阅弹簧启动的官方文档

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 

因此,您可以将文件存储在resources文件夹内的locale文件夹中,名称为messages.properties或以任何特定语言。