代码之家  ›  专栏  ›  技术社区  ›  Manish Kumar

无法解决中缺少属性的占位符值错误应用程序属性

  •  0
  • Manish Kumar  · 技术社区  · 4 年前

    @Component
    @EnableConfigurationProperties
    @ConfigurationProperties("audit")
    @Setter
    @Getter
    public class PlannerPropertyReader {
    
      @Value("#{'${audit.planner.collection-blacklist}'.split(',')}")
      private List<String> blacklistCollection;
    
    }
    

    在这里 audit.planner audit.planner.collection-blacklist 不存在于应用程序属性文件。因此它抛出

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'plannerPropertyReader': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'audit.planner.collection-blacklist' in value "#{'${audit.planner.collection-blacklist}'.split(',')}"
    

    如果@value中的属性无法解析,如何设置默认值?

    0 回复  |  直到 4 年前
        1
  •  2
  •   Anirudh Jadhav    4 年前

    你能试试吗这是:-

    @Value("#{'${audit.planner.collection-blacklist:''}'.split(',')}")