Java web app: Tomcat and configuration files .properties

六眼飞鱼酱① 提交于 2019-12-02 08:30:47

问题


I have a java web app with Tomcat as servlet container.

I would to use different configuration files for different build configurations, i.e.

1) demo.properties

2) real.properties

3) test.properties

in which I would to specify the database name, db user and password (now for the db I use JNDI resource configuration in app context.xml), if send mail should be enabled or not (now I have two methods whose content I have to comment or not according to the purpose), some css image paths and some other stuff.

If it's possible to do so, how can I extrapolate db connection from context.xml? and How can I prevent to send email if my app is test or demo?

EDIT 2

Thanks to Anton Shchastnyi's answer to this question, I succeeded in extrapolating db connection parameters from context.xml (say in configApp.properties).

The configApp.properties must be in Tomcat lib folder together with .class which implements IntrospectionUtils.PropertySource.

So, how could I generalize this solution such that it can be used for different web app deployment? (I prepare the .war locally, then it's deployed on remote server)

来源:https://stackoverflow.com/questions/26589018/java-web-app-tomcat-and-configuration-files-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!