Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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

 
Ranch Hand
Posts: 177
  • 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.
 
Bartender
Posts: 1868
81
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
Bartender
Posts: 1868
81
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.
 
Bartender
Posts: 1002
16
Java Linux Mac OS X Spring VI Editor
  • 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.  
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!