You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chapter05/chapter05.adoc
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,14 +121,19 @@ classes and interfaces included in the MicroProfile Configuration API:
121
121
- `Config` - the class that is the main entry point to the configuration API
122
122
and provides access to configuration data. The Config class provides
123
123
static methods that can be used to access configuration properties.
124
+
124
125
- `ConfigProvider` - a utility class for getting the Config instance. It
125
126
allows retrieving the static instance of the Config object.
127
+
126
128
- `ConfigBuilder` - An interface used to create a Config instance manually.
127
129
It can add default sources, converters, and configuration sources.
130
+
128
131
- `ConfigSource` - This class represents a source of configuration values.
129
132
It reads configuration data from a specific source, such as system
130
133
properties, environment variables, files, or data stores.
134
+
131
135
- `Property` - It represents a key/value pair in the configuration data.
136
+
132
137
- `Converter<T>` - This interface implements custom converters that convert
133
138
configuration values from String to any desired type.
134
139
@@ -329,10 +334,15 @@ In this example, we’re injecting a property named "product.maintenanceMessage"
329
334
As we saw, the Config API makes it easy to inject configuration properties into an application. The Config API defines a contract for config implementations. A ConfigSource is used to read configuration data from a particular source. For example, we could create a ConfigSource that reads configuration data from a file.
330
335
331
336
`ConfigSource` interface has the following methods:
337
+
332
338
- `String getName()` : Returns the name of the ConfigSource.
339
+
333
340
- `int getOrdinal()` : Returns the ordinal of the ConfigSource. Ordinals are used to determine the precedence of ConfigSources. A higher ordinal means a higher precedence.
341
+
334
342
- `Map<String, String> getProperties()` : Returns a map of the properties in this ConfigSource. The keys in the map are the property names, and the values are the property values.
343
+
335
344
- `getValue(String propertyName)` : Returns the value of the given property. If the property is not found, this method returns null.
345
+
336
346
- `Set getPropertyNames()` : Returns a Set of the property names in this ConfigSource.
337
347
338
348
Let’s implement a feature in our MicroProfile e-Commerce application to integrate payment gateway configuration dynamically by creating a PaymentServiceConfigSource (a custom ConfigSource) which could fetch API keys and endpoints. This would ensure that payment service configurations are up-to-date and can be changed without redeploying the application.
@@ -469,7 +479,8 @@ public class PaymentService {
469
479
}
470
480
----
471
481
472
-
Explanation:
482
+
**Explanation:**
483
+
473
484
- `@Path("/authorize")`: Defines the base URI for the RESTful service. This class will handle requests made to URIs that start with `/payment/api/authorize`.
474
485
- `@RequestScoped`: Indicates that a new instance of `PaymentService` is created for each HTTP request.
475
486
- `@POST`: Specifies that the `processPayment` method will respond to HTTP POST requests, which is appropriate for operations that change server state (in this case, processing a payment).
0 commit comments