zoukankan      html  css  js  c++  java
  • springboot Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder ‘name’ in value “${name}” 错误解决:

    springboot启动时会检索 @Value 对应配置文件中的key,当该key不存在时就会报:Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder异常,解决方案有两种:

    1,设置 @Value 的默认值

    1 @Value("${name:default_name}")
    2 private String name;

    上面代码中,当配置文件中 name key 不存在时,就会使用“default_name”作为默认值,key 与默认值用“:”符号分割。

    2,在 Application 类中设置PropertySourcesPlaceholderConfigurer类的默认属性

    1 // 设置@Value注解取值不到忽略(不报错)
    2 @Bean
    3 public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
    4     PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer();
    5     c.setIgnoreUnresolvablePlaceholders(true);
    6     return c;
    7 }
  • 相关阅读:
    iftop 安装流程
    Centos 6.5 Tengine 安装流程
    linux 查看系统进程前十
    Centos 6.5 mongodb 安装流程
    linux 磁盘查看方式
    Linux 磁盘分区及挂载
    linux 路由添加
    rsyslog 重启
    文件上传到Web服务器
    一些链接1
  • 原文地址:https://www.cnblogs.com/lgjava/p/10969557.html
Copyright © 2011-2022 走看看