Read common external property file in Java Webapp and java normal app

前端 未结 1 1466
闹比i
闹比i 2021-01-07 15:12

I know this question has answered many a time with most useful answer as below,

Where to place and how to read configuration resource files in servlet based applicat

相关标签:
1条回答
  • 2021-01-07 15:28

    You can add a <context> to tomcat/conf/server.xml (in this example, linux path):

    <Context docBase="/home/yourusername/tomcat/assests" path="/assets" />
    

    If you are using Windows:

    <Context docBase="C:\path\to\myapp\assets" path="/assets" />
    

    And then you can access it like any other resource within your webapp (e.g.: /assets/myappConfig.property).

    If you are using JDBC for example, you could store the connection properties in a Singleton and request it from there, and that class could take care of change checks on that file.

    0 讨论(0)
提交回复
热议问题