What is application.properties file in spring boot

In this article, we will understand one of the important files in Spring Boot which is the application. properties.

Spring Boot Application properties

One of the advantages of Spring Boot over standard Spring Framework is that it provides us with “lesser configuration”. Spring Boot has a default application.properties file and it is auto-detected.

Spring Boot allows us to configure our application configuration using a file called application. properties. It can reside anywhere in the classpath of our application.

In our Example, It is present in the src/main/resources folder in the project structure as you can see above. So, by using this default file, we don’t have to register a PropertySource or even provide the path to the property file.

Spring Boot has various default properties that can be configured in the application.properties file. There are some default properties in Spring boot to support Logging, AOP, Identity, Hibernate, JPA and, etc. It also allows us to add our own custom property if required.

Example:

In this, we can use an application.properties file to set logging levels.

logging.level.some.package.path=DEBUG

In this, we can use an application.properties file to set name, port number.

spring.application.name = MyFirstSbProject   

server.port = 8088

Spring Boot Common Application Properties.

The following is the list of Common Application Property Category list.

  • Core Properties.
  • Cache Properties.
  • Mail Properties.
  • JSON Properties.
  • Transaction Properties.
  • Data Properties.
  • Web Properties.
  • Data Migration Properties.
  • Integration Properties.
  • Templating Properties.
  • Server Properties.
  • RSocket Properties.
  • Actuator Properties.
  • DevTools Properties.
  • Testing Properties.

Why we need Application Configuration?

While creating any application, the demand for configuration varies from one environment to other.

  • If you want to connect with the database, you can have the configuration in this file.
  • If you want to have a different configuration.
  • If You can want to configure the port to run the server using the server. port.

Let us see the list of common Spring Boot properties.

Property

Description

Debug

It is used to enable debug logs.

spring. application.name

It is used to set the name of application

spring.application.admin.enabled

It is used to enable admin features of the application
spring. config.name

It is used to set the name of the config file

server. port

It is used to set the port of the server

spring. config.location

It is used to set the location of the config file
logging. file.path

It is used to configure the log file path

spring. banner.charset

It is used for file encoding

logging.file

It is used to set the name of a log file.

spring. application.index

It is used to set the application index.

spring. mail.default-encoding

It is used to set default MimeMessage encoding.

spring. mail.host

It is used to set the SMTP server host.

spring. mail.password

It is used to log in & password of the SMTP server.

spring. mail.port

It is used to set SMTP server ports.

spring. mail. test-connection

It is used to check mail servers.

spring. mail.username

It is used to set the login name of the SMTP server.

spring. mail.sources

It is used to set sources for the application.

server.servlet-path

It is used to set the path of the dispatcher servlet
server.ssl.enabled

It is used to enable SSL support

spring.http.multipart.enabled

It is used to enable support for multi-part uploads.

spring.mvc.date-format

It is used to set date formats.

spring.mvc.locale

It is used to set locale for application.
security.basic.enabled It is used to enable basic authentication.
server. server-header

It is used to set the value for the server response header.

This is the list of Common Spring Properties. If you want to know more, view the official Spring Boot doc https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html

Thus, this was all about the Application Property file in Spring Boot.