Lädt...

🔧 Learn about the priority levels of config files and distinguish between .yaml and .properties files in Java Spring Boot.


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Hello everyone! Today, I will guide you through the priority levels of configuration files in a Java Spring Boot project and the differences between .yaml and .properties files. Let’s dive in!

1. Priority Levels of Configuration Files

In Spring Boot, configuration files can be placed in various locations, each with its own priority level. The common structure of configuration files in a project is as follows:

Image description

The structure of configuration files in the project will be arranged in the following order of priority:

Image description

2. Checking the Priority Levels

To test if the priority levels work as described, I changed the port in several configuration files:

  • File 1: port 8080

Image description

  • File 2: port 8081

Image description

  • File 3: port 8082

Image description

  • File 4: port 8083

Image description

After running the application, the port that was set is 8080.

Image description

Then, I deleted the outermost configuration file and ran the application again. The result showed the port as 8081.

Image description

Similarly, you can test with the remaining configuration files.

Isn’t it amazing? From these examples, we can clearly distinguish the priority of configuration files in a project.

3. Differentiating .properties and .yaml Files
In Java Spring Boot, both .properties and .yaml files are used to configure the application. However, they have some differences:

  • .properties
    • Simple "key-value" structure.
    • Stores data as strings. For complex data types, additional processing is required.
    • Example:
server.port=8080
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
  • .yaml:
    • Hierarchical structure, making it easy to read and organize complex information.
    • Supports multiple data types (strings, numbers, arrays, objects, booleans), making the configuration more flexible.
    • Example
server:
  port: 8080
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mydb

4. Priority Levels When Both .properties and .yaml Files Exist

Let’s say we have both .properties and .yaml files in the project. Let’s check the priority level:

File .properties: port 8083

Image description

File .yaml: port 8084

Image description

After running the application, the port that was set is 8083.

Image description

Conclusion

From the examples above, you should now have a clearer understanding of the priority levels of configuration files in Spring Boot and the differences between .properties and .yaml. I hope this article helps you gain more useful knowledge. If you found it helpful, don’t forget to leave me a reaction!

If you found this article useful and interesting, please share it with your friends and family. I hope you found it helpful. Thanks for reading 🙏

Let's get connected! You can find me on:

...

🔧 Advanced Configuration with Spring Boot: Profiles, Properties, and YAML


📈 44.15 Punkte
🔧 Programmierung

🔧 Spring vs Spring MVC vs Spring Boot: A Detailed Comparison for Java Developers


📈 36.29 Punkte
🔧 Programmierung

🕵️ Spring Cloud Config up to 2.1.8/2.2.2 spring-cloud-config-server path traversal


📈 34.88 Punkte
🕵️ Sicherheitslücken

🕵️ Spring Cloud Config up to 1.4.5/2.0.3/2.1.1 spring-cloud-config-server directory traversal


📈 34.88 Punkte
🕵️ Sicherheitslücken

🔧 Project Lombok | Java Library | Simplify Your Code | Spring Boot | Java Spring


📈 33.62 Punkte
🔧 Programmierung

🔧 How to Distinguish Between High-Quality and Low-Quality PBT Keycaps: A Detailed Guide


📈 32.51 Punkte
🔧 Programmierung

🔧 Demystifying Spring: A Beginner's Journey into Spring Framework and Spring Boot


📈 31.6 Punkte
🔧 Programmierung

📰 software-architektur.tv: GraalVM mit Spring Native, Spring Boot und Spring Cloud


📈 31.01 Punkte
📰 IT Nachrichten

🔧 Learn Spring Boot and Spring Data JPA


📈 30.62 Punkte
🔧 Programmierung

🔧 How to Use Spring Boot Eureka Server in Spring Boot 3.3.0+


📈 30.21 Punkte
🔧 Programmierung

🔧 Managing Application Properties with Spring Boot Profiles: A Best Practices Guide


📈 29.1 Punkte
🔧 Programmierung

🔧 Validating Configuration Properties in Spring Boot Application Startup


📈 29.1 Punkte
🔧 Programmierung

🐧 Where should I put my font and color config? In my Terminal config? My shell config?


📈 29.05 Punkte
🐧 Linux Tipps

🔧 What is YAML? A Developer's Guide to YAML vs YML


📈 28.93 Punkte
🔧 Programmierung

🕵️ CVE-2022-3064 | go-yaml up to 2.2.3 YAML Document resource consumption (Nessus ID 212040)


📈 28.93 Punkte
🕵️ Sicherheitslücken

🔧 YAML - YAML Ain't Markup Language


📈 28.93 Punkte
🔧 Programmierung

🕵️ ROS Actionlib actionlib/tools/library.py:132 yaml Loader yaml.safe_load input validation


📈 28.93 Punkte
🕵️ Sicherheitslücken

🕵️ yaml-rust up to 0.4.0 YAML Document load_from_str denial of service


📈 28.93 Punkte
🕵️ Sicherheitslücken

🕵️ osbs-client up to 0.56.0 yaml.load() YAML File Remote Code Execution


📈 28.93 Punkte
🕵️ Sicherheitslücken

🕵️ yaml-cpp 0.6.2 YAML File HandleFlowSequence denial of service


📈 28.93 Punkte
🕵️ Sicherheitslücken

🕵️ yaml-cpp 0.6.2 YAML File HandleFlowSequence denial of service


📈 28.93 Punkte
🕵️ Sicherheitslücken

🕵️ yaml-cpp 0.6.2 singledocparser.cpp YAML::SingleDocParser denial of service


📈 28.93 Punkte
🕵️ Sicherheitslücken

🕵️ yaml-cpp 0.5.3 YAML File HandleNode denial of service


📈 28.93 Punkte
🕵️ Sicherheitslücken

🕵️ yaml-cpp 0.6.2 YAML File HandleFlowMap denial of service


📈 28.93 Punkte
🕵️ Sicherheitslücken

🕵️ yaml-cpp 0.5.3 YAML File HandleNode Denial of Service


📈 28.93 Punkte
🕵️ Sicherheitslücken

🔧 Organizing YAML files by creating directories like `config/x` in Rails


📈 28.72 Punkte
🔧 Programmierung

🔧 How to configure Pulumi using YAML Config Files


📈 28.72 Punkte
🔧 Programmierung

🔧 Grok 3: AI Thông Minh Nhất Thế Giới


📈 28.6 Punkte
🔧 Programmierung

matomo