Spring boot application properties file
Spring Boot comes with a built-in mechanism for application configuration using a file called application.properties. It is located under the src/main/resources folder, as shown below.
This file is like a properties file which stores key-value pair. Below is an example
Spring Boot provides various pre-defined properties that can be configured in application.properties file. The properties have default values unless configures specific properties.
Note -> Spring Boot also allows us to define our own property if required.
Application.properties file allows as to configure various properties. Some of the purposes are:
- Configure the Spring Boot framework
- Define custom configuration properties
- Define environment specific properties
YAML file
There is another alternative to application.properties file and that is application.yaml file. The sytax used in YAML file is different. Either of the two files is used. Examples of a YAML file is given below
spring:
application:
name: spring boot sample application
server:
port: 8081
spring:
thymeleaf:
enabled: true
Spring boot properties examples
Spring Boot pre-defined properties are divided into various categories. Some of the most common properties are listed in the below table.
Property | Default Value | Description |
---|---|---|
spring.application.name | Used to set the application name. | |
spring.config.name | application | It is used to set config file name. |
spring.application.admin.enabled | false | It is used to enable admin features of the application. |
server.port | 8080 | Used to set the port on which server will run |
spring.config.location | It is used to config the file name. | |
server.servlet.context-path | It configures the context path of the application. | |
logging.file.path | It configures the location of the log file. | |
logging.file | Used to set log file name. | |
spring.banner.charset | UTF-8 | Banner file encoding. |
spring.banner.location | classpath:banner.txt | It is used to set banner file location. |
spring.application.index | It is used to set 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.mail.default-encoding | UTF-8 | It is used to set default MimeMessage encoding. |
spring.mail.host | It is used to set SMTP server host. For example, smtp.example.com. | |
spring.mail.password | It is used to set 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 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 network address to which the server should bind to. | |
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 context path of the application. | |
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 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 date format. For example, dd/MM/yyyy. | |
spring.mvc.locale | It is used to set locale for the application. | |
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 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. |