• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
Ranch Hand
Posts: 175
  • 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: 1807
74
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: 1807
74
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: 965
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. 
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!