英文:
How to override an interface fault tolerance annotation in application.properties
问题
我试图在 application.properties 中覆盖一个接口的 Timeout 容错注解。然而,我不确定是否可以通过配置文件使用 property [classname/methodname/]annotation/parameter 来覆盖注解参数。你有关接口的语法是什么?
这是我的 ReST 客户端接口:
package com.myProject;
@RegisterRestClient(configKey = "test")
@Timeout
public interface MyInterface{
@POST
@Path("/my-endpoint")
Uni<AResponse> create(ARequest request);
}
这是我的 application.properties:
com.myProject.MyInterface/Timeout/value=2000
查看 Quarkus 开发 UI 仪表板时,Timeout 值仍然是 1000,这是默认值。
英文:
I am trying to override an interface Timeout Fault tolerance annotation in application.properties. However I am not sure if it is possible to override annotation parameters via configuration file using property [classname/methodname/]annotation/parameter for an interface?
Any idea what would be the syntax for interface?
Here is my ReST client Interface:
package com.myProject;
@RegisterRestClient(configKey = "test")
@Timeout
public interface MyInterface{
@POST
@Path("/my-endpoint")
Uni<AResponse> create(ARequest request);
}
And here is my application.properties:
com.myProject.MyInterface/Timeout/value=2000
looking into the Quarkus dev UI dashboard, Timeout value is still 1000 which is the default value.
答案1
得分: 2
这是对我的问题的答案:
com.myProject.MyInterface$$CDIWrapper/Timeout/value=2000
这正是在dev UI MyInterface$$CDIWrapper中可见的内容,我需要在application.properties中使用相同的内容。
英文:
Here is the answer to my question:
com.myProject.MyInterface$$CDIWrapper/Timeout/value=2000
This is exactly what can be seen in dev UI MyInterface$$CDIWrapper and I needed to use the same in the application.properties.
答案2
得分: -1
只需在注解中设置它
你可以尝试直接在注解值中设置,就像这样:
@Timeout(2000)
在 application.properties
中覆盖(如果需要)
根据 SmallRye 容错文档,你应该能够使用以下之一覆盖值:
annotation-name/property-name=value
fully-qualified-class-name/method-name/annotation-name/property-name=value
在你的情况下应该是:
Timeout/value=2000
或
com.myProject.MyInterface/create/Timeout/value=2000
请注意我只在最后一个中添加了方法名 create
编辑
我认为你需要在方法级别设置你的注解 @Timeout
,并像上面的示例一样添加值
package com.myProject;
@RegisterRestClient(configKey = "test")
public interface MyInterface{
@POST
@Timeout(2000)
@Path("/my-endpoint")
Uni<AResponse> create(ARequest request);
}
英文:
Just set it in annotation
You could try setting it directly in the annotation value like this :
@Timeout(2000)
And override in application.properties
if needed
According to SmallRye Fault Tolerance Documentation, you should be able to override value using one of these :
annotation-name/property-name=value
fully-qualified-class-name/method-name/annotation-name/property-name=value
Which in your case should be :
Timeout/value=2000
Or
com.myProject.MyInterface/create/Timeout/value=2000
Notice I only added method name create
to the latest one
Edit
I believe you have to set your annotation @Timeout
at the method level and add value like example above
package com.myProject;
@RegisterRestClient(configKey = "test")
public interface MyInterface{
@POST
@Timeout(2000)
@Path("/my-endpoint")
Uni<AResponse> create(ARequest request);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论