第一种方式:

xx.properties 属性名称错误,未与@Value("${xxx}") 进行对应

 

第二种方式:

该类未注入到spring bean容器中


@Component
@Controller
@Service
# 上面未注入,使用 @Autowired 会报错
@Autowired
 

第三种方式:

采用 new 等方式获取该对象

 @Component   
    class TestValue{
         @Value("${tag}")
         private String tagValue;
    }

    class Test{
        ...
        TestValue testValue = new TestValue()
    }
\

 

第四种方式

将该属性 用 static final 等字眼进行 修饰

@Value("${value}")
private
static String value; //错误
@Value("${value}")
private final String value; //错误

 

第五种方式 

该属性名 大写

@Value("${value}")
private static String VALUE;  //错误

参考文档:https://blog.csdn.net/zzmlake/article/details/54946346

 

第五种方式 是我真正遇到的,若还有其他方式会导致@Value("${xxx}") 为null ,

请在下方留言,

 

相关文章:

  • 2021-09-03
  • 2022-12-23
  • 2021-12-10
  • 2022-01-28
  • 2021-05-08
  • 2022-01-12
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2021-12-14
相关资源
相似解决方案