gpt4 book ai didi

quarkus - 无法使用 quarkus 注入(inject)配置属性

转载 作者:行者123 更新时间:2023-12-05 05:05:26 28 4
gpt4 key购买 nike

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

sms.gateway.pinLength = 5

加载该属性的类如下:

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 (配置属性 session )

关于quarkus - 无法使用 quarkus 注入(inject)配置属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60551973/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com