配置Tomcat以使用属性文件来加载数据库连接信息 [英] Configure Tomcat to use properties file to load DB connection information

查看:106
本文介绍了配置Tomcat以使用属性文件来加载数据库连接信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建从属性文件读取配置参数的Tomcat部署的接受做法是什么?

What are the accepted practices for creating a Tomcat deployment that reads configuration parameters from a properties file?

能够提供WAR文件并指定客户端只需要在特定目录中创建或编辑属性文件就很好。这是一个有规律的做事方式吗?有没有比这更好的做法?

It would be nice to be able to deliver a WAR file and specify that the client need only create or edit a properties file in a specific directory. Is this a somewhat regular way of doing things? Is there a better approach than this?

推荐答案

我们经常通过提供一个WAR和一个Context XML文件来分发webapps,它被放入你的 tomcat / conf / Catalina / localhost 目录,并可以从任何路径加载webapp。有一个参考文档 here 。这提供了以下优点:

We often distribute webapps by providing a WAR, and a Context XML file, which gets placed into your tomcat/conf/Catalina/localhost directory, and can load the webapp from any path. There is a reference document here. This provides the following advantages:


  • 可以在此配置上下文参数,并由webapp读取

  • 可以在此处定义和配置DataSources。

  • WAR可以实际存在于文件系统的任何位置,这意味着如果Tomcat升级,只需要将这一个配置文件移动到新的Tomcat安装,网络应用程序和任何其他文件可以保留在他们的位置。

如果你真的想要一个属性文件,你可以设置一个参数指向您的属性文件的上下文XML文件,请阅读 ServletContextListener ,然后读入属性文件。

If you really want a properties file, you can set a parameter in the context XML file pointing to your properties file, read the parameter in a ServletContextListener and then read in the properties file.

这篇关于配置Tomcat以使用属性文件来加载数据库连接信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