Java mapping properties file




















The class has all three maps and their names corresponds to the name of the properties sub groups. We have also added a well-formatted toString method that we will use to print the bean, when application starts. Now, when we print the populated bean, we see that the nested Maps are correctly read from our YAML file. Thus, we can easily bind the configurations in Java Maps. For the full source code of the examples used in this tutorial, you can refer to our Github Repository.

Email Required, but never shown. The Overflow Blog. Stack Gives Back Safety in numbers: crowdsourcing data on nefarious IP addresses. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked Related Hot Network Questions. Question feed. Learn more. Reading Properties file in Java Ask Question. Asked 10 years, 1 month ago. Active 8 months ago.

Viewed k times. Specifically: Exception in thread "main" java. NullPointerException at java. Improve this question. Jesper k 44 44 gold badges silver badges bronze badges.

Add a comment. Active Oldest Votes. Improve this answer. Mark Elliot Mark Elliot 71k 19 19 gold badges silver badges bronze badges. I did what you advised me but it still throws the same exception — nikos. Steven Gomez Steven Gomez 5 5 silver badges 2 2 bronze badges. Don't forget to close the Reader in prop. There are many methods in that link. Why did you choose the one with class loader?

Are there any advantages or disadvantages of that method? You can use ResourceBundle class to read the properties file. In the next sections, we will read such lists into Java Beans using ConfigurationProperties annotation.

Remember that, instead of a YAML file we can use any equivalent properties file and the ConfigurationProperties annotation will work in both cases. In order to read this configuration, we will create a class and use ConfigurationProperties annotation along with a prefix of config.

We have printed the populated bean instance using a PostConstruct method and it shows the list is read correctly. Lists in a YAML or even a properties file will not always contain plain elements and they can be more complex. For example list of unrelated group of fields. We can see that each element in the list has a group of unrelated fields.



0コメント

  • 1000 / 1000