How to load properties file using spring




















Given a file db. Here you can see how fields are annotated with Value property key name annotation in order to map them with the specific property in the. Rather than using Value annotation, Environment should be used to read properties file in Spring.

Actually PropertySource annotation adds a PropertySource to Spring's Environment so that can be used to make your code simpler. In that case you just need to Autowire or Inject Environment into your Config class and use Environment object to get property value.

In cases where a given property key exists in more than one. 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? Sandeep Sandeep 2 2 gold badges 5 5 silver badges 17 17 bronze badges. Add a comment. Active Oldest Votes. 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. SpringBootApplication; import org. SpringApplication ;. SpringBootApplication ;. ApplicationContext ;. AnnotationConfigApplicationContext : Closing org. This is field from config This application reads from multiple. Got comments, or suggestions?

No need to use the separate file like application. The following is an example code to keep the Spring active profiles in application.

Note that the delimiter is used to separate each profile in application. Karthikeya T. Chaand Sheikh. Senol Atac. Spring Boot - Application Properties Advertisements. Previous Page. Next Page.



0コメント

  • 1000 / 1000