我尝试实现自定义配置类型并且它有效。但是,当我将自定义类型与一组配置一起使用时,@ConfigProperties
它无法通过名称自动识别属性,而是将属性视为具有嵌套属性的对象。
我怎样才能正确地实现这样的行为?(我是 Quarkus 的新手,所以如果我在这里做错了,请纠正我)
这是一个转换自定义类型的代码片段:
public class Percentage {
private double percentage;
public Percentage() {}
public Percentage(double percentage) {
this.percentage = percentage;
}
public void setPercentage(double percentage) {
this.percentage = percentage;
}
public double getPercentage() {
return this.percentage;
}
}
@Priority(300)
public class PercentageConverter implements Converter<Percentage> {
@Override
public Percentage convert(String value) {
int percentIndex = value.indexOf("%");
return new Percentage(Double.parseDouble(value.substring(0, percentIndex - 1)));
}
}
/// this works ------
public class Hello {
@ConfigProperty(name = "custom.vat")
Percentage vat;
public Hello () {
}
// .....
}
/// however, this fails
@ConfigProperties(prefix = "custom")
public class CustomConfig {
public Percentage vat;
public Percentage profit;
}
javax.enterprise.inject.spi.DeploymentException: No config value of type [double] exists for: custom.vat.percentage
at io.quarkus.arc.runtime.ConfigRecorder.validateConfigProperties(ConfigRecorder.java:39)