1

I want to write to an application.yml file as well as read from it respectively, after value has been written in a spring boot application during runtime. It can be application.properties file as well. The property's key can be written dynamically or it can be entered manually by the developer(Doesn't matter).

The key-value pair must me accessible after it has been written to the yaml/properties file.

I don't have much information about the above mentioned concept. So, haven't implemented it yet. Hence, there is no source code for it. I tried to search on the web but didn't get expected information, so posting it here.

Since I don't know the way it is done, if someone knows whether it is the same way or different ways to write to both(properties/yaml) files, preferred way is using the yaml file.

Any helpful links or tutorials are welcome.

Thank You

  • Does this answer your question: https://stackoverflow.com/questions/38761781/how-change-property-values-at-runtime-in-spring – Prateek Pande Jan 19 '21 at 04:37
  • @PrateekPande no it doesn't. Here I want to write to the file during runtime. The key may already exist. – Sulaiman Ahmed Z Jan 19 '21 at 04:41
  • 1
    Check out this post:- https://stackoverflow.com/a/59853090/7597142 After getting the property, you have to update and then reload the property file to reflect updated values. – Prateek Pande Jan 19 '21 at 04:52
  • 1
    Can you elaborate more on what are you trying to achieve at the end? Modifying the application.yml from within the application during the runtime is not something that people usually do in spring boot and there are plenty reasons for that... – Mark Bramnik Jan 19 '21 at 08:55
  • @MarkBramnik this is a localized project within which I am writing the values to application.yml file. After I provide it to my senior, he will rewrite it to get the details from a db. This approach is temporary. And ofcourse at runtime we don't change the application.yml file. – Sulaiman Ahmed Z Jan 19 '21 at 09:03
  • 1
    In this case maybe you need to create an application.yaml somewhere in the "temp" location and do not change anything in src/main/resources/application.yaml for example.What do you mean by 'The key-value pair must me accessible after it has been written to the yaml/properties file'. Accessible from where? – Mark Bramnik Jan 19 '21 at 09:58
  • @MarkBramnik by that I mean anywhere from the application. Anyways I figured out a way to do it using ```@ConfigurationProperties```annotation in the project. Thanks for the help. – Sulaiman Ahmed Z Jan 19 '21 at 10:24

1 Answers1

0

I used @ConfigurationProperties in my project to solve this problem.