Adding a directory to tomcat classpath and read the property file in spring

后端 未结 3 361
梦毁少年i
梦毁少年i 2021-02-03 23:29

I am trying to read the test1.properties file which is located at an external folder.

here is my spring config file:



        
3条回答
  •  温柔的废话
    2021-02-04 00:26

    If your intention to keep file outside the war or ear , so that you can update it without compling and creating war again. just editing the file and restarting the server. Keep it in any external folder , even outside server and give absolute path in spring.

    
    
    
        
            classpath:test.properties
            **file:/someexteranal/dir/test1.properties**
        
    
    

    Best thing , you can give this / path with root in Unix/linux and same will work in windows, just need to keep file in directory where your server is installed. Like your tomcat in D drive , then keep it in D:\someexternal\dir and above code will work fine there too

提交回复
热议问题