-->

Java web app: Tomcat and configuration files .prop

2020-04-18 07:03发布

问题:

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)