简体   繁体   English

在tomcat Webapp中引用可变的外部Web服务URL

[英]Reference mutable external webservice url in tomcat webapp

I have a jax-rs webapp deployed on tomcat. 我在Tomcat上部署了一个jax-rs webapp。 The webapp references another external webservice, whose url may change due to version increment and is different on the dev environment than in production. 该Web应用程序引用了另一个外部Web服务,其URL可能会由于版本增加而改变,并且在开发环境中与生产环境中的URL不同。

Now I tried different approaches to reference the current external service url but neither seems good enough: 现在,我尝试了不同的方法来引用当前的外部服务URL,但似乎都不够好:

A) I can have variables in a database table, which is different for dev/ production. A)我可以在数据库表中包含变量,这对于dev / production来说是不同的。 On version increment, I'd need to update the urls. 在版本增加时,我需要更新网址。 This works ok, but I'd rather like the variables closer with the application, if possible. 这行得通,但我希望变量尽可能靠近应用程序。

B) I can store the variables in context xml. B)我可以将变量存储在上下文xml中。 But then I have application-specific parameters in it, which I would like to avoid. 但是然后我要避免使用特定于应用程序的参数。 Even more, i need to restart the application or even the tomcat instance for changes to take effect. 更重要的是,我需要重新启动应用程序甚至是tomcat实例,以使更改生效。 I'd like to avoid that in the production environment. 我想在生产环境中避免这种情况。

C) I can place the variables in web.xml. C)我可以将变量放在web.xml中。 Then I have to update the application with a version increment of the external webservice. 然后,我必须使用外部Web服务的版本增量来更新应用程序。 I could handle this if I only link to major versions of the external webservice, where endpoints may change, so updates would be seldom. 如果我仅链接到外部Web服务的主要版本(端点可能会更改),则可以解决此问题,因此很少进行更新。 But worse is, I will not have different values for dev and production, as web.xml comes with the application. 但更糟糕的是,由于web.xml随应用程序一起提供,因此我对于开发和生产的值将没有不同。

Any other ideas or suggestions, how to come around this? 还有其他想法或建议,如何解决?

Ok, I ended up with a properties file now, which I did not pack with the application but which resides on the server. 好的,我现在得到了一个属性文件,该文件未与应用程序打包在一起,但位于服务器上。 So I can have different ones for development and production, where I reference the current version of an external webservice. 因此,我可以使用不同的版本进行开发和生产,在其中引用外部Web服务的当前版本。 The properties filename comes from context.xml. 属性文件名来自context.xml。

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

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