简体   繁体   English

春季启动:带有外部messages.properties文件的ResourceBundle

[英]spring-boot: ResourceBundle with external messages.properties file

@Configuration
public class MessageSourceConfig {

    @Bean
    public static MessageSource messageSource() {
        ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
        messageSource.setBasename("file: c:/temp/messages");

        return messageSource;
    }
}

I am trying to make spring-boot to use my external messages.properties, messages_en_Us.properties files. 我正在尝试使spring-boot使用我的外部messages.properties,messages_en_Us.properties文件。 Unfortunately I get this error: 不幸的是我得到这个错误:

ResourceBundle [file: c:/temp/messages] not found for MessageSource: Can't find bundle for base name file: c:/temp/messages, locale en_US

Files are there and I have studied such cases and it is stated that this should work in spring-boot, but it doesn't. 文件已经存在,我已经研究了这种情况,并指出这应该在spring-boot中起作用,但事实并非如此。 I have also tried ReloadableResourceBundleMessageSource and failed the same way. 我也尝试过ReloadableResourceBundleMessageSource并以相同的方式失败。 What am I doing wrong here? 我在这里做错了什么?

Try that : 尝试:

messageSource.setBasename("file://c:/temp/messages");

Edit : 编辑:

After some tests in comments, it is rather this way of doing which works for the OP : 经过评论中的一些测试之后,OP才可以使用这种方法:

    messageSource.setBasename("file:C:/temp/messages");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot:添加了外部messages.properties但未使用 - Spring Boot: external messages.properties are being added but not used Spring Boot国际化(messages.properties) - Spring Boot internationalization (messages.properties) 春季启动-基于请求的不同messages.properties - Spring boot - different messages.properties based on request 如何在java包(Spring Boot)中加载`messages.properties`? - How to load `messages.properties` in java packages (Spring Boot)? 多模块 spring 启动项目messages.properties未加载 - Multi-Module spring boot project messages.properties is not loaded 如何在Seam 2中实现资源包(messages.properties)的热重装 - How to implement hot reloading of resourcebundle (messages.properties) in Seam 2 Spring ResourceBunddleMessageSource没有采用默认的messages.properties文件 - Spring ResourceBunddleMessageSource is not taking default messages.properties file 在 Spring 启动应用程序中传递常量消息的正确方法(messages.properties 或 Constant 类) - Proper way of passing constant messages in Spring boot application (messages.properties or Constant class) spring messages.properties使用变量名 - spring messages.properties uses variable name jrebel排除文件(messages.properties) - jrebel exclude file ( messages.properties )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM