官术网_书友最值得收藏!

The @ConfigProperty annotation

The @ConfigProperty annotation can be used to inject configuration values in Java fields or method parameters using CDI, as shown:

@Inject
@ConfigProperty(name="my.url")
private URL myURL;

The @ConfigProperty annotation can have defaultValue, which is used to configure the field if the configuration property is not found in the underlying Config:

@Inject
@ConfigProperty(name="my.url", defaultValue="http://localhost/")
private URL myURL;

If defaultValue is not set and no property is found, the application will throw DeploymentException as it cannot be properly configured.

It is possible to use Optional if a configuration property might not be present, as shown in the following code block:

@Inject
@ConfigProperty(name="my.url")
private Optional<URL> someUrl; // will be set to Optional.empty if the
                               // property `my.url` cannot be found

After reading the configuration, we need to provide source configuration sources, which will be covered in the next section.

主站蜘蛛池模板: 翁牛特旗| 建平县| 屯门区| 潼关县| 南投市| 西吉县| 凤阳县| 武冈市| 泗水县| 南华县| 永仁县| 随州市| 襄城县| 庐江县| 河曲县| 洛川县| 资溪县| 凤阳县| 托克逊县| 凤山县| 临汾市| 聂荣县| 沾化县| 石城县| 长兴县| 鄂尔多斯市| 南皮县| 涪陵区| 赣榆县| 全州县| 宁河县| 东乡县| 雷州市| 麻江县| 油尖旺区| 平阳县| 扶绥县| 张家界市| 茌平县| 巧家县| 阿图什市|