Springboot应用程序无法从Spring Config Server属性中正确获取值



我有一个小问题,我真的不知道为什么会发生这种情况

@RefreshScope
@Configuration
@Getter
public class ConfigProperties {
@Value("${receipts.Application}")
private String application;
@Value("${receipts.ApplicationIdMT}")
private String applicationIdMT;
@Value("${receipts.IdComercioMT}")
private String idComercioMT;
//more properties
}

我有这个配置类,我从应用程序中获取值。yml这个文件在git存储库中,因为我的项目使用配置服务器来获取值

我在git-reo中的application.yml如下所示:

receipts:
Application: NAVERU
ApplicationIdMT: b96f9c62-e6a
IdComercioMT: 02500000012
//more properties

当我获取值时,发生了一些奇怪的事情,我的类的一个例子是:

//logic and imports....
public class ClientBase {
@Autowired
protected ConfigProperties configProperties;
public void printValues(){
String application= configProperties.getApplication();
String applicationIdMT= configProperties.getApplicationIdMT();
String idComercioMT= configProperties.getIdComercioMT();
System.out.println("aplication: "+application);
System.out.println("idMt: "+applicationIdMT);
System.out.println("idComerceMt: "+idComercioMT);
}

}

当我看到控制台中的值时:

aplication: NAVERU
idMt: b96f9c62-e6a
idComerceMt: 352321546

我不明白为什么idComerceMt会有这个值,因为就像我显示的那样,实际值是02500000012

问题是IdComercioMT的值被读取为一个数字,并且前缀为0,它在八进制中被解析

02500000012(八进制(=352321546(十进制(

由于Configuration类希望该值为String,因此可以通过引用值来轻松修复:

receipts:
Application: NAVERU
ApplicationIdMT: b96f9c62-e6a
IdComercioMT: '02500000012'
# more properties

在target\BOOT-INF\classes 中检查属性文件中的值

最新更新