~~ Spring Boot ~~

 1. Introduction

    1.1 Spring Boot-Intorduction
    1.2 Spring Boot-Architecture
    1.3 Spring Boot-Quick Start

 2. Project Creation

    2.1 Spring Initializer
    2.2 Spring Boot CLI
    2.3 STS IDE
    2.4 Eclipse IDE
    2.5 First Program
    2.6 Spring Boot-Code Structure

 3. Spring Boot – Beans & DI
 4. Spring Boot – Runners
 5. Spring Boot – Properties File
 6. Spring Boot – Looging
 7. Spring Boot – Rest WebServices
 8. Spring Boot – Exception Handling
 9. Spring Boot – Interceptor
 10. Spring Boot – Servlet Filter
 11. Spring Boot – Rest Template
 12. Spring Boot – File HANDLING
 13. Spring Boot – Thymeleaf
 14. Spring Boot – Internationalization
 15. Spring Boot – Scheduling
 16. Spring Boot – Actuator
 17. Spring Boot – Email Handling
 18. Spring Boot – Database Handling
 19. Spring Boot – Caching

Spring Boot | Application Properties :

Spring Boot provides a built-in configuration file, called “application.properties”. Application properties help us to override the default configuration and also work in different environment with different values. There are lots of properties which we can configure in this configuration file. we can find these properties on “common-application-properties”

We can keep multiple properties file for different environment in classpath. It will be available in “src/main/resources” folder as below. We can use “predefined properties” as well as “custom properties” also.

1. Predefined Properties :

Below is sample code for application.properties. we can find more properties on “common-application-properties”.

#Server Configuration
server.port = 9090 spring.application.name = demoservice

In the above example we configured Server port as “9090” and Application name as “demoservice”. If we want to use some comment then we should use # symbol for that line.

2. Custom Properties :

We can create our own custom properties using application.properties file. Now let’s see how we can achieve this. First add below propery in properties file.

#Custome Property
website.name=study4onle

Now we will use @Value annotation and (${…}) placeholder to fetch the value from properties file, as below one of the Controller class.

package com.study4online.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ApplicationController {

//Fetching application name from properties File
@Value("${spring.application.name}")
String serviceName;

@RequestMapping(value = "/", method = RequestMethod.GET)
public String sName() {
return serviceName;
}

}

When we will hit url – http://localhost:8079/ in browser, we can see run this applicationrun this application, we can see below output.

 

NOTE : Here we need to make sure that key which we are using under placeholder should match to application.properties file key, otherwise it will throw “IllegalArgumentException”.