java
主页 > 软件编程 > java >

springboot自定义配置Boolean属性不生效的解决

2022-03-18 | 秩名 | 点击:

自定义配置Boolean属性不生效

记录一下,今天遇到一个很坑的问题,boolean值类型的字段不能以is开头,不然获取不到配置文件中的值


如何设置boolean属性

几个要点

配置文件 ftp.started=false

类:

1

2

3

4

5

6

7

8

9

10

11

12

13

//是否启动ftp任务

private boolean ftpStarted;

public String isFtpStarted() {

return ""+ftpStarted;

}

 

public void setFtpStarted(String ftpStarted) {

if (ftpStarted.equalsIgnoreCase("true")) {

this.ftpStarted = true;

}else {

this.ftpStarted = false;

}

}

spring配置文件:

1

2

3

<bean id="RcsFtpManager" class="com.feinno.security.rcs.rcsi.ftp.RcsFtpManager">

<property name="ftpStarted" value="${ftp.started}"/>

</bean>

原理很简单,spring设置后转化为内部boolean类型,有其他方法可交流,应该是比较笨的方法

原文链接:https://blog.csdn.net/weixin_44207812/article/details/107323425
相关文章
最新更新