gpt4 book ai didi

java - 消息源找不到 key

转载 作者:行者123 更新时间:2023-11-30 06:50:24 29 4
gpt4 key购买 nike

我有一个配置了以下消息源的项目:

 @Bean
public ReloadableResourceBundleMessageSource messageSource() {
final ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
source.setBasename("i18n/core/messages");
source.setDefaultEncoding("UTF-8");
source.setUseCodeAsDefaultMessage(true);
return source;
}

我想使用这个“核心”项目作为我的应用程序项目的库。消息在此核心中定义为资源。

在同一个核心项目中,我有一个@ControlerAdvice,它获取我的应用程序抛出的所有异常,如下所示:

@ExceptionHandler
public void unknownException(final Exception ex) {

if (ex instanceof StudioException){
throw (StudioException) ex;
}

final UUID uuid = UUID.randomUUID();
final String[] strings = {uuid.toString()};
String message = messageSource.getMessage("exception.not.identified",strings, LocaleContextHolder.getLocale());
final UnknownError unknownError = new UnknownError();
unknownError.setUuid(uuid.toString());
unknownError.setLogger(ExceptionUtils.getStackTrace(ex));
unknownErrorService.save(unknownError);
throw new StudioException(message);

问题是,当我使用核心项目作为应用程序项目的依赖项时,抛出异常,ExceptionHandler 被调用,但 messageSource 无法找到 key 。

我尝试使用“classpath:...”设置基本名称,我将核心中资源的目录结构更改为与应用程序项目不同,但没有成功。

这是我的 i18n 属性: Properties files

有谁知道我如何解决这个问题,在我的核心项目中拥有 key 和消息逻辑?

最佳答案

正如 surya 评论的:

try with setBasename("classpath:i18n/core/messages")

解决了问题。

关于java - 消息源找不到 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42926537/

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