
- Spring Boot Tutorial
- Spring Boot - Home
- Spring Boot - Introduction
- Spring Boot - Quick Start
- Spring Boot - Bootstrapping
- Spring Boot - Tomcat Deployment
- Spring Boot - Build Systems
- Spring Boot - Code Structure
- Spring Beans & Dependency Injection
- Spring Boot - Runners

Spring Boot - Application Properties
- Spring Boot - Logging
- Building RESTful Web Services
- Spring Boot - Exception Handling
- Spring Boot - Interceptor
- Spring Boot - Servlet Filter
- Spring Boot - Tomcat Port Number
- Spring Boot - Rest Template
- Spring Boot - File Handling
- Spring Boot - Service Components
- Spring Boot - Thymeleaf
- Consuming RESTful Web Services
- Spring Boot - CORS Support
- Spring Boot - Internationalization
- Spring Boot - Scheduling
- Spring Boot - Enabling HTTPS
- Spring Boot - Eureka Server
- Service Registration with Eureka
- Zuul Proxy Server and Routing
- Spring Cloud Configuration Server
- Spring Cloud Configuration Client
- Spring Boot - Actuator
- Spring Boot - Admin Server
- Spring Boot - Admin Client
- Spring Boot - Enabling Swagger2
- Spring Boot - Creating Docker Image
- Tracing Micro Service Logs
- Spring Boot - Flyway Database
- Spring Boot - Sending Email
- Spring Boot - Hystrix
- Spring Boot - Web Socket
- Spring Boot - Batch Service
- Spring Boot - Apache Kafka
- Spring Boot - Twilio
- Spring Boot - Unit Test Cases
- Rest Controller Unit Test
- Spring Boot - Database Handling
- Securing Web Applications
- Spring Boot - OAuth2 with JWT
- Spring Boot - Google Cloud Platform
- Spring Boot - Google OAuth2 Sign-In
- Spring Boot Resources
- Spring Boot - Quick Guide
- Spring Boot - Useful Resources
- Spring Boot - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
Application Properties support us to work in different environments. In this chapter, you are going to learn how to configure and specify the properties to a Spring Boot application.
Command Line Properties
Spring Boot application converts the command line properties into Spring Boot Environment properties. Command line properties take precedence over the other property sources. By default, Spring Boot uses the 8080 port number to start the Tomcat. Let us learn how change the port number by using command line properties.
Step 1 − After creating an executable JAR file, run it by using the command java –jar <JARFILE> .
Step 2 − Use the command given in the screenshot given below to change the port number for Spring Boot application by using command line properties.

Note − You can provide more than one application properties by using the delimiter −.
Properties File
Properties files are used to keep ‘N’ number of properties in a single file to run the application in a different environment. In Spring Boot, properties are kept in the application.properties file under the classpath.
The application.properties file is located in the src/main/resources directory. The code for sample application.properties file is given below −
Note that in the code shown above the Spring Boot application demoservice starts on the port 9090.
Spring Boot supports YAML based properties configurations to run the application. Instead of application.properties , we can use application.yml file. This YAML file also should be kept inside the classpath. The sample application.yml file is given below −
Externalized Properties
Instead of keeping the properties file under classpath, we can keep the properties in different location or path. While running the JAR file, we can specify the properties file path. You can use the following command to specify the location of properties file while running the JAR −

Use of @Value Annotation
The @Value annotation is used to read the environment or application property value in Java code. The syntax to read the property value is shown below −
Look at the following example that shows the syntax to read the spring.application.name property value in Java variable by using @Value annotation.
Observe the code given below for a better understanding −
Note − If the property is not found while running the application, Spring Boot throws the Illegal Argument exception as Could not resolve placeholder 'spring.application.name' in value "${spring.application.name}" .
To resolve the placeholder issue, we can set the default value for the property using thr syntax given below −
Spring Boot Active Profile
Spring Boot supports different properties based on the Spring active profile. For example, we can keep two separate files for development and production to run the Spring Boot application.
Spring active profile in application.properties
Let us understand how to have Spring active profile in application.properties. By default, application. properties will be used to run the Spring Boot application. If you want to use profile based properties, we can keep separate properties file for each profile as shown below −
application.properties
application-dev.properties
application-prod.properties
While running the JAR file, we need to specify the spring active profile based on each properties file. By default, Spring Boot application uses the application.properties file. The command to set the spring active profile is shown below −

