无法使用 quarkus 注入配置 属性

Not able to inject config property with quarkus

我正在尝试从 Spring 迁移现有应用程序,但我遇到了一些问题。我的 application.properties:

里有这个
sms.gateway.pinLength = 5

加载这个属性的class如下:

import io.quarkus.arc.config.ConfigProperties;

@ConfigProperties(prefix="sms.gateway")
public class SmsGatewayConfig {

    public Integer pinLength;

    public Integer getPinLength() {
        return pinLength;
    }

    public void setPinLength(Integer pinLength) {
        this.pinLength = pinLength;
    }
}

这会触发错误消息:

No config value of type [java.lang.Integer] exists for: sms.gateway.pin-length

如果我将配置文件中的 pinLength 更改为 pin-length,同样的代码也可以工作。此外,如果我将此代码更改为以下内容,它也可以正常工作:

import javax.enterprise.context.ApplicationScoped;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@ApplicationScoped
public class SmsGatewayConfig {

    @ConfigProperty(name="sms.gateway.pinLength")
    public Integer pinLength;

    public Integer getPinLength() {
        return pinLength;
    }

    public void setPinLength(Integer pinLength) {
        this.pinLength = pinLength;
    }
}

我错过了什么?这在 Spring.

中工作正常

试一试:

@ConfigProperties (namingStrategy = NamingStrategy.VERBATIM)

https://github.com/quarkusio/quarkus/wiki/Migration-Guide-1.2(ConfigProperties 会话)