quarkus中使用什么而不是弃用@configprefix(“ prefix”)
我想在应用程序文件中注入具有相同名称但前缀不同的前缀的属性。 例如:
application.properties:
greeting.message = hello
bye.message = bye
为此, documentation 建议使用以下用法:
@ConfigProperties(prefix = "greeting")
public class GreetingConfiguration {
@Size(min = 20)
public String message;
}
@ApplicationScoped
public class SomeBean {
@Inject
GreetingConfiguration greetingConfiguration;
@ConfigPrefix("bye")
GreetingConfiguration byeConfiguration;
}
这种方式 :可以使用相同的变量(消息)调用engringConfiguration.message和Byeconfiguration消息。
但不建议使用它,因为@configproperties和@configprefix注释被弃用。
建议改用@configmapping。
同样,我如何使用具有相同名称的不同前缀和属性,而不会在Java侧创建多个变量(EX: - 消息)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据文件
示例(同一前缀),
application.properties
消息接口
config映射接口可以注入任何CDI意识到的bean:
因为由于以下限制。
在同一后缀的情况下,这是不可能的, 仍然是一种罕见的情况,也许您可以找出其他方法。
注明 * @exprementim-指定元素是实验性并且可能会改变而无需通知的注释。
参考- https://quarkus.io/guides/guides/guides/config-mappings/config-mappings
refer-a> refer-refo- https://smallrye.io/docs/docs/docs/docs/smallrye-config/main/main/main/mappapple/mapping/mpapping/mpapping一下。 html
As per the document
Example(Same prefix),
application.properties
Message Interface
A config mapping interface can be injected into any CDI aware bean:
This is not possible in the case of the same suffix because due to the below limitation.
Means
String suffix()
unavailable. Still, yours is a rare scenario, maybe you can figure out other ways.Note * @Experimental - Annotation that specifies that an element is experimental and may change without notice.
Refer - https://quarkus.io/guides/config-mappings
Refer - https://smallrye.io/docs/smallrye-config/main/mapping/mapping.html