What is the best place to store a configuration file in a Java web application (WAR)?

后端 未结 6 1588
猫巷女王i
猫巷女王i 2020-12-23 01:54

I create a web application (WAR) and deploy it on Tomcat. In the webapp there is a page with a form where an administrator can enter some configuration data. I don\

6条回答
  •  清酒与你
    2020-12-23 02:43

    The answer to this depends on how you intend to read and write that config file.

    For example, the Spring framework gives you the ability to use XML configuration files (or Java property files); these can be stored in your classpath (e.g., in the WEB-INF directory), anywhere else on the filesystem, or even in memory. If you were to use Spring for this, then the easiest place to store the config file is in your WEB-INF directory, and then use Spring's ClassPathXmlApplicationContext class to access your configuration file.

    But again, it all depends on how you plan to access that file.

提交回复
热议问题