简体   繁体   English

Spring-boot ReloadableResourceBundleMessageSource 不工作

[英]Spring-boot ReloadableResourceBundleMessageSource not working

I have created a class TestReloadableResourceBundleMessageSource by extending ReloadableResourceBundleMessageSource in my application and implemented like this.我创建了一个类TestReloadableResourceBundleMessageSource通过扩展ReloadableResourceBundleMessageSource在我的应用程序和这样的实现。

public class TestReloadableResourceBundleMessageSource extends ReloadableResourceBundleMessageSource {

//....
}


@Bean
public TestReloadableResourceBundleMessageSource messageSource() {

    String messagesPath = "C:/messages";

    TestReloadableResourceBundleMessageSource messageSource = new  TestReloadableResourceBundleMessageSource();
    messageSource.setBasename("file:" + messagesPath);
    messageSource.setCacheSeconds(0);
    messageSource.setDefaultEncoding(Charsets.UTF_8.name());

    return messageSource;
  }

But when I'm changing the properties file values, save and reload the page I'm getting the old values not new values without restarting the server.但是,当我更改属性文件值时,保存并重新加载页面时,我会在不重新启动服务器的情况下获得旧值而不是新值。

My properties files are not in class path.我的属性文件不在类路径中。

What could be reason and how can I reload it.可能是什么原因,我该如何重新加载它。 Any solution will be appreciated.任何解决方案将不胜感激。

I'm using spring-boot 1.4.4.RELEASE .我正在使用spring-boot 1.4.4.RELEASE

Below code is working for me.下面的代码对我有用。

@Bean
    public ReloadableResourceBundleMessageSource messageSource() {
        ReloadableResourceBundleMessageSource  resource = new ReloadableResourceBundleMessageSource();
        String messageFolderPath = propertyLocation + "/" + "i18n";
        resource.setBasename("file:"+messageFolderPath+"/messages");
        resource.setDefaultEncoding("UTF-8");
        resource.setCacheSeconds(10);
        return resource;
    }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM