concept application property in category spring

appears as: pplication properties, application properties
Spring Microservices in Action, 2E

This is an excerpt from Manning's book Spring Microservices in Action, 2E.

Figure 2.14 License project structure with the bootstrap class, application properties, tests and pom.xml 

The next step to create our Spring Configuration config server is the set-up of one more file to define the core configuration of the server so it can be up and running. This file can be either an application.properties, application.yml, bootstrap.properties or bootstrap.yml. The bootstrap file is a specific file of Spring cloud and it is loaded before the application.properties or application.yml and is typically used for specifying the spring application name, the spring cloud configuration git location, encryption/decryption information and more. Specifically, the bootstrap file is loaded by a parent Spring ApplicationContext and that parent is loaded before the one that uses the application properties or yml files. As for the file extensions .yml and .properties are just different data formats and you can choose the one you prefer. From now on this book you’ll see that I will use the bootstrap.yml to define the configuration of the config server and the microservices.

Listing 5.11 ServiceConfig used to centralize application properties
package com.optimagrowth.license.config;
 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
@Component
public class ServiceConfig{
 
  @Value("${example.property}")
  private String exampleProperty;
 
  public String getExampleProperty(){
    return exampleProperty;
  }
}