Java 带弹簧靴和thymeleaf-i18n的Spring MVC 4不工作

Java 带弹簧靴和thymeleaf-i18n的Spring MVC 4不工作,java,spring-boot,spring-mvc,internationalization,thymeleaf,Java,Spring Boot,Spring Mvc,Internationalization,Thymeleaf,我试图在SpringMVC4中用SpringBoot制作一个简单的国际化示例,但它不起作用。这是我的web应用程序结构 下面是我的java配置: import java.util.Locale; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servle

我试图在SpringMVC4中用SpringBoot制作一个简单的国际化示例,但它不起作用。这是我的web应用程序结构

下面是我的java配置:

import java.util.Locale;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

@Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter
{
    @Bean
    public LocaleResolver localeResolver() {
        SessionLocaleResolver localeResolver = new SessionLocaleResolver();
        Locale defaultLocale = new Locale("en_US");
        localeResolver.setDefaultLocale(defaultLocale);
        return localeResolver;
    }

    @Bean
    public LocaleChangeInterceptor localeChangeInterceptor() {
        LocaleChangeInterceptor localeChangeInterceptor = new
                LocaleChangeInterceptor();
        localeChangeInterceptor.setParamName("lang");
        return localeChangeInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(localeChangeInterceptor());
    }
}
“我的胸腺”页:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport"
        content="width=device-width, initialscale=1, maximum-scale=1.0, user-scalable=no" />
    <title>Home</title>

    <!-- CSS Links -->
</head>
<body>
    <div class="container">
        <div class="row">
            <p th:text="#{welcome}">Hello</p>
        </div>
    </div>
</body>
</html>
当我点击localhost:8080/home时,它会打印出“欢迎光临”??。
我不知道我错过了什么。我发现有些人将basename写为“classpath:messages”,这是什么意思?我的意思是,我的项目结构不对,应该将属性文件放在其他地方吗?

因为没有人打算发布这个问题的答案,所以我发布了一个

(只是答案!)与你的问题有关

它表示您将默认语言(无论是否为英语)的消息放在messages.properties中,并为其他地区创建特定文件


如果messages.properties不适用于英语,那么为其创建一个messages\u en.properties文件。

添加一个
messages.properties
。您的项目结构似乎很好,
src/main/resources
是一个源文件夹,即
classpath
中的文件夹。我不明白这里有什么问题,您希望发生什么?以及实际输出是多少?正如M.Deinum提到的,如果您将文件messages.properties添加到资源中(文件甚至可能为空)它会启动Workththx…是的,你是正确的,正如D.M.DeNin所说,它现在工作得很好。但是,如果我可以问,为什么它需要,特别是我定义了一个默认区域来使用EnUUS属性文件?我应该删除EnUUS文件并考虑MeasAg.Stices默认英文(我是指为什么复制)?让我知道您使用的是什么版本的
Thymeleaf
?因为我使用的是相同的结构,它不适合我。
spring.messages.basename=messages
spring.messages.encoding=UTF-8