gpt4 book ai didi

java - 找不到 MessageSource 的 ResourceBundle

转载 作者:行者123 更新时间:2023-11-30 08:21:34 25 4
gpt4 key购买 nike

我是 spring 的新手,现在我正在尝试使用 aplicationContext 执行 I18N 流程。我正在使用 Maven 模块化项目。我的项目包括以下子模块:

模型-myApp服务-myAppwebApp-myApp

services-MyApp
src/main/java
src/main/resources

在 services-myApp 资源文件夹中,我使用消息源声明了应用程序上下文

<!-- Need to I18N  -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="WEB-INF/lang/myFile"/>
</bean>

在 webApp 中我有 I18N 所需的文件

webApp-MyApp src/main/webapp/WEB-INF/lang/myFile_it_IT.properties

现在当我尝试获取消息时:

        String message = applicationContext.getMessage("myCode", null,null, Locale.ITALY);

我反而得到

WARN ResourceBundleMessageSource - ResourceBundle [/WEB-INF/lang/myFile] not found for MessageSource: Can't find bundle for base name /WEB-INF/lang/myFile, locale it_IT

并且消息为空。如果我将文件移动到 webApp 类路径 (/src/main/resources) 并将 messageSource 的值更改为 myFile 一切正常。

我该如何解决?

最佳答案

尝试使用 ReloadableResourceBundleMessageSource而不是 ResourceBundleMessageSource。它将查找 WEB-INF 下的文件。

关于java - 找不到 MessageSource 的 ResourceBundle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25121392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com