You can see active profile name on the console log as shown below −
Now, Tomcat has started on the port 9090 (http) as shown below −
You can set the Production active profile as shown below −

Now, Tomcat started on the port 4431 (http) as shown below −

Spring active profile for application.yml
Let us understand how to keep Spring active profile for application.yml. We can keep the Spring active profile properties in the single application.yml file. No need to use the separate file like application.properties.
The following is an example code to keep the Spring active profiles in application.yml file. Note that the delimiter (---) is used to separate each profile in application.yml file.
To command to set development active profile is given below −
Now, Tomcat started on the port 9090 (http) as shown below −
The command to set Production active profile is given below −
This will start Tomcat on the port 4431 (http) as shown below:
Kickstart Your Career
Get certified by completing the course
- Java Arrays
- Java Strings
- Java Collection
- Java 8 Tutorial
- Java Multithreading
- Java Exception Handling
- Java Programs
- Java Project
- Java Collections Interview
- Java Interview Questions
- Spring Boot

- Explore Our Geeks Community
- Spring Boot - MongoRepository with Example
- Spring Boot - Integrating Hibernate and JPA
- Spring Boot JpaRepository with Example
- Spring Boot - CRUD Operations using MongoDB
- Spring Boot - Spring Data JPA
- Upload Multiple Files in Spring Boot using JPA, Thymeleaf, Multipart
- Spring Boot - Difference Between CrudRepository and JpaRepository
- Spring Boot - CrudRepository with Example
- Spring Boot - application.yml/application.yaml File
- Spring Boot - CRUD Operations using MySQL Database
- How to Implement One to Many Mapping in Spring Boot?
- How to Run Your First Spring Boot Application in Eclipse IDE?
- How to Run Spring Boot Application?
- Spring Boot - Application Properties
- Spring Boot - H2 Database
- Spring Boot - CRUD Operations
- Spring Boot - REST Example
- Spring Boot - Change Port
- Spring Boot - Hello World
- What is Command Line Runner Interface in Spring Boot?
- How to Make a Simple RestController in Spring Boot?
- How to Implement Simple Authentication in Spring Boot?
- What is PathVariable in the Spring Boot?
- How to Create a Spring Boot Project in Spring Initializr and Run it in IntelliJ IDEA?
- How to Get the Body of Request in Spring Boot?
Spring Boot – Application Properties
As we already know Spring Boot is built on the top of the spring and contains all the features of spring. And is becoming a favorite of developers these days because it’s a rapid production-ready environment that enables the developers to directly focus on the logic instead of struggling with the configuration and set-up. In Spring Boot, whenever you create a new Spring Boot Application in spring starter, or inside an IDE (Eclipse or STS) a file is located inside the src/main/resources folder named as application.properties file which is shown in the below image as shown below as follows:
Geeks, now you must be wondering what does this file do? What are the major roles of this file during development? So in a spring boot application, application.properties file is used to write the application-related property into that file. This file contains the different configuration which is required to run the application in a different environment, and each environment will have a different property defined by it. Inside the application properties file, we define every type of property like changing the port, database connectivity, connection to the eureka server, and many more. Now let’s see some examples for better understanding.
Example 1: To Change the Port Number
Sometimes when you run your spring application you may encounter the following type of error

The error is Port 8989 was already in use. So in this case you may kill that process that is running on this port number or you may change your port number and rerun your application. So where do you have to change your port number? e.g in the application.properties file .

