在 JEE 应用程序中从 yaml 文件注入地图属性

Injecting Map properties from yaml file in JEE application

我最近开始使用 JEE(使用 CDI 和 Payara),我试图了解我是否可以从 yaml 文件中注入以映射结构编写的属性。

在 Spring 中非常简单,只需在 Map 类型的字段上使用 @Value,或 @ConfigurationProperties在 class 上,仅此而已。

在 JEE 应用程序中可以实现类似的功能吗?

是的,这是可能的,但不是开箱即用的 Java EE 应用程序。

要在其他地方提供任何类型的 Map 注入,您需要安排一些事情来实现它。

要安排一些东西来制作一个可以注入某处(或任何其他对象)的 Map,您可以使用各种 CDI 工具,其中 @Produces is probably the best choice. There are other choices. You might be interested in a CDI tutorial I wrote for relative newcomers.

最后,您可能希望查看 MicroProfile Config,这将允许类似但不完全相同的功能。