This awesome post shows how to read properties from multiple properties files in Spring Boot and it will help you sleep like a baby tonight! If we want to read multiple properties files, then we need more than one properties file. For this post, we have application. For simplicity, we place these files in the resources directory in the Maven project.
We use a singleton bean whose properties map to entries in 3 separate properties files. This is the main class to read properties from multiple properties files into an object in Spring Boot. We use PropertySource and locations of the files in the classpath.
The application. Alternatively, we could use PropertySourced. The codes are available here. Value; import org. PropertySourcesPlaceholderConfigurer is used from Spring framework 5. PropertyPlaceholderConfigurer class was used which is deprecated from Spring 5.
For example there is a app. Notice how org. Environment is injected and that object is used to get properties. If app. If no default is specified and a property cannot be resolved, an IllegalArgumentException is thrown. You can also use PropertySources container annotation that aggregates several PropertySource annotations. If a given property key exists in more than one. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 10 years, 2 months ago. Active 9 years ago. Viewed 18k times. I suggested use the propertyconfigurer and use maven profiles to generate the environment specific build Can you please advise which one suits which case? Improve this question. Sandeep Sandeep 2 2 gold badges 5 5 silver badges 17 17 bronze badges.
Add a comment. Active Oldest Votes. Improve this answer. I forgot to press submit on this answer, so now it duplicates some information that others have provided. Still, I'll leave it here in case anybody finds the additional details to be helpful. Dave Newton Dave Newton k 23 23 gold badges silver badges bronze badges.
Can this be done?
0コメント