我有一个分布式系统,上面有 8 个运行 tomcat 的应用服务器。这是一个 Spring 应用程序。我想使用一个位于其他服务器上的属性文件,所有 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 地址加载文件。
你能帮我解决这个问题吗?
最佳答案
这是我用来通过 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
引号字符串中可能会有帮助?
关于java - 如何在java中的spring可重新加载消息资源中使用远程位置属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22604503/