So as given in the above screenshot you can change your port number by the following line
Example 2: To define the name of our application
To define the name of our application you can write the properties like this
So you can see this represents the property as key-value pair here, every key associated with a value also.
Example 3: Connecting with the MySQL Database
To connect with the MySQL Database you have to write a bunch of lines. You can write the properties like this
Example 4: Connecting with the H2 Database
H2 is an embedded, open-source, and in-memory database. It is a relational database management system written in Java. It is a client/server application. It is generally used in unit testing. It stores data in memory, not persist the data on disk. To connect with the H2 Database you have to write a bunch of lines. You can write the properties like this
Example 5: Connecting with the MongoDB Database
To connect with the MongoDB Database you have to write a bunch of lines. You can write the properties like this
Example 6: Connecting with the Eureka Server
Eureka Server is an application that holds information about all client-service applications. Every Microservice will register into the Eureka server and the Eureka server knows all the client applications running on each port and IP address. Eureka Server is also known as Discovery Server. You can write the properties like this
Example 7 : Connecting with the PostgreSQL
PostgreSQL is a free and open-source relational database management system. To connect with the PostgreSQL Database you have to write a bunch of lines. You can write the properties like this.
Note : The value written here is sample data. Please write the values as per your requirements. But the keys remain the same.
application.yml/application.yaml file
The application.properties file is not that readable. So most of the time developers choose application.yml file over application.properties file. YAML is a superset of JSON, and as such is a very convenient format for specifying hierarchical configuration data. YAML is more readable and it is good for the developers to read/write configuration files. For example, let’s pick some of the properties files that we have explained above, and let’s write them in YAML format.
Case 1: Let’s pick above example 3 where we were connecting with the MySQL Database , the corresponding properties will be as follows:
Case 2: Let’s pick above example 6 where we were connecting with the Eureka Server, the corresponding properties will be as follows:
Please Login to comment...
- nandinigujral
- Java-Spring-Boot
Please write us at contrib[email protected] to report any issue with the above content
Improve your Coding Skills with Practice
Instantly share code, notes, and snippets.
memory-lovers / application.properties template for Spring Boot
- Star 5 You must be signed in to star a gist
- Fork 2 You must be signed in to fork a gist


IMAGES
VIDEO
COMMENTS
In today’s competitive job market, it’s crucial to have a well-crafted resume that stands out from the rest. One way to achieve this is by using a resume in Word format. One of the significant advantages of using a resume in Word format is ...
When it comes to applying for a job, having a well-crafted and visually appealing CV is crucial. With the advent of technology, there are now countless resources available online that offer free CV formats. However, not all of them are crea...
In today’s competitive job market, it is crucial to stand out from the crowd and make a lasting impression on potential employers. One way to do this is by presenting your information in a clear and concise manner through a simple biodata f...
1 Answer 1 ... From the javadoc of java.util.Properties : The key contains all of the characters in the line starting with the first non-white
See CaffeineSpec for more details on the spec format. spring.cache.couchbase.expiration. Entry expiration. By default the entries never expire.
YAML Format. As well as Java properties files, we can also use YAML-based configuration files in our Spring Boot application. YAML is a
COMMON SPRING BOOT PROPERTIES # # This sample file is provided as a guideline. Do NOT copy it in its # entirety to your own application.
properties или application.yml из перечисленных ниже источников в ... формате. Мы можем поэкспериментировать и переопределить адреса
properties file under the classpath. The application.properties file is located in the src/main/resources directory. The code for sample application.properties
... formats in the form of code. In the application.properties file, properties are stored as a single-line configuration. Spring Boot generates
yml file over application.properties file. YAML is a superset of JSON, and as such is a very convenient format for specifying hierarchical
memory-lovers/application.properties template for Spring Boot · Star 5 You must be signed in to star a gist · Fork 2 You must be signed in to fork a gist.
Каждый из этих вариантов может быть в формате key/value или в yml(yaml) формате. ... properties или application.yml или application.yaml. В
The format of application properties is simple, consisting of key-value pairs separated by an equal sign (key=value). On the other hand