异常:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘companyNewsService’: Unsatisfied dependency expressed through field ‘capricornSftpConfig’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘capricornSftpConfig’: Could not bind properties to CapricornSftpConfig (prefix=capricorn.sftp, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is org.springframework.beans.InvalidPropertyException: Invalid property ‘types[1]’ of bean class [com.hoau.capricorn.util.sftp.CapricornSftpConfig]: Illegal attempt to get property ‘types’ threw exception; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property ‘types[1]’ of bean class [com.hoau.capricorn.util.sftp.CapricornSftpConfig]: Cannot access indexed value of property referenced in indexed property path ‘types[1]’: returned null
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory1.getObject(AbstractBeanFactory.java:306)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)atorg.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor1.getObject(AbstractBeanFactory.java:306)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)atorg.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessorAutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
… 19 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘capricornSftpConfig’: Could not bind properties to CapricornSftpConfig (prefix=capricorn.sftp, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is org.springframework.beans.InvalidPropertyException: Invalid property ‘types[1]’ of bean class [com.hoau.capricorn.util.sftp.CapricornSftpConfig]: Illegal attempt to get property ‘types’ threw exception; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property ‘types[1]’ of bean class [com.hoau.capricorn.util.sftp.CapricornSftpConfig]: Cannot access indexed value of property referenced in indexed property path ‘types[1]’: returned null
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:334)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:291)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:409)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1620)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory1.getObject(AbstractBeanFactory.java:306)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)atorg.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor1.getObject(AbstractBeanFactory.java:306)atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)atorg.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)atorg.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)atorg.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessorAutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
… 32 common frames omitted
Caused by: org.springframework.beans.InvalidPropertyException: Invalid property ‘types[1]’ of bean class [com.hoau.capricorn.util.sftp.CapricornSftpConfig]: Illegal attempt to get property ‘types’ threw exception; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property ‘types[1]’ of bean class [com.hoau.capricorn.util.sftp.CapricornSftpConfig]: Cannot access indexed value of property referenced in indexed property path ‘types[1]’: returned null
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:722)
at org.springframework.beans.AbstractNestablePropertyAccessor.getNestedPropertyAccessor(AbstractNestablePropertyAccessor.java:850)
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyAccessorForPropertyPath(AbstractNestablePropertyAccessor.java:827)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:270)
at org.springframework.boot.bind.RelaxedDataBinder$RelaxedBeanWrapper.setPropertyValue(RelaxedDataBinder.java:699)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:859)
at org.springframework.validation.DataBinder.doBind(DataBinder.java:755)
at org.springframework.boot.bind.RelaxedDataBinder.doBind(RelaxedDataBinder.java:128)
at org.springframework.validation.DataBinder.bind(DataBinder.java:740)
at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:272)
at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:240)
at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:329)
… 45 common frames omitted
Caused by: org.springframework.beans.NullValueInNestedPathException: Invalid property ‘types[1]’ of bean class [com.hoau.capricorn.util.sftp.CapricornSftpConfig]: Cannot access indexed value of property referenced in indexed property path ‘types[1]’: returned null
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:653)
… 57 common frames omitted

如果将1⃣️代码写在集合空判断之下,那么this.types就永远都不会被赋值,而后面的yml配置解析用到getTypes时,就会报错了

 /*** @ConfigurationProperties整个是使用反射实例化对象,然后一点一点的填充值* 初始化时types是一个空list,将这个空列表塞到配置类实例中之后,再逐步将yml配置文件* 中的值解析出来,填充到list中**/public void setTypes(List<ItemDto> types) { //set方法只会执行一次this.types = types;   //1⃣️if (CollectionUtils.isEmpty(types)){return;    //代码会从这里返回}for (Integer i= 0; i< types.size(); i++){types.get(i).setCode(i.toString());}}public List<ItemDto> getTypes() {return types;}

SpringBoot YML 配置ListBean相关推荐

  1. Springboot yml配置参数加密 ,jasypt自定义解密器(拓展篇)

    前言 最近项目组开始关注一些敏感数据的明文相关的事宜 , 其实这些东西也是都有非常成熟的解决方案. 既然最近着手去解决这些事情,那么也顺便给还未了解的大伙普及一下. Springboot yml配置参 ...

  2. SpringBoot yml 配置

    1. 在 spring boot 中,有两种配置文件,一种是application.properties,另一种是application.yml,两种都可以配置spring boot 项目中的一些变量 ...

  3. springboot yml 配置redis_springboot快速集成redis,事务配置

    什么是redis 是一个非关系型数据库内存数据库,以key-value方式进行存储,Redis以单线程方式存储,既然是单线程(保证线程安全) Redis一个应用场景 令牌生成(临时有效) 短信验证码( ...

  4. springboot项目配置yml中数据源后报错Unknown database user_information(已解决)

    目录 问题现象: 问题分析: 解决方法: 问题现象: 今天在用.yml配置了springboot项目的Mysql数据源后,出现了无法访问数据库的问题: 报错如下: Unknown database ' ...

  5. springboot项目配置(yml,pom)

    首先使用idea创建一个纯净的springboot项目 1,替换pom文件 <?xml version="1.0" encoding="UTF-8"?&g ...

  6. 深圳Java培训学习:SpringBoot的yml配置及多环境切换【千锋】

    深圳Java培训学习:SpringBoot的yml配置及多环境切换[千锋] 1,配置风格 从application.properties转换到application.yml 并不改变功能效果,只是改变 ...

  7. yml配置oracle连接,springboot yml 文件配置oracle,提示账号密码错误

    最近使用Spring boot,本来一直连接的是mysql数据库,一直没问题.昨天在更换了oracle数据库后,一直提示账号密码不正确,登录被拒绝.检查多次,检查账号密码一切正常,但就是连接不上ora ...

  8. springboot腾讯企业邮箱发送邮件的yml配置

    springboot腾讯企业邮箱发送邮件的yml配置 spring:mail:default-encoding: UTF-8host: smtp.exmail.qq.comport: 587usern ...

  9. springboot开发(yml配置和注解解析)

    so easy!第一个版本开发完了.需要进阶组件集成了. ​ 微服务的概念及时组件即服务,服务即接口,接口也是服务.组件调用使用restful,编码风格其实也是restful风格,接下来,我们项目开发 ...

  10. 【springboot】配置

    配置文件 SpringBoot使用一个全局的配置文件,配置文件名是固定的: •application.properties •application.yml 配置文件的作用:修改SpringBoot自 ...

最新文章

  1. SQL中的Exist操作
  2. el-tree 权限 勾选_一周新债总结,最高涨30%,10月26日起可转债交易需要先开权限...
  3. 【学术相关】现阶段硕士的困境:读博没信心,不读还闹心
  4. c语言不可见字符的ascii,转CHAR不可见字符
  5. vb冒泡排序法流程图_VB算法-冒泡排序教案
  6. fofa自动化爬虫脚本更新+详解
  7. python面试如何以相反顺序展示一个文件的内容?
  8. 我的firefox插件开发历程
  9. C盘 html后缀 删,磁盘清理c盘的后果是什么?
  10. nCode:DesignLife案例教程六
  11. 关闭eslint语法检查
  12. 2021年中国教育行业发展现状及未来发展趋势分析:在校生人数达2.91亿人[图]
  13. 《C语言入门》猜数字小游戏代码实现
  14. 不小心误删注册表exe,所有exe程序无法运行
  15. 世卫和盖茨基金会被黑?疑2.5万电邮账号密码被公开
  16. jquery加载页面的几种方法(页面加载完成就执行)
  17. win7下配置IIS
  18. ipad和iphone切图_如何在iPhone,iPad和Apple TV上设置Steam Link
  19. Win10必做的性能优化
  20. 复习一周,字节跳动三场技术面+HR面,不小心拿了offer

热门文章

  1. 北京五大不可不去的隐秘餐厅
  2. 这几款可以识别图片文字的app值得一试
  3. 20条理由告诉你,为什么当前的深度学习成了人工智能的死胡同?
  4. 2019.7月面试题总结(三)
  5. java逻辑与或非_Java基础——逻辑运算符与或非
  6. html动态显示背景颜色,js动态修改背景颜色方法汇总
  7. 移动通信基础(8)帧结构
  8. sparkstream报错 Caused by: org.apache.spark.SparkException: This RDD lacks a SparkContext. It could ha
  9. 种草电商怎么做,我助你从0到1搭建种草商城
  10. matlab空间计量AIC准则,关于AIC准则