Spring Boot Application Properties

Spring Boot Properties with features, project, starter project wizard, cli, application, annotations, dm, properties, actuator, thymeleaf view, jpa, jdbc

Spring Boot Application Properties

Spring Boot Application Properties

Spring Boot provides various properties which can be specified inside our project's application.properties file. These properties have default values and you can set that inside the properties file. Properties are used to set values like: server-port number, database connection configuration etc.

The following table contains common Spring Boot properties.

Property Default value Description
banner.charset UTF-8 It is used to set banner file encoding.
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 application index.
spring.application.name   It is used to set 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 file locations.
spring.config.name application It is used to set config 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 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.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 support.
spring.http.multipart.enabled True It is used to enable support of multi-part uploads.
spring.http.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.
spring.social.facebook.app-id   It is used to set 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 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 Boot Example

In this example, we are creating properties file and setting server port.

We have following files in our Spring Boot project.

// pom.xml

  1. <?xmlversionxmlversion="1.0"encoding="UTF-8"?>  
  2. <projectxmlnsprojectxmlns="https://maven.apache.org/POM/4.0.0"xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"  
  3.     xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">  
  4.     <modelVersion>4.0.0</modelVersion>  
  5.   
  6.     <groupId>com.javatpoint</groupId>  
  7.     <artifactId>spring-boot-example</artifactId>  
  8.     <version>0.0.1-SNAPSHOT</version>  
  9.     <packaging>jar</packaging>  
  10.   
  11.     <name>spring-boot-example</name>  
  12.     <description>A project for Spring Boot</description>  
  13.   
  14.     <parent>  
  15.         <groupId>org.springframework.boot</groupId>  
  16.         <artifactId>spring-boot-starter-parent</artifactId>  
  17.         <version>2.0.0.BUILD-SNAPSHOT</version>  
  18.         <relativePath/><!-- lookup parent from repository -->  
  19.     </parent>  
  20.   
  21.     <properties>  
  22.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  23.         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>  
  24.         <java.version>1.8</java.version>  
  25.     </properties>  
  26.   
  27.     <dependencies>  
  28.         <dependency>  
  29.             <groupId>org.springframework.boot</groupId>  
  30.             <artifactId>spring-boot-starter-web</artifactId>  
  31.         </dependency>  
  32.   
  33.         <dependency>  
  34.             <groupId>org.springframework.boot</groupId>  
  35.             <artifactId>spring-boot-starter-test</artifactId>  
  36.             <scope>test</scope>  
  37.         </dependency>  
  38.     </dependencies>  
  39.   
  40.     <build>  
  41.         <plugins>  
  42.             <plugin>  
  43.                 <groupId>org.springframework.boot</groupId>  
  44.                 <artifactId>spring-boot-maven-plugin</artifactId>  
  45.             </plugin>  
  46.         </plugins>  
  47.     </build>  
  48.   
  49.     <repositories>  
  50.         <repository>  
  51.             <id>spring-snapshots</id>  
  52.             <name>Spring Snapshots</name>  
  53.             <url>https://repo.spring.io/snapshot</url>  
  54.             <snapshots>  
  55.                 <enabled>true</enabled>  
  56.             </snapshots>  
  57.         </repository>  
  58.         <repository>  
  59.             <id>spring-milestones</id>  
  60.             <name>Spring Milestones</name>  
  61.             <url>https://repo.spring.io/milestone</url>  
  62.             <snapshots>  
  63.                 <enabled>false</enabled>  
  64.             </snapshots>  
  65.         </repository>  
  66.     </repositories>  
  67.   
  68.     <pluginRepositories>  
  69.         <pluginRepository>  
  70.             <id>spring-snapshots</id>  
  71.             <name>Spring Snapshots</name>  
  72.             <url>https://repo.spring.io/snapshot</url>  
  73.             <snapshots>  
  74.                 <enabled>true</enabled>  
  75.             </snapshots>  
  76.         </pluginRepository>  
  77.         <pluginRepository>  
  78.             <id>spring-milestones</id>  
  79.             <name>Spring Milestones</name>  
  80.             <url>https://repo.spring.io/milestone</url>  
  81.             <snapshots>  
  82.                 <enabled>false</enabled>  
  83.             </snapshots>  
  84.         </pluginRepository>  
  85.     </pluginRepositories>  
  86. </project>  

// HomeController.java

  1. package comtpoint;  
  2. import org.springframework.web.bind.annotation.RequestMapping;  
  3. import org.springframework.web.bind.annotation.RestController;  
  4. @RestController  
  5. public class HomeController {  
  6.     @RequestMapping("/hello")  
  7.     public String hello(){  
  8.         return"Hello!";  
  9.     }  
  10.  

// SpringBootExampleApplication.java

  1. package com.tpoint;  
  2. import org.springframework.boot.SpringApplication;  
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;  
  4. import org.springframework.web.bind.annotation.RequestMapping;  
  5. @SpringBootApplication  
  6. public class SpringBootExampleApplication {  
  7.     public static void main(String[] args) {  
  8.         SpringApplication.run(SpringBootExampleApplication.class, args);  
  9.     }  
  10. }  

// application.properties

  1. server.port=2017  

Our project structure looks like the below.

Output:

After running the application, it produces the following output.

You can see that this application is running on port 2017.

Same like, we can set other properties also for our Spring Boot application.