English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

SpringBoot Application Properties

The Spring Boot Framework comes with built-in mechanisms to use application.properties for application configuration. It is located at src/main/resources as shown in the figure below.

Spring Boot provides files that can be application.properties various properties in the file. These properties have default values. We can set one or more properties for the Spring Boot application. Spring Boot also allows us to define our own properties as needed.

The application.properties file allows us to Run applications in different environments. In short, we can use the application.properties file to perform the following operations:

Configure the Spring Boot framework Define our application custom configuration properties

Sample of application.properties

#Configure application name
pring.application.name = demoApplication
#Configure port
server.port = 8081

In the above example, we have already configured application nameand Port. Port8081Indicates that the application is running on port 8081 running on.

Note: Lines starting with # are comments.

YAML properties file

Spring Boot provides another file for configuring properties, called yml file. The Yaml file takes effect because there is Snake YAML jar. In addition to using the application.properties file, we can also use the application.yml file, but Yml The file should appear in the classpath.

application example.yml

spring:
application:
name: demoApplication
server:
port: 8081

In the above example, we have already configured application nameand Port. Port8081Indicates that the application is running on port 8081 running on.

Spring Boot property categories

There are 16The categories of Spring Boot properties are as follows:

Core properties Cache properties Email properties JSON properties Data properties Transaction properties Data migration properties Integration properties Network media resources Template properties Server properties Security properties RSocket properties Executor properties DevTools properties Test properties

Application properties table

The following table provides a list of common Spring Boot properties:

PropertyDefault valueDescription
DebugfalseIt enables debug logs.
spring.application.name
It is used to set the application name.
spring.application.admin.enabledfalseIt is used to enable the management features of the application.
spring.config.nameapplicationUsed to set the configuration file name.
spring.config.location
It is used to configure the file name.
server.port8080Configure the HTTP 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.charsetUTF-8Banner file encoding.
spring.banner.locationclasspath: banner.txtIt is used to set the location of the title file.
logging.file
It is used to set the 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.enabledfalseIt is used to enable management features for the application.
spring.config.location
It is used to configure the file location.
spring.config.nameapplicationIt is used to set the filename.
spring.mail.default-encodingUTF-8It is used to set the default encoding for MimeMessage.
spring.mail.host
It is used to set the SMTP server host. For example, smtp.example.com.
spring.mail.password
It is used to set the login password for the SMTP server.
spring.mail.port
It is used to set the SMTP server port.
spring.mail.test-connectionfalseIt is used to test if the mail server is available at startup.
spring.mail.username
It is used to set the login username for the SMTP server.
spring.main.sources
It is used to set the source of the application.
server.address
It is used to set the network address that the server should bind to.
server.connection-timeout
It is used to set the time (in milliseconds) that the connector 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.port8080It is used to set the HTTP port.
server.server-header
It is used for server response headers (if empty, headers will not be sent).
server.servlet-path/It is used to set the path of the main scheduler servlet.
server.ssl.enabled
It is used to enable SSL support.
spring.http.multipart.enabledtrueIt is used to enable support for chunked uploads.
spring.servlet.multipart.max-File size1MBIt is used to set the maximum file size.
spring.mvc.async.request-timeout
It is used to set the 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 the language environment of the application.
spring.social.facebook.app-id
It is used to set the Facebook App ID of the application.
spring.social.linkedin.app-id
It is used to set the LinkedIn Application ID for the application.
spring.social.twitter.app-id
It is used to set the Twitter App ID for the application.
security.basic.authorize-moderoleIt is used to set the security authorization mode to be applied.
security.basic.enabledtrueIt is used to enable basic authentication.
Spring.test.database.replaceanyType of Existing DataSource to Replace.
Spring.test.mockmvc.printdefaultMVC Print Options
spring.freemaker.content-typetext/htmlContent Type Value
server.server-header
Value for Server Response Headers.
spring.security.filter.dispatcher-typeasync, error, requestSecurity Filter Chain Dispatcher Type.
spring.security.filter.order-100Security Filter Chain Order.
spring.security.oauth2.client.registration.*
OAuth Client Registration.
spring.security.oauth2.client.provider.*
OAuth Provider Details.