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
@Path("/hello") public class HelloResource { @Inject @ConfigProperty(name = "message.hello") private String message; @GET public String message(){ return message; } }
Accessing the /api/hello
endpoint, the message will be seen.
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 microprofile-config.properties 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.