Spring Boot: @Value returns always null

后端 未结 5 650
既然无缘
既然无缘 2020-12-10 02:53

I would like to use a value from application.properties file in order to pass it in the method in another class. The problem is that the value returns always

5条回答
  •  Happy的楠姐
    2020-12-10 03:49

    The other answers are probably correct for the OP.

    However, I ran into the same symptoms (@Value-annotated fields being null) but with a different underlying issue:

    import com.google.api.client.util.Value;

    Ensure that you are importing the correct @Value annotation class! Especially with the convenience of IDEs nowadays, this is a VERY easy mistake to make (I am using IntelliJ, and if you auto-import too quickly without reading WHAT you are auto-importing, you might waste a few hours like I did).

    Of course, the correct class to import is:

    import org.springframework.beans.factory.annotation.Value;

提交回复
热议问题