Skip to content
Advertisement

Spring Boot – Injecting application properties into a Util class variable

I would like to ask a question as per title.

I have a util class such as follows:

JavaScript

When I launch the application, and debug, the above variable SOME_VAR comes as null 🙁

I am aware that I am using this in a Util class, which is an antipattern, I think.

Could someone help me understand what I need to correct to get this to work?

Regards

Advertisement

Answer

Spring does not allow you to inject values in static variables. Use a non static instead.

If it has to be static, do something like this:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement