如何在application.properties中覆盖接口容错注解

huangapple go评论56阅读模式
英文:

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 = &quot;test&quot;)
@Timeout
public interface MyInterface{
    @POST
    @Path(&quot;/my-endpoint&quot;)
    Uni&lt;AResponse&gt; 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 = &quot;test&quot;)
public interface MyInterface{
    @POST
    @Timeout(2000)
    @Path(&quot;/my-endpoint&quot;)
    Uni&lt;AResponse&gt; 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 = &quot;test&quot;)
public interface MyInterface{
    @POST
    @Timeout(2000)
    @Path(&quot;/my-endpoint&quot;)
    Uni&lt;AResponse&gt; create(ARequest request);
}

huangapple
  • 本文由 发表于 2023年4月20日 01:39:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76057398.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定