This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How do you prefer to configure Spring Boot configurations?

 
Ranch Hand
Posts: 239
2
  • 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 IntelliJ IDE MySQL Database Chrome Java
  • 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 IntelliJ IDE MySQL Database Chrome Java
  • 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: 1041
19
Mac OS X IntelliJ IDE Oracle Spring VI Editor Tomcat Server Redhat Java Linux
  • 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.  
 
Liar, liar, pants on fire! refreshing plug:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!