Java-Tomcat:在不重新启动服务器的情况下重新加载context.xml [英] Java - Tomcat: Reload context.xml without restarting server
问题描述
我正在使用spring mvc和tomcat作为服务器.我希望能够更改自动装配的jndi字段(作为String):
I'm using spring mvc and tomcat as a server. I want to be able to change a jndi field that is Autowired(as String):
<jee:jndi-lookup id="someMessage" jndi-name="someMessage"/>
在我的其中一项服务中,
引用了Tomcat的conf/context.xml,它看起来像这样:
in one of the my services, that is referenced to conf/context.xml of Tomcat, that looks something like this:
<Environment name="someMessage" value="Change this." type="java.lang.String" />.
但是,当我更改context.xml的值时,除非我重新启动服务器,否则此更改不会反映在Spring管理的服务上.是否有任何反映而无需重新启动或重新部署战争的变化?我知道有一种解决方案,可以在属性文件之一中包含这样的动态字段,然后使用commons配置库重新加载更改,但是我正在寻找一种解决方案,以将该字段保留在conf/context.xml中.
However, when I change the value on context.xml, this change is not reflected on my service managed by spring, unless I restart server. Is there anyway to reflect this change without restarting or redeploying war? I know there is a solution to include such a dynamic field in one of properties file and then use commons configuration library to reload the changes, but I'm looking for a solution to keep this field on my conf/context.xml...
推荐答案
据我所知,如果将其放入tomcat主页的conf/context.xml
中是不可能的,如以下文档所示:
As far as I know, it's impossible if you put it into the conf/context.xml
of your tomcat home as the following doc shows:
- StandardContext .html#reload():如果context.xml已更改,则应停止此Context并创建(并启动)新的Context实例. -即无法通过原始上下文实现
- 重新加载现有的应用程序:重新加载现有的应用程序Web应用程序,以反映/WEB-INF/classes或/WEB-INF/lib的内容中的更改. -即不反映context.xml的更改
- StandardContext.html#reload(): If the context.xml has changed, you should stop this Context and create (and start) a new Context instance instead. -- i.e. can't achieve by original context
- Reload Existing App: Reload an existing web application, to reflect changes in the contents of /WEB-INF/classes or /WEB-INF/lib. -- i.e. not reflect the change of context.xml
但是您可以定义应用程序的/META-INF/context.xml
,它将打包到war中,并且可以在不重新启动服务器的情况下替换war.
But you can define your app's /META-INF/context.xml
, which will be packed into war and you can replace war without restart server.
这篇关于Java-Tomcat:在不重新启动服务器的情况下重新加载context.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!