gpt4 book ai didi

How to define custom application property in Quarkus Extension with non-fixed key(如何使用非固定键在Quarkus扩展中定义自定义应用程序属性)

转载 作者:bug小助手 更新时间:2023-10-25 14:01:09 28 4
gpt4 key购买 nike



I'm writing a Quarkus Extension (on Quarkus 2.16) whose purpose is to set some fields of a MyClient object based on values ​​inserted in the application.properties.

我正在编写一个Quarkus扩展(在Quarkus 2.16上),其目的是根据application.properties中插入的值设置MyClient对象的某些字段。


I would like this extension to be able to manage N instances of MyClient by reading properties whose key must follow a syntax like:

我希望此扩展能够通过读取其键必须遵循如下语法的属性来管理MyClient的N个实例:


quarkus.myextension.myclient.CLIENTNAME-1.name=Bob

Quarkus.myextension.myclient.CLIENTNAME-1.name=Bob


quarkus.myextension.myclient.CLIENTNAME-2.name=John

Quarkus.myextension.myclient.CLIENTNAME-2.name=John


...

..。


quarkus.myextension.myclient.CLIENTNAME-N.name=Paul

Quarkus.myextension.myclient.CLIENTNAME-N.name=Paul


Where CLIENTNAME is a value chosen at will by the user of the extension.

其中,客户端名称是扩展的用户随意选择的值。


Is there any way to achieve this result? I've seen similar behavior in many extensions (e.g. RestClient) but haven't figured out how to reproduce it

有没有办法实现这一结果?我在许多扩展(例如RestClient)中看到了类似的行为,但还没有想出如何重现它


Thanks a lot.

非常感谢.


更多回答

So you are looking for a config object that will give you this behavior?

因此,您正在寻找一个可以提供此行为的配置对象?

smallrye.io/smallrye-config/Main/config/map-support for properties mapping and quarkus.io/guides/writing-extensions#configuration tell you more about how to use config in extensions

用于属性映射的smallrye.io/smallrye-config/Main/config/map-support和quarkus.io/guides/writing-extensions#configuration告诉您有关如何在扩展中使用配置的更多信息

Thanks for the replies. I had already read WriteYourOwnExtension, but what is not clear to me is how to use the class annotated with @ConfigMap: I see that a Processor class is defined but I don't understand whether it should be inserted in Runtime or Deployment, nor how this class should be used so that I can recover the properties

谢谢你的回复。我已经阅读了WriteYourOwnExtension,但我不清楚的是如何使用用@ConfigMap注释的类:我看到定义了一个处理器类,但我不知道它是应该插入到运行时还是部署中,也不知道应该如何使用这个类以便恢复属性

优秀答案推荐
更多回答

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com