Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 弹簧靴&x2B;Thymeleaf找不到消息属性_Spring_Spring Boot_Thymeleaf_Properties File - Fatal编程技术网

Spring 弹簧靴&x2B;Thymeleaf找不到消息属性

Spring 弹簧靴&x2B;Thymeleaf找不到消息属性,spring,spring-boot,thymeleaf,properties-file,Spring,Spring Boot,Thymeleaf,Properties File,我正在尝试使用Spring Boot和Thymeleaf创建一个web应用程序,但在获取模板以使用属性文件中定义的消息时遇到了问题。而不是属性文件中定义的消息,而是显示?表单。欢迎使用控制台不会记录任何错误 项目结构是这样的 ──┬ I believe that changing the name of form.properties to messages.properties and locating it in the root of your resources folder shoul

我正在尝试使用Spring Boot和Thymeleaf创建一个web应用程序,但在获取模板以使用属性文件中定义的消息时遇到了问题。而不是属性文件中定义的消息,而是显示
?表单。欢迎使用
控制台不会记录任何错误

项目结构是这样的

──┬ I believe that changing the name of 
form.properties
to
messages.properties
and locating it in the root of your resources folder should allow spring boot to pick it up automagically.

When I have multiple message files I explicitly list them in a MessageSource bean so that the MVC auto-configuration picks them up, e.g.:

@Bean
public MessageSource messageSource() {
    final ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
    messageSource.setBasenames("classpath:/some-mvc-messages", "classpath:/some-other-mvc-messages", "classpath:/another-projects/mvc-messages");
    messageSource.setUseCodeAsDefaultMessage(true);
    messageSource.setDefaultEncoding("UTF-8");
    messageSource.setCacheSeconds(5);
    return messageSource;
}

──┬  我认为,将
form.properties
的名称更改为
messages.properties
,并将其定位在资源文件夹的根目录中,应该可以让spring boot自动获取它

当我有多个消息文件时,我会在MessageSourcebean中显式地列出它们,以便MVC自动配置将它们提取出来,例如:

 @SpringBootApplication
 @EnableAutoConfiguration
    public class Run {

        public static void main(String[] args) {
            SpringApplication.run(Run.class, args);
            System.out.println("Run");
        }

    }

我在使用messages.properties文件时遇到了相同的问题 问题是@EnableAutoConfiguration没有添加到我的Spring启动文件中


在添加了它的工作后

谢谢,我为消息源设置了basename,现在就可以工作了谢谢你的提示。我遇到了这样的问题:当作为jar文件运行时,Thymeleaf国际化消息不会得到解决,但在调试时会运行。添加这个Bean声明对我来说解决了这两种情况。谢谢!出于某种原因,我的
messages.properties
位于
src/main/resources
i18n
子目录中(可能遵循了许多关于Spring Boot+Thymeleaf+i18n的糟糕博文中的一条建议,这些博文告诉你要做太多的手动配置,而不是让Spring Boot为你做)。移动它修复了这个问题。这很奇怪,因为SpringBootApplication已经包含EnableAutoConfiguration。