春季本地化的一些问题



mymessages_en.properties:

title=Backpack Content
list.book=Book
list.water=Water
current.locale=Current locale
list.sweater=Sweater
list.cookies=Cookies

我的配置:

@Configuration
public class ApplConf implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
@Bean
public LocaleResolver localeResolver(){
return new SessionLocaleResolver();
}

private LocaleChangeInterceptor localeChangeInterceptor(){
var loc = new LocaleChangeInterceptor();
loc.setParamName("lang");
return loc;
}
}

我的文件名为";欢迎ftlh";

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<#import "/spring.ftl" as spring>
<h1> <@spring.message "title" /></h1>
<ul>
<li><@spring.message "list.cookies" /></li>
<li><@spring.message "list.sweater" /></li>
<li><@spring.message "list.book" /></li>
<li><@spring.message "list.water" /></li>
</ul>
<hr>
<p><@spring.message "current.locale" />: ${.locale}</p>
</body>
</html>

控制器:

@RequestMapping("/welcomePage")
public String hello(){
return "welcome";
}

我搜索了localhost:11314/welcomePage,还尝试了localhost:1314/welcomePage?lang=en-GB,但它只显示:

FreeMarker模板错误(调试模式;在生产中使用RETHROW!(:Java方法;org.springframework.web.servlet.support.RequestContext.getMessage(String("在org.springframework.web.servlet.support.RequestContext对象上调用时引发异常"org.springframework.web.servlet.support.RequestContext@63511cca";请参阅Java堆栈跟踪中的原因异常。----FTL堆栈跟踪("~"表示与嵌套相关(:-失败于:${springMacroRequestContext.getMessag…[在第28行第22列的模板"spring.FTL"中的宏"消息"中]-通过:@spring.message"title"[在第9行第6列的模板中的welcome.ftlh]中]----Java堆栈跟踪(适用于程序员(:----freemarker.core_TemplateModelException:[…已打印异常消息;请参阅上面的内容…]

配置application.yml

spring:
messages:
basename: org/springframework/security/messages, yourPath/messages

相关内容

  • 没有找到相关文章

最新更新