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. Paul Vargas This approach is recommended for i18n. My use case is for Jenkins so it's nice to have a solution that doesn't rely upon a bunch of ClassPathLoader shenanigans. You can't use this keyword like - props. Mukus Mukus 4, 2 2 gold badges 37 37 silver badges 54 54 bronze badges. ApplicationContext is available only in case of Spring application — joro.
Then load it as: props. Since your properties file is not at the root of your project, you don't need the leading slash. I was getting the exception thrown in the first place without the leading slash. It's still not working. You can use java. INFO: Pre-instantiating singletons in org. DefaultListableBeanFactory bd2: defining beans [org. After make these change run the main application file then we get the following output:. Hello Dinesh! Circle is Drawn! Circle: Point is: 20, 0.
If you need to read properties file in your Spring application all you need is to configure a PropertyPlaceholderConfigurer bean in your application context. Following example shows how to read property values from a properties file named myMessage. The number of such path can vary from 1 to n number. Hope i am clear with my requirement -Hemant.
Ok, So do you use annotations at all? There are so many ways you could go about doing this Personally I would use option 1 or 2 but it is up to you in the end Hi Sean So do you use annotations at all. No we use xml based approach. Use your placeholders to create a list bean and inject that: I could use that. In this case i had 4 location. But it may varies from 1 to say 20 location. Why would you need 2. Next if you don't want to use MessageSource or java. Properties then I think the only option is to do something like what has been done here by making a subclass of PropertyPlaceholderConfigurer.
You are right Hemant. My mistake, sincere apologies! Viewed 17k times. This is my project structure - src - main - java - mypackage - resources - config application. Improve this question. Yamen Nassif Yamen Nassif 2, 2 2 gold badges 20 20 silver badges 42 42 bronze badges. See this question: stackoverflow. JoshSullivan nope — Yamen Nassif. Add a comment. Active Oldest Votes.
Improve this answer. Jose Martinez Jose Martinez Thank you for sharing.
0コメント