Spring @Value is not resolving to value from property file

前端 未结 8 2150
不思量自难忘°
不思量自难忘° 2020-12-13 11:55

I\'ve had this working in some other project before, I am just re-doing the same thing but for some reason it\'s not working. The Spring @Value is not reading f

相关标签:
8条回答
  • 2020-12-13 12:47

    Please note that if you have multiple application.properties files throughout your codebase, then try adding your value to the parent project's property file.

    You can check your project's pom.xml file to identify what the parent project of your current project is.

    Alternatively, try using environment.getProperty() instead of @Value.

    0 讨论(0)
  • 2020-12-13 12:51

    for Sprig-boot User both PropertyPlaceholderConfigurer and the new PropertySourcesPlaceholderConfigurer added in Spring 3.1. so it's straightforward to access properties file. just inject

    Note: Make sure your property must not be Static

    @Value("${key.value1}")
    private String value;
    
    0 讨论(0)
提交回复
热议问题