Continued from:

MicroProfile Config 

This module is simple yet powerful at the same time. Following the 12-Factor principles, it allows us to separate the configuration values from our code, so we won’t need to repackage the application each time the underlying runtime environment changes.

message.hello = Hello to MP-Config
stockservice.api.url = http://localhost:8080/stock-service/api
public class HelloResource {
   @Inject @ConfigProperty(name = "message.hello")
   private String message;
   public String message(){
      return message;

Accessing the /api/hello endpoint, the message will be seen.

Accessing the /api/hello endpoint

Another use of the MicroProfile Config module is to inject the url of other services that our application needs to consume.

@Inject @ConfigProperty(name = "stockservice.api.url")
private String apiUrl;

MicroProfile Config is going to search the System Properties, Environment Variables, and file for the value to inject. In a containerized environment, we might want to use environment variables to populate the configuration values of our application.

Table of contents:


Pages: 1 2 3 4 5 6 7 8

Leave a Reply

Your email address will not be published. Required fields are marked *