0

After packaging a spring boot web application into a jar. Is it possible to load up the properties file and edit it? If not, what would be the best practices to edit properties file while it's packaged in a jar?

Currently I am only able to obtain values from my properties file, but I am stuck on adding new values into it. How can I add @!newServer12 behind @!twtph? I am using "@!" as delimiters.

Properties File sample

ServerName = westpark@!southerndb@!kingsroad@!seamingless@!treehouse@!codebase@!twtph
JayC
  • 2,144
  • 8
  • 42
  • 77
  • 1
    Of course it doesn't. What you need is a database or something similar. You don't store data in property files, you store properties in them. – Kayaman Dec 12 '16 at 14:29
  • Possible duplicate of http://stackoverflow.com/questions/14117117/dynamically-loading-properties-file-using-spring – Raghuveer Dec 12 '16 at 14:30
  • @Kayaman The data that are inputted through HTML forms are being saved to mongodb. Should I manually extract all the data from my properties file and add it into mongodb? – JayC Dec 12 '16 at 14:33
  • 2
    I don't understand why you have put data in `application.properties` in the first place. It's like wearing socks on your hands and then complaining that it's a bit hard to move your fingers. – Kayaman Dec 12 '16 at 14:34
  • @Kayaman basically the my properties file stores hard coded server names. I use java to get those values one by one to connect to a shh2 server to obtain some values. So technically if I want to add a server name it wouldn't it have to go to the properties file. – JayC Dec 12 '16 at 14:36
  • I can understand server names in the property file. That's not the same as putting user input from HTML forms into it. If you have Mongo in use, then that's a lot more suitable place for your data. – Kayaman Dec 12 '16 at 14:39
  • I see, my last few sentences caused a confusion. I understood why adding data into properties file wouldn't make sense at all. I meant to say adding new property values. – JayC Dec 12 '16 at 14:47
  • It's a bit unclear to me. My guess is that you're talking about the application.properties in your .JAR/.WAR and that you can't edit that. Is that correct? So you want to be able to manually edit the application.properties file? Do you need hot reloading or does it not matter that you have to restart the application to make the changed properties work? – g00glen00b Dec 12 '16 at 15:04
  • Yes, I can't edit the application.properties once packaged into a jar. I was trying to create a input form with html where users can input values and it will automatically go into the properties file. If that is not possible I don't mind restarting my application to make the changes work. – JayC Dec 12 '16 at 15:12
  • 1
    This article will explain you what are different way you can set configuration value: https://spapas.github.io/2016/03/31/spring-boot-settings/ – Nagaraddi Dec 12 '16 at 16:17
  • @nagareddy I can see that they can change properties value "Key", "new value". But it doesn't speak about Keys that have delimiters. – JayC Dec 12 '16 at 20:55
  • It's still not a good idea. So highly mutable data doesn't belong in a property file. If it were a good idea, it would also be easy, however as you can see it's not easy. – Kayaman Dec 13 '16 at 07:44
  • @Kayaman Thank you for giving me knowledge on what is the right way to approach this. Currently I have loops that iterate through my server values to split them and obtain some values for each server. Moral of this story, based on what you said is to save my server values into a database then re implement my logic using the database values? Sorry, if I sound repetitive. – JayC Dec 13 '16 at 14:50
  • 1
    That's right. Even normal file based storage is a poor fit for webapps, but trying to modify a property file inside a jar file takes it to a whole new level. – Kayaman Dec 13 '16 at 14:53
  • @Kayaman What database would you recommend that would be compatible on cloud foundry? – JayC Dec 13 '16 at 15:10
  • It doesn't really matter if you're storing simple data like that. If you're already using MongoDB, you could easily store the data there too. – Kayaman Dec 13 '16 at 15:30

0 Answers0