O'Reilly logo

Hands-On Enterprise Java Microservices with Eclipse MicroProfile by Scott Stark, Antoine Sabot-Durand, Pavol Loffay, Jeff Mesnil, Heiko W. Rupp, Cesar Saavedra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Config object

The org.eclipse.microprofile.config.Config interface is the entry point to retrieve configuration in a Java application.

There are two ways to get an instance of Config:

  1. The first (and preferred) way is to use CDI to inject it into the code:

@Inject
private Config config;
  1. The second way is to call the static method, org.eclipse.microprofile.config.ConfigProvider#getConfig(), to obtain an instance of Config:
Config config = ConfigProvider.getConfig();

The Config interface provides two methods to retrieve properties:

  • getValue(String propertyName, Class propertyType): This method throws a runtime exception if the property is not present in the configuration. This method must be used only for mandatory configuration ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required