【问题标题】:How to use remote location property file in spring re loadable message resource in javajava - 如何在java中的spring可重新加载消息资源中使用远程位置属性文件
【发布时间】:2014-03-24 08:40:24
【问题描述】:

我有一个分布式系统,上面有 8 个运行 tomcat 的应用服务器。这是一个弹簧应用程序。我想使用一个位于其他一些服务器上的属性文件,所有 tomcat 只会从那里读取它。 我正在使用 ReloadableResourceBundleMessageSource 来使用自动刷新功能。 我的 bean 定义是

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">  
          <property name="basenames" >
            <list>
                <value>file:///192.168.1.10//var/rateLimit</value> 
             </list>
        </property>
        <property name="cacheSeconds" value="60"></property>  
</bean>  

我正在调用这样的属性

System.out.println(messageSource.getMessage("testProp", null, null));

我无法使用此 IP 地址加载文件。

你能帮我解决这个问题吗?

【问题讨论】:

  • file:/// 192.168.1.10//var/rateLimit
  • 您是否在浏览器中查看过该链接?
  • 是的,我检查了我可以在浏览器中打开它

标签: java spring tomcat spring-mvc


【解决方案1】:

这是我用来通过 HTTP 读取外部属性文件的方法:

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames" value="/WEB-INF/messages,http://our.server.org/ws/i18n"/>
    <property name="cacheSeconds" value="300"/>
    <property name="useCodeAsDefaultMessage" value="true"/>
</bean>

也许将文件 URI 包含在 value 带引号的字符串中可能会有所帮助?

【讨论】:

  • 亲爱的你能否再建议我一件事,因为将这个文件保存在远程位置会在读取属性时影响应用程序的性能。
  • 如果您将cacheSeconds 设置为-1,那么它将永久缓存文件。因此它只会在启动时加载文件一次,并且不会影响性能。您可能希望将其设置为某个长值,以便获取更改(例如每天)。
  • 嗯,很酷,这意味着如果我每隔 24 小时制作一次,文件将在 24 小时内加载一次,那么这段时间之间将没有 http 连接。每个应用服务器都有缓存文件,不会与远程服务器通信。对吗?
猜你喜欢
  • 1970-01-01
  • 2018-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-13
  • 2015-06-11
  • 1970-01-01
  • 2020-04-26
相关资源
最近更新 更多