Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do you prefer to configure Spring Boot configurations?  RSS feed

 
Ranch Hand
Posts: 113
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I studied that Spring Boot provides "auto configuration" feature.
You write datasource properties in application.properties file, Spring boot injects Datasource, EntityManager objects in your Java class.
But when I see tutorial examples over internet, they write all beans in @Configuration file.
I would like to ask you what way do you prefer to configure the EntityManager, TransacionManagement, SessionFactory, DataSource, Repository objects when you develop a Spring Boot based application ?


Thanks in advance.
 
Saloon Keeper
Posts: 1599
56
Android Chrome IntelliJ IDE Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For (someone who started learning/using Spring Boot 2 in Jan 2018) I prefer not to use the XML files when I don't have to.
I also like using the application.yml file over application.properties.
If you start using the Spring Cloud Config then I suspect that bootstrap.yml is preferred.

I'm unsure if one method is better then an other method.
 
Pete Letkeman
Saloon Keeper
Posts: 1599
56
Android Chrome IntelliJ IDE Java MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that there is an predefined order in which Spring handles external configurations as listed here https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html.

A configuration value in a .properties file may be overwritten with a value in the .yml file or the other way around.
I cannot seem to fine the documentation which states which take precedence between the two, but I thought it was the .yml files.
 
Rancher
Posts: 955
9
Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Java Configuration (ie @Configuration), you are writing Java code therefore you have the added benefit of type safety.  Also allows you to use profiles. 
 
Get me the mayor's office! I need to tell him about this tiny ad:
free 1 hour java lesson
https://coderanch.com/t/695988/free-hour-java-lesson
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!