自定义配置Boolean属性不生效
记录一下,今天遇到一个很坑的问题,boolean值类型的字段不能以is开头,不然获取不到配置文件中的值
如何设置boolean属性
几个要点
配置文件 ftp.started=false
类:
//是否启动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配置文件:
<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
查看更多关于springboot 自定义配置Boolean属性不生效的解决的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did194196