spring 对于properties 配置文件动态刷新的问题

posha279280542 2017-07-17 08:58:21
环境
Spring 4 MVC,Quartz,没有web。纯粹的JAVA程序


需求,有个配置文件 conf. properties,内容如下
tablename=test,test2


启动程序后spring注入配置文件。程序可以获取tablename的值,

现在问题是,程序运行过程中,修改conf.properties 文件中tablename的值为: com,com1,获取的仍是变动之前的值:test,test2

请问如何动态刷新这个配置文件的值,再不重启程序的情况下。

以下是spring配置文件:

<!-- 将多个配置文件位置放到列表中 -->
<bean id="propertyResources" class="java.util.ArrayList">
<constructor-arg>
<list>
<value>file:conf/config.properties</value>
</list>
</constructor-arg>
</bean>


<!-- 将配置文件读取到容器中,交给Spring管理 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" ref="propertyResources" />
</bean>

在线急等。。。
...全文
2439 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
小菜鸡z 2018-12-10
  • 打赏
  • 举报
回复
引用 6 楼 yuong的世界 的回复:
@Autowired ConfigurableWebApplicationContext configurableWebApplicationContext; ------------------------------------------------------------------------------------------ //重新加载元数据 XmlWebApplicationContext context = (XmlWebApplicationContext) WebApplicationContextUtils.getWebApplicationContext(request.getServletContext()); context.refresh(); //重新load所有bean configurableWebApplicationContext.refresh(); 需要两个refresh()才行
老哥,request.getServletContext() 中的request是什么呢
yuong的世界 2018-12-06
  • 打赏
  • 举报
回复
@Autowired ConfigurableWebApplicationContext configurableWebApplicationContext; ------------------------------------------------------------------------------------------ //重新加载元数据 XmlWebApplicationContext context = (XmlWebApplicationContext) WebApplicationContextUtils.getWebApplicationContext(request.getServletContext()); context.refresh(); //重新load所有bean configurableWebApplicationContext.refresh(); 需要两个refresh()才行
诸秋白 2017-11-28
  • 打赏
  • 举报
回复
兄弟我也想明白spring支持动态修改properties文件吗?
大__淼 2017-07-19
  • 打赏
  • 举报
回复
这个修改properties文件 是程序运行过程中手工修改的还是通过代码修改的?
牛小云 2017-07-19
  • 打赏
  • 举报
回复
兄弟,这个问题你解决没有,我也遇到了同样的问题
李德胜1995 2017-07-17
  • 打赏
  • 举报
回复
eclipse配置jrebel插件实现tomcat热部署可以实现。。。。
posha279280542 2017-07-17
  • 打赏
  • 举报
回复 1
主要就是想请问下,spring当前是否提供对于properties文件加载后,自动刷新的功能,如果有,请问该如何配置, 如果没有,请问该如何实现。

51,395

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