Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Spring Boot Application Properties
3.
Example of Application Properties
3.1.
YAML Properties File
3.1.1.
Example of application.yml
4.
Spring Boot Property Categories
5.
Application Properties
6.
Frequently Asked Questions (FAQS)
7.
Key Takeaways
Last Updated: Mar 27, 2024

Spring Boot Application Properties

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

There are several application development frameworks available, but one of the most popular frameworks when working with java is the Spring framework.

source: Link

We will be completely fascinated with the Spring framework and its ability to manage applications.

source: Giphy

In this article, we will learn about the Spring Boot Application Properties. We will go through the example of an application property. We will also learn about the categories of the application properties available in the Spring Boot framework. Later, we will also list all the application properties in a tabular format.

Spring Boot Application Properties

Spring Boot Framework comes has a built-in mechanism for application configuration using a file called the ‘application.properties’. It is located in the src/main/resources folder, as shown below in the following figure.

The Spring Boot framework provides various properties that can be configured in the ‘application.properties’ file. The properties have default values. We can set a property for the application. Spring Boot also enables us to define our own property when needed.

The ‘application.properties’ file allows us to run an application in another environment. Briefly, we can use the application.properties file to:

  • Configure the Spring Boot framework
  • define our application custom configuration properties
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Example of Application Properties

Let us have a look at how we can configure the application properties with an example.

#configuring application name 
spring.application.name = ApplicationExample
#configuring port 
server.port = 8081 


In the above file, we have configured the application name and port. Port 8081 represents that the application runs on port 8081.

YAML Properties File

The yml file provided by Spring Boot is used to configure the properties. Because the Snake YAML jar is on the classpath, the Yaml file works. We can use the application.yml file instead of the application.properties file, however the YML file must be present in the classpath.

Example of application.yml

spring: 
application: 
name: ApplicationExample
server: 
port: 8081 


The application name and port have been configured in the example above. The application operates on port 8081, as shown by the port number.

Spring Boot Property Categories

The following are the sixteen Spring Boot Property categories:

  1. Core Properties: These are the application properties concerned with the basic configuration details.
  2. Cache Properties: Application properties dealing with cache memory management.
  3. Mail Properties: The application properties dealing with the SMTP (Simple Mail Transfer Protocol).
  4. JSON(JavaScript Object Notation) Properties: These properties are concerned with the serialization of JSON.
  5. Data Properties: Application Properties that work on data manipulation and management.
  6. Transaction Properties:  These are the application properties concerned with the transaction execution.
  7. Data Migration Properties: Application properties regarding the migration of data from one schema to another one.
  8. Integration Properties: The application properties dealing with the Integration of data and packages.
  9. Web Properties:  These properties are concerned with the implementation of the web applications.
  10. Templating Properties: Application properties which handles the httpsessions.
  11. Server Properties: The application properties having the server details.
  12. Security Properties: These are the application properties about the security and authentication details.
  13. RSocket Properties: Application properties regarding the transport and socket transmission.
  14. Actuator Properties: The application properties regarding the Cloud Foundry actuator endpoint security calls.
  15. DevTools Properties: These properties are concerned with the details of the development tools.
  16. Testing Properties: The application properties dealing with testing and quality assurance.

Application Properties

A collection of common Spring Boot application properties can be found in the table below:

Property Default Values Description
Debug false It enables debug logs.
spring.application.name   It is used to set the application name.
spring.application.admin.enabled false It is used to enable admin features of the application.
spring.config.name application It is used to set config file name.
spring.config.location   It is used to config the file name.
server.port 8080 Configures the HTTP(HyperText Transfer Protocol) server port
server.servlet.context-path   It configures the context path of the application.
logging.file.path   It configures the location of the log file.
spring.banner.charset UTF-8 Banner file encoding.
spring.banner.location classpath:banner.txt It is used to set banner file location.
logging.file   It is used to set log file name. For example, data.log.
spring.application.index   It is used to set the application index.
spring.application.name   It is used to set the application name.
spring.application.admin.enabled false It is used to enable admin features for the application.
spring.config.location   It is used to config the file locations.
spring.config.name application It is used to set config the file name.
spring.mail.default-encoding UTF-8 It is used to set default MimeMessage encoding.
spring.mail.host   It is used to set SMTP(Simple Mail Transfer Protocol) server host. For example, smtp.example.com.
spring.mail.password   It is used to set the login password of the SMTP server.
spring.mail.port   It is used to set SMTP server port.
spring.mail.test-connection false It is used to test that the mail server is available on startup.
spring.mail.username   It is used to set the login user of the SMTP server.
spring.main.sources   It is used to set sources for the application.
server.address   It is used to set the network address to which the server should bind.
server.connection-timeout   It is used to set time in milliseconds that connectors will wait for another HTTP request before closing the connection.
server.context-path   It is used to set the context path of the application.
server.port 8080 It is used to set HTTP port.
server.server-header   It is used for the Server response header (no header is sent if empty)
server.servlet-path / It is used to set path of the main dispatcher servlet
server.ssl.enabled   It is used to enable SSL(Secure Sockets Layer) support.
spring.http.multipart.enabled True It is used to enable support of multi-part uploads.
spring.servlet.multipart.max-file-size 1MB It is used to set max file size.
spring.mvc.async.request-timeout   It is used to set time in milliseconds.
spring.mvc.date-format   It is used to set the date format. For example, dd/MM/yyyy.
spring.mvc.locale   It is used to set locale for the application.
spring.social.facebook.app-id   It is used to set the application's Facebook App ID.
spring.social.linkedin.app-id   It is used to set application's LinkedIn App ID.
spring.social.twitter.app-id   It is used to set the application's Twitter App ID.
security.basic.authorize-mode role It is used to set security authorize-mode to apply.
security.basic.enabled true It is used to enable basic authentication.
Spring.test.database.replace any Type of existing DataSource to replace.
Spring.test.mockmvc.print default MVC(Model-View-Controller) Print option
spring.freemaker.content-type text/html Content-Type value
server.server-header   Value to use for the server response header.
spring.security.filter.dispatcher-type async, error, request Security filter chain dispatcher types.
spring.security.filter.order -100 Security filter chain order.
spring.security.oauth2.client.registration.*   OAuth client registrations.
spring.security.oauth2.client.provider.*   OAuth provider details.

 

Frequently Asked Questions (FAQS)

  1. What is Spring?
    The Spring framework is one of the most popular application development frameworks of Java. The important feature of the spring framework is dependency injection or the Inversion of Control.
     
  2. What is Spring Boot?
    Spring Boot is one of the modules of the Spring Framework. It helps us to build a stand-alone application with very minimal or almost zero configurations.
     
  3. What are Spring Boot application properties?
    The ‘application.properties’ file in Spring Boot allows us to run an application in a different environment. 
     
  4. What is Snake YAML?
    SnakeYAML library is used to serialize Java objects to YAML documents and vice versa.

Key Takeaways

In this article, we learnt about the Spring Boot Application Properties. We also went through the example of an application property. 

We also learned about the categories of the application properties available in the Spring Boot framework. We also saw the list of all the application properties in a tabular format.

Recommended Readings:

Apart from this, you can also expand your knowledge by referring to these articles on Java and Web development.

You can also consider our Spring Boot Course to give your career an edge over others.

Happy Learning!
 

Previous article
Springbootapplication annotation
Next article
Spring Boot Starters
Live masterclass