Updated April 18, 2023
Introduction to Spring Boot
In Spring boot application, we have different ways to configure the properties for the project; we can use any of them. In comparison to the Spring framework, Spring Boot is very easy and makes a lot of configuring for us automatically. We have mainly 3 ways by which we can configure the spring application, but spring boot provided one easy way to do this by using a properties file, we can have all the application related configuration inside that file only, these properties can be very from the environment to environment. Here we will see its internal working and how we can configure all the things for our application in detail to better understand.
List of Spring Boot Properties
Here we will see different types of properties that we need to make in order to provide configuration for our application. This can be done via .properties file or .yml files in spring boot. In both the files, we have different type of syntax that need to follow; otherwise, the application will not run.
Let’s get started with the different type of properties we have in common:
Key for Property |
Description (what it does) |
logging.file.path | This property will help us to mention the path for the log file. |
debug | This property will enable the debug logs for us. |
logging.config | This property will tell us the location which will contain the logging configuration, for example, any .xml file or etc. |
info.* | This property will add the info endpoint. |
logging.charset.file | This will tell the Charset used for the file output. |
logging.charset.console | This will set the charset for the console output. |
logging.file.name | This property is used to mention the logging file name. |
logging.exception-conversion-word | This property is sued to tell the conversion words which are being used when logging exceptions. |
logging.group.* | This property is sued to log groups. |
logging.logback.rollingpolicy.clean-history-on-start | This property is used to clean up the archive log files but on startup. |
logging.level.* | This property is used to set the log level.
logging.level.org.springframework=INFO |
logging.pattern.console | This property is used to set the appender pattern, which will show the logs on the console. |
logging.logback.rollingpolicy.max-history | This property is used to set the number of days we can kept the archive logs. |
logging.logback.rollingpolicy.file-name-pattern | This property is used to roll over the file name (log file name). |
logging.logback.rollingpolicy.max-file-size | By the use of this, we can set the maximum size for the log file. |
logging.logback.rollingpolicy.total-size-cap | This property will set the size for the backup file. |
logging.pattern.file | This property will tell the Appender pattern for the file output. |
logging.pattern.dateformat | This property will tell the Appender pattern for the date format. |
spring.application.admin.jmx-name | Used for the JMX name for the spring application. |
spring.aop.auto | This will enable the auto proxy AspectJ. |
logging.pattern.level | This property will set the Appender pattern for log level. |
spring.aop.proxy-target-class | Proxy is to be true. |
spring.application.admin.enabled | This is used to enable the admin feature for the application or not. |
spring.banner.image.invert | This property is used to check the weather the image for the dark terminal. |
spring.application.name | This is used to give the application name. |
spring.banner.charset | This property issued for banner file encoding. |
spring.autoconfigure.exclude | To exclude the classes from the auto-configuration. |
spring.banner.image.bitdepth | Used for bit path. |
spring.banner.image.height | Used for the height for the banner images. |
spring.banner.image.location | It will tell the file location. |
spring.banner.image.width | Used to set the width of the banner image. |
spring.banner.image.margin | Merging for the banner image. |
spring.config.import | This property will help us to import the additional configuration data. |
spring.config.name | This will tell the config name. |
spring.config.location | This will tell the config file location. |
spring.info.build.location | Will tell the location to the build file. |
spring.info.build.encoding | Tell the build encoding. |
spring.info.git.encoding | File encoding. |
spring.jmx.default-domain | Will tell the JMX default domain. |
spring.jmx.server | JMX server name. |
spring.main.banner-mode | Tell the mode to display the banner. |
spring.main.cloud-platform | Check whether the cloud platform is overridden or not. |
spring.main.allow-bean-definition-overriding | Check whether the bean definition is over ridden or not. |
spring.main.register-shutdown-hook | This will take true or false and check whether the application has shut up a hook or not. |
spring.main.log-startup-info | This property is used for logging the information or logs when the application startups it also takes true or false as the value. |
spring.messages.always-use-message-format | Takes true or false as the value and try to apply the message format rules and parse the messages. |
spring.messages.fallback-to-system-locale | Fallback of the system also takes a value as true or false. |
trace | This property helps to enable the trace logs; it also takes the Boolean value as true or false; by default, it is false. |
All the properties that we have seen above come under the core properties of the spring boot; we also have cache, database and many more properties which are required in the application. We can also configure the security, Jackson, database, and other required property in the files when needed.
We have so many properties of the spring boot application out of which we have shown some of them above; now we can see one sample file which contains the properties of the application, we will see both the the files .properties and .yml.
- .properties file
- .yml file
Example:
Below find the sample file for the configuration which are required to run the application.
Code:
spring:
application:
name: ABC
profile: Development
banner:
location: banner.txt
datasource:
driverClassName: com.mysql.cj.jdbc.Driver
url: your url to the db
username: coc
liquibase:
enabled: true
change-log: classpath:db/your file
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
servlet:
multipart:
enabled: true
file-size-threshold: 2KB
max-file-size: 200MB
max-request-size: 215MB
security:
oauth2:
resourceserver:
jwt:
jwk-set-uri: your token configuration goes here
issuer-uri : if any
jackson:
mapper:
accept_case_insensitive_properties: true
Conclusion
By using properties, we can make so many configurations very easily in spring boot. Most of the configuration is automatically added in spring boot when we create the project from scratch; we just need to do the application-specific configuration under the requirement. All these are very easy to use and handle as well.
Recommended Articles
This is a guide to Spring Boot Properties. Here we discuss the introduction and list of spring boot properties for better understanding. You may also have a look at the following articles to learn more –