• 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
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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

 
Ranch Hand
Posts: 176
  • 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: 1856
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: 1856
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.
 
Rancher
Posts: 978
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. 
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!